void Sprite::remapImages(FrameNumber frameFrom, FrameNumber frameTo, const std::vector<uint8_t>& mapping) { ASSERT(m_format == IMAGE_INDEXED); ASSERT(mapping.size() == 256); CelList cels; getCels(cels); for (CelIterator it = cels.begin(); it != cels.end(); ++it) { Cel* cel = *it; // Remap this Cel because is inside the specified range if (cel->getFrame() >= frameFrom && cel->getFrame() <= frameTo) { Image* image = getStock()->getImage(cel->getImage()); LockImageBits<IndexedTraits> bits(image); LockImageBits<IndexedTraits>::iterator it = bits.begin(), end = bits.end(); for (; it != end; ++it) *it = mapping[*it]; } } }
void UndoTransaction::newFrameForLayer(Layer* layer, int frame) { ASSERT(layer); ASSERT(frame >= 0); switch (layer->getType()) { case GFXOBJ_LAYER_IMAGE: // displace all cels in '>=frame' to the next frame for (int c=m_sprite->getTotalFrames()-1; c>=frame; --c) { Cel* cel = static_cast<LayerImage*>(layer)->getCel(c); if (cel) setCelFramePosition(cel, cel->getFrame()+1); } copyPreviousFrame(layer, frame); break; case GFXOBJ_LAYER_FOLDER: { LayerIterator it = static_cast<LayerFolder*>(layer)->get_layer_begin(); LayerIterator end = static_cast<LayerFolder*>(layer)->get_layer_end(); for (; it != end; ++it) newFrameForLayer(*it, frame); break; } } }
void DocumentApi::addFrameForLayer(Layer* layer, FrameNumber frame) { ASSERT(layer); ASSERT(frame >= 0); Sprite* sprite = layer->getSprite(); switch (layer->getType()) { case GFXOBJ_LAYER_IMAGE: // Displace all cels in '>=frame' to the next frame. for (FrameNumber c=sprite->getLastFrame(); c>=frame; --c) { Cel* cel = static_cast<LayerImage*>(layer)->getCel(c); if (cel) setCelFramePosition(sprite, cel, cel->getFrame().next()); } copyPreviousFrame(layer, frame); break; case GFXOBJ_LAYER_FOLDER: { LayerIterator it = static_cast<LayerFolder*>(layer)->getLayerBegin(); LayerIterator end = static_cast<LayerFolder*>(layer)->getLayerEnd(); for (; it != end; ++it) addFrameForLayer(*it, frame); break; } } }
void UndoTransaction::moveFrameBeforeLayer(Layer* layer, int frame, int before_frame) { ASSERT(layer); switch (layer->getType()) { case GFXOBJ_LAYER_IMAGE: { CelIterator it = ((LayerImage*)layer)->getCelBegin(); CelIterator end = ((LayerImage*)layer)->getCelEnd(); for (; it != end; ++it) { Cel* cel = *it; int new_frame = cel->getFrame(); // moving the frame to the future if (frame < before_frame) { if (cel->getFrame() == frame) { new_frame = before_frame-1; } else if (cel->getFrame() > frame && cel->getFrame() < before_frame) { new_frame--; } } // moving the frame to the past else if (before_frame < frame) { if (cel->getFrame() == frame) { new_frame = before_frame; } else if (cel->getFrame() >= before_frame && cel->getFrame() < frame) { new_frame++; } } if (cel->getFrame() != new_frame) setCelFramePosition(cel, new_frame); } break; } case GFXOBJ_LAYER_FOLDER: { LayerIterator it = static_cast<LayerFolder*>(layer)->get_layer_begin(); LayerIterator end = static_cast<LayerFolder*>(layer)->get_layer_end(); for (; it != end; ++it) moveFrameBeforeLayer(*it, frame, before_frame); break; } } }
void DocumentApi::moveFrameBeforeLayer(Layer* layer, FrameNumber frame, FrameNumber beforeFrame) { ASSERT(layer); switch (layer->getType()) { case GFXOBJ_LAYER_IMAGE: { CelIterator it = ((LayerImage*)layer)->getCelBegin(); CelIterator end = ((LayerImage*)layer)->getCelEnd(); for (; it != end; ++it) { Cel* cel = *it; FrameNumber newFrame = cel->getFrame(); // moving the frame to the future if (frame < beforeFrame) { if (cel->getFrame() == frame) { newFrame = beforeFrame.previous(); } else if (cel->getFrame() > frame && cel->getFrame() < beforeFrame) { --newFrame; } } // moving the frame to the past else if (beforeFrame < frame) { if (cel->getFrame() == frame) { newFrame = beforeFrame; } else if (cel->getFrame() >= beforeFrame && cel->getFrame() < frame) { ++newFrame; } } if (cel->getFrame() != newFrame) setCelFramePosition(layer->getSprite(), cel, newFrame); } break; } case GFXOBJ_LAYER_FOLDER: { LayerIterator it = static_cast<LayerFolder*>(layer)->getLayerBegin(); LayerIterator end = static_cast<LayerFolder*>(layer)->getLayerEnd(); for (; it != end; ++it) moveFrameBeforeLayer(*it, frame, beforeFrame); break; } } }
void Sprite::remapImages(FrameNumber frameFrom, FrameNumber frameTo, const std::vector<uint8_t>& mapping) { ASSERT(m_format == IMAGE_INDEXED); ASSERT(mapping.size() == 256); CelList cels; getCels(cels); for (CelIterator it = cels.begin(); it != cels.end(); ++it) { Cel* cel = *it; // Remap this Cel because is inside the specified range if (cel->getFrame() >= frameFrom && cel->getFrame() <= frameTo) { Image* image = getStock()->getImage(cel->getImage()); for (int y=0; y<image->h; ++y) { IndexedTraits::address_t ptr = image_address_fast<IndexedTraits>(image, 0, y); for (int x=0; x<image->w; ++x, ++ptr) *ptr = mapping[*ptr]; } } } }