int CHRs_optimization(tiles_data _data, bool _check) { int deleted_CHRs_cnt = 0; int CHR_data_sum; byte[] img_buff = new byte[utils.CONST_SPR8x8_TOTAL_PIXELS_CNT]; int size_offs; int size = _data.get_first_free_spr8x8_id(false); for (int CHR_n = 0; CHR_n < size; CHR_n++) { if (check_blocks_CHR(CHR_n, _data) == false) { CHR_data_sum = _data.spr8x8_sum(CHR_n); if (CHR_data_sum != 0) { ++deleted_CHRs_cnt; } if (_check == true) { continue; } // delete useless CHR { size_offs = platform_data.get_CHR_bank_max_sprites_cnt() - 1; for (int i = CHR_n; i < size_offs; i++) { _data.from_CHR_bank_to_spr8x8(i + 1, img_buff, 0); _data.from_spr8x8_to_CHR_bank(i, img_buff); } } // the last CHR is an empty space { #if DEF_ZX for (int i = 0; i < img_buff.Length; i++) { img_buff[i] = utils.CONST_ZX_DEFAULT_PAPER_COLOR; } #else Array.Clear(img_buff, 0, utils.CONST_SPR8x8_TOTAL_PIXELS_CNT); #endif _data.from_spr8x8_to_CHR_bank(platform_data.get_CHR_bank_max_sprites_cnt() - 1, img_buff); } shift_CHRs_data(CHR_n, _data); --CHR_n; --size; } } return(deleted_CHRs_cnt); }
public void paste_spr() { if (m_copy_spr_ind >= 0 && m_data != null) { if (m_sel_ind >= 0) { m_data.from_CHR_bank_to_spr8x8(m_copy_spr_ind, utils.tmp_spr8x8_buff); m_data.from_spr8x8_to_CHR_bank(m_sel_ind, utils.tmp_spr8x8_buff); MainForm.set_status_msg(String.Format("CHR Bank: Sprite #{0:X2} copied to #{1:X2}", m_copy_spr_ind, m_sel_ind)); update(); dispatch_event_need_gfx_update(); #if DEF_ZX dispatch_event_CHR_selected(); #else dispatch_event_data_changed(); #endif } else { MainForm.message_box("Please, select a CHR!", "Paste CHR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public int merge_CHR_bin(BinaryReader _br, tiles_data _data) { byte[] tmp_arr = new byte[utils.CONST_SPR8x8_TOTAL_PIXELS_CNT]; int y; int added_CHRs = 0; int chr_id = _data.get_first_free_spr8x8_id(true); if (chr_id >= 0) { do { tmp_arr = _br.ReadBytes(platform_data.get_native_CHR_size_bytes()); for (y = 0; y < utils.CONST_SPR8x8_SIDE_PIXELS_CNT; y++) { convert_CHR(y, ref tmp_arr, ref utils.tmp_spr8x8_buff); } _data.from_spr8x8_to_CHR_bank(chr_id++, utils.tmp_spr8x8_buff); ++added_CHRs; if (chr_id == platform_data.get_CHR_bank_max_sprites_cnt()) { break; } }while(_br.BaseStream.Position + platform_data.get_native_CHR_size_bytes() <= _br.BaseStream.Length); } else { throw new Exception("There is no free space in the active CHR bank!"); } return(added_CHRs); }
public int merge_CHR_spred(BinaryReader _br) { int CHR_cnt = _br.ReadInt32(); int spr8x8_cnt; bool res = true; int copied_CHRs = 0; tiles_data data = get_tiles_data(tiles_data_pos); int chr_id; // get a first free spr8x8 position { chr_id = data.get_first_free_spr8x8_id(true); if (chr_id < 0) { throw new Exception("There is no free space in the active CHR bank!"); } } for (int i = 0; i < CHR_cnt; i++) { _br.ReadInt32(); // skip id _br.ReadInt32(); // skip link_cnt spr8x8_cnt = _br.ReadInt32(); if (chr_id + spr8x8_cnt > platform_data.get_CHR_bank_max_sprites_cnt()) { MainForm.set_status_msg(String.Format("Merged: {0} of {1} CHR banks", i, CHR_cnt)); res = false; if (copied_CHRs == 0) { return(-1); } } for (int j = 0; j < spr8x8_cnt; j++) { _br.Read(utils.tmp_spr8x8_buff, 0, utils.CONST_SPR8x8_TOTAL_PIXELS_CNT); if (res) { data.from_spr8x8_to_CHR_bank(chr_id++, utils.tmp_spr8x8_buff); ++copied_CHRs; } } } if (copied_CHRs != 0) { if (MainForm.message_box("Import palette ?", "SPReD Data Import", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { for (int plt_n = 0; plt_n < utils.CONST_PALETTE_SMALL_NUM_COLORS * utils.CONST_NUM_SMALL_PALETTES; plt_n++) { data.subpalettes[plt_n >> 2][plt_n & 0x03] = (byte)_br.ReadInt32(); } } } return(res ? CHR_cnt:-1); }
public void shift_colors(bool _shift_transp) { if (m_data != null) { m_CHR_ids.Clear(); if (edit_mode == EMode.bem_CHR_select) { m_CHR_ids.Add(tiles_data.get_block_CHR_id(m_data.blocks[(m_sel_block_id << 2) + m_sel_quad_ind])); } else { int CHR_id; for (int quad_n = 0; quad_n < utils.CONST_BLOCK_SIZE; quad_n++) { CHR_id = tiles_data.get_block_CHR_id(m_data.blocks[(m_sel_block_id << 2) + quad_n]); if (!m_CHR_ids.Contains(CHR_id)) { m_CHR_ids.Add(CHR_id); } } } int CHR_n; int pix_n; int size = m_CHR_ids.Count; byte clr_ind; ++clr_ind_remap_arr_pos; clr_ind_remap_arr_pos %= _shift_transp ? (clr_ind_remap_transp_arr.Length >> 2):(clr_ind_remap_arr.Length >> 2); byte[] remap_arr = _shift_transp ? clr_ind_remap_transp_arr:clr_ind_remap_arr; int start_clr_ind = clr_ind_remap_arr_pos << 2; for (CHR_n = 0; CHR_n < size; CHR_n++) { m_data.from_CHR_bank_to_spr8x8(m_CHR_ids[CHR_n], utils.tmp_spr8x8_buff, 0); for (pix_n = 0; pix_n < utils.CONST_SPR8x8_TOTAL_PIXELS_CNT; pix_n++) { clr_ind = utils.tmp_spr8x8_buff[pix_n]; clr_ind = remap_arr[start_clr_ind + clr_ind]; utils.tmp_spr8x8_buff[pix_n] = clr_ind; } m_data.from_spr8x8_to_CHR_bank(m_CHR_ids[CHR_n], utils.tmp_spr8x8_buff); } dispatch_event_pixel_changed(); dispatch_event_data_changed(); dispatch_event_need_gfx_update(); update(); } }
void BtnOkClick_Event(object sender, EventArgs e) { if (m_color_A >= 0 && m_color_B >= 0) { #if DEF_PALETTE16_PER_CHR int pix_n; int CHR_id; int CHR_n; int block_n; bool[] CHR_flags = new bool[platform_data.get_CHR_bank_max_sprites_cnt()]; Array.Clear(CHR_flags, 0, CHR_flags.Length); uint block_data; int ff_block_n = m_tiles_data.get_first_free_block_id(false); for (block_n = 0; block_n < ff_block_n; block_n++) { for (CHR_n = 0; CHR_n < utils.CONST_BLOCK_SIZE; CHR_n++) { block_data = m_tiles_data.blocks[(block_n << 2) + CHR_n]; CHR_id = tiles_data.get_block_CHR_id(block_data); if (CHR_flags[CHR_id] == false && (tiles_data.get_block_flags_palette(block_data) == m_tiles_data.palette_pos)) { m_tiles_data.from_CHR_bank_to_spr8x8(CHR_id, utils.tmp_spr8x8_buff, 0); for (pix_n = 0; pix_n < utils.CONST_SPR8x8_TOTAL_PIXELS_CNT; pix_n++) { if (utils.tmp_spr8x8_buff[pix_n] == m_color_A) { utils.tmp_spr8x8_buff[pix_n] = ( byte )m_color_B; } else if (utils.tmp_spr8x8_buff[pix_n] == m_color_B) { utils.tmp_spr8x8_buff[pix_n] = ( byte )m_color_A; } } m_tiles_data.from_spr8x8_to_CHR_bank(CHR_id, utils.tmp_spr8x8_buff); CHR_flags[CHR_id] = true; } } } #else for (int i = 0; i < m_tiles_data.CHR_bank.Length; i++) { if (m_tiles_data.CHR_bank[i] == m_color_A) { m_tiles_data.CHR_bank[i] = ( byte )m_color_B; } else if (m_tiles_data.CHR_bank[i] == m_color_B) { m_tiles_data.CHR_bank[i] = ( byte )m_color_A; } } #endif int ind_A = m_tiles_data.subpalettes[m_color_A >> 2][m_color_A & 0x03]; int ind_B = m_tiles_data.subpalettes[m_color_B >> 2][m_color_B & 0x03]; m_tiles_data.subpalettes[m_color_A >> 2][m_color_A & 0x03] = ind_B; m_tiles_data.subpalettes[m_color_B >> 2][m_color_B & 0x03] = ind_A; for (int j = 0; j < utils.CONST_NUM_SMALL_PALETTES; j++) { palette_group.Instance.get_palettes_arr()[j].update(); } } else { MainForm.message_box("Please, select both Color A and Color B!", "Colors Swapping Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }