public virtual void load_palettes(BinaryReader _br, byte _ver, platform_data.EPlatformType _prj_platform, string _file_ext, tiles_data _data) { int i; #if DEF_NES bool nes_file = (_file_ext == platform_data.CONST_NES_FILE_EXT); #endif int palettes_cnt = (_ver == 1) ? 1: _br.ReadInt32(); if (m_palettes == null) { m_palettes = new List <palette16_data>(16); } palette16_data plt16 = null; for (i = 0; i < palettes_cnt; i++) { plt16 = new palette16_data(); if (_ver <= 2) { plt16.m_palette0 = utils.read_byte_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette1 = utils.read_byte_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette2 = utils.read_byte_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette3 = utils.read_byte_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); } else { plt16.m_palette0 = utils.read_int_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette1 = utils.read_int_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette2 = utils.read_int_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); plt16.m_palette3 = utils.read_int_arr(_br, utils.CONST_PALETTE_SMALL_NUM_COLORS); } m_palettes.Add(plt16.copy()); #if DEF_NES if (!nes_file) { plt16.m_palette1[0] = plt16.m_palette2[0] = plt16.m_palette3[0] = plt16.m_palette0[0]; } #endif #if DEF_FIXED_LEN_PALETTE16_ARR if (i >= platform_data.get_fixed_palette16_cnt()) { continue; } #endif _data.palettes_arr.Add(plt16); } }
public palettes_array(ComboBox _cbox_palettes) { instance = this; m_cbox = _cbox_palettes; m_cbox.DrawItem += new DrawItemEventHandler(PaletteDrawItem_Event); m_cbox.Items.Clear(); for (int i = 0; i < utils.CONST_PALETTE16_ARR_LEN; i++) { m_cbox.Items.Add(String.Format(" #{0:d2}", i)); m_plts[i] = new palette16_data(); #if DEF_PCE m_plts[i].assign(i == 0 ? 0x16f:0, 64, 128, 192, 64 + 20, 128 + 20, 192 + 20, 256 + 20, 128 + 40, 192 + 40, 256 + 40, 320 + 40, 192 + 60, 256 + 60, 320 + 60, 384 + 60);
public static void update_block_gfx(int _block_id, tiles_data _data, Graphics _gfx, int _img_half_width, int _img_half_height, int _x_offs = 0, int _y_offs = 0, uint _flags = 0) { Bitmap bmp; uint chr_data; byte flip_flag = 0; int plt_ind = -1; #if DEF_ZX palette16_data zx_plt = get_draw_block_palette_by_draw_block_flags(_flags); #endif palette16_data plt16 = null; for (int j = 0; j < utils.CONST_BLOCK_SIZE; j++) { chr_data = _data.blocks[(_block_id << 2) + j]; #if DEF_FLIP_BLOCKS_SPR_BY_FLAGS flip_flag = tiles_data.get_block_flags_flip(chr_data); #endif #if DEF_NES plt_ind = tiles_data.get_block_flags_palette(chr_data); #endif #if DEF_PALETTE16_PER_CHR plt16 = _data.palettes_arr[tiles_data.get_block_flags_palette(chr_data)]; #if DEF_ZX plt16 = (zx_plt != null) ? zx_plt:plt16; #endif #else plt16 = _data.palettes_arr[_data.palette_pos]; #endif _data.from_CHR_bank_to_spr8x8(tiles_data.get_block_CHR_id(chr_data), utils.tmp_spr8x8_buff); bmp = utils.create_bitmap(utils.tmp_spr8x8_buff, 8, 8, flip_flag, false, plt_ind, plt16); _gfx.DrawImage(bmp, _x_offs + ((j % 2) * _img_half_width), _y_offs + ((j >> 1) * _img_half_height), _img_half_width, _img_half_height); bmp.Dispose(); } }
public static Bitmap create_bitmap(byte[] _arr, int _width, int _height, byte _flags, bool _alpha, int _plt_ind, palette16_data _plt = null, int _arr_offset = 0) { int img_size = _width * _height; int[] img_buff = new int[img_size]; GCHandle handle = GCHandle.Alloc(img_buff, GCHandleType.Pinned); #if DEF_NES bool apply_palette = (_plt != null && _plt_ind >= 0); int[] clr_inds = apply_palette ? _plt.subpalettes[_plt_ind]:null; int alpha; apply_palette = (clr_inds != null) && apply_palette; #endif int clr; int pix_ind; #if !DEF_NES // valid palette ? if (_plt != null) #endif { for (int p = 0; p < img_size; p++) { pix_ind = _arr[p + _arr_offset]; #if DEF_NES if (apply_palette) #endif { #if DEF_NES clr = palette_group.Instance.main_palette[clr_inds[pix_ind]]; #else clr = palette_group.Instance.main_palette[_plt.subpalettes[pix_ind / CONST_NUM_SMALL_PALETTES][pix_ind % CONST_NUM_SMALL_PALETTES]]; #endif if ((clr != 0 && _alpha == true) || _alpha == false) { clr |= 0xFF << 24; } } #if DEF_NES else { alpha = (pix_ind == 0) ? (_alpha ? 0x00:0xFF):0xFF; pix_ind <<= 6; clr = alpha << 24 | pix_ind << 16 | pix_ind << 8 | pix_ind; } #endif img_buff[p] = clr; } } Bitmap bmp = new Bitmap(_width, _height, _width << 2, PixelFormat.Format32bppPArgb, handle.AddrOfPinnedObject()); handle.Free(); flip_bmp(bmp, _flags); return(bmp); }
public static palette16_data get_draw_block_palette_by_view_type(ETileViewType _view_type, palette16_data _default_plt) { return((_view_type == ETileViewType.tvt_BW) ? zx_alt_palettes[CONST_ZX_PALETTE_BW]:(_view_type == ETileViewType.tvt_Inv_BW) ? zx_alt_palettes[CONST_ZX_PALETTE_INV_BW]:_default_plt); }