void UndoTransaction::setPixelFormat(PixelFormat newFormat, DitheringMethod dithering_method) { Image *old_image; Image *new_image; int c; if (m_sprite->getPixelFormat() == newFormat) return; // Change pixel format of the stock of images. if (isEnabled()) m_undoHistory->pushUndoer(new undoers::SetStockPixelFormat(m_undoHistory->getObjects(), m_sprite->getStock())); m_sprite->getStock()->setPixelFormat(newFormat); // Use the rgbmap for the specified sprite const RgbMap* rgbmap = m_sprite->getRgbMap(); for (c=0; c<m_sprite->getStock()->size(); c++) { old_image = m_sprite->getStock()->getImage(c); if (!old_image) continue; new_image = quantization::convert_pixel_format(old_image, newFormat, dithering_method, rgbmap, // TODO check this out m_sprite->getCurrentPalette(), m_sprite->getBackgroundLayer() != NULL); this->replaceStockImage(c, new_image); } // Change sprite's pixel format. if (isEnabled()) m_undoHistory->pushUndoer(new undoers::SetSpritePixelFormat(m_undoHistory->getObjects(), m_sprite)); m_sprite->setPixelFormat(newFormat); // Regenerate extras m_document->destroyExtraCel(); // change "sprite.palette" if (newFormat == IMAGE_GRAYSCALE) { if (isEnabled()) { // Save all palettes PalettesList palettes = m_sprite->getPalettes(); for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) { Palette* palette = *it; m_undoHistory->pushUndoer(new undoers::RemovePalette( m_undoHistory->getObjects(), m_sprite, palette->getFrame())); } } UniquePtr<Palette> graypal(Palette::createGrayscale()); m_sprite->resetPalettes(); m_sprite->setPalette(graypal, true); } }
void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, DitheringMethod dithering_method) { Image* old_image; Image* new_image; int c; if (sprite->getPixelFormat() == newFormat) return; // Change pixel format of the stock of images. DocumentUndo* undo = m_document->getUndo(); if (undo->isEnabled()) m_undoers->pushUndoer(new undoers::SetStockPixelFormat(getObjects(), sprite->getStock())); sprite->getStock()->setPixelFormat(newFormat); // TODO Review this, why we use the palette in frame 0? FrameNumber frame(0); // Use the rgbmap for the specified sprite const RgbMap* rgbmap = sprite->getRgbMap(frame); for (c=0; c<sprite->getStock()->size(); c++) { old_image = sprite->getStock()->getImage(c); if (!old_image) continue; new_image = quantization::convert_pixel_format (old_image, newFormat, dithering_method, rgbmap, sprite->getPalette(frame), sprite->getBackgroundLayer() != NULL); replaceStockImage(sprite, c, new_image); } // Change sprite's pixel format. if (undo->isEnabled()) m_undoers->pushUndoer(new undoers::SetSpritePixelFormat(getObjects(), sprite)); sprite->setPixelFormat(newFormat); // Regenerate extras m_document->destroyExtraCel(); // When we are converting to grayscale color mode, we've to destroy // all palettes and put only one grayscaled-palette at the first // frame. if (newFormat == IMAGE_GRAYSCALE) { // Add undoers to revert all palette changes. if (undo->isEnabled()) { PalettesList palettes = sprite->getPalettes(); for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) { Palette* palette = *it; m_undoers->pushUndoer(new undoers::RemovePalette( getObjects(), sprite, palette->getFrame())); } m_undoers->pushUndoer(new undoers::AddPalette( getObjects(), sprite, FrameNumber(0))); } // It's a UniquePtr because setPalette'll create a copy of "graypal". UniquePtr<Palette> graypal(Palette::createGrayscale()); sprite->resetPalettes(); sprite->setPalette(graypal, true); } }