private void _updatePalettes() { if (_externalPalette != null) { if (_internalPalette != null) { _mixedPalette = new Palette(_externalPalette); _mixedPalette.merge(_internalPalette); } else { _mixedPalette = _externalPalette; } } }
private void updatePalettes() { Graphics g; Palette mp; // draw the current external palette palettes[currentPaletteIndex].drawPalette((Bitmap)externalPalettePictureBox.Image, 10); externalPalettePictureBox.Refresh(); // if there's a currently locked internal palette, draw that if (lockedInternalPalette != null) { lockedInternalPalette.drawPalette((Bitmap)internalPalettePictureBox.Image, 10); // then merge the two palettes into Palette mp mp = new Palette(palettes[currentPaletteIndex]); mp.merge(lockedInternalPalette); } // else draw the image's internal palette, if it exists else { if (currentImage.getInternalPalette() != null) { currentImage.getInternalPalette().drawPalette((Bitmap)internalPalettePictureBox.Image, 10); // and get its mixed palette mp = currentImage.getMixedPalette(); } else { g = Graphics.FromImage(internalPalettePictureBox.Image); g.Clear(Color.White); // set mixed palette to the current external palette mp = palettes[currentPaletteIndex]; } } internalPalettePictureBox.Refresh(); // draw mixed palette mp.drawPalette((Bitmap)mixedPalettePictureBox.Image, 10); mixedPalettePictureBox.Refresh(); // if any of the palettes have changed, redraw the frame view updateFrame(); }
/// <summary> /// Renders the frames' palettized pixel data in ImageFrame.buffer to ImageFrame.bitmap, /// using the provided internal Palette, overriding any saved one. /// </summary> /// <param name="internalPalette"></param> public void render(Palette internalPalette) { //if ( Palette p; Graphics g; // if the Image's own internal palette was passed, draw from the mixed if (internalPalette == _internalPalette) { p = _mixedPalette; } // else, build a temporary mixed palette else { p = new Palette(_externalPalette); p.merge(internalPalette); } // ! for (int i = 0; i < _header.frameCount; ++i) { if (_frames[i].bitmap != null && _frames[i].buffer != null) { g = Graphics.FromImage(_frames[i].bitmap); g.Clear(Color.Black); for (int y = 0; y < _header.height; ++y) { for (int x = 0; x < _header.width; ++x) { int index = x + y * _header.width; int val = _frames[i].buffer[index]; _frames[i].bitmap.SetPixel(x, y, Color.FromArgb((int)p[val])); } } } else { // make it some kind of "invalid" default image? } } }