mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-28 00:35:30 +00:00
Add FrameNumber type.
This commit is contained in:
parent
ac3ad1fbc2
commit
c3030b9daa
@ -122,7 +122,7 @@ protected:
|
||||
void onExport()
|
||||
{
|
||||
Sprite* sprite = m_document->getSprite();
|
||||
int nframes = sprite->getTotalFrames();
|
||||
FrameNumber nframes = sprite->getTotalFrames();
|
||||
int columns;
|
||||
|
||||
switch (m_sheetType.getSelectedItem()) {
|
||||
@ -145,9 +145,9 @@ protected:
|
||||
UniquePtr<Image> tempImage(Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()));
|
||||
image_clear(resultImage, 0);
|
||||
|
||||
int oldFrame = sprite->getCurrentFrame();
|
||||
FrameNumber oldFrame = sprite->getCurrentFrame();
|
||||
int column = 0, row = 0;
|
||||
for (int frame=0; frame<nframes; ++frame) {
|
||||
for (FrameNumber frame(0); frame<nframes; ++frame) {
|
||||
// TODO "tempImage" could not be necessary if we could specify
|
||||
// destination clipping bounds in Sprite::render() function.
|
||||
tempImage->clear(0);
|
||||
@ -175,7 +175,7 @@ protected:
|
||||
resultImage.release();
|
||||
|
||||
// Create the cel.
|
||||
UniquePtr<Cel> resultCel(new Cel(0, indexInStock));
|
||||
UniquePtr<Cel> resultCel(new Cel(FrameNumber(0), indexInStock));
|
||||
|
||||
// Add the cel in the layer.
|
||||
undoTransaction.addCel(resultLayer, resultCel);
|
||||
@ -191,8 +191,8 @@ protected:
|
||||
}
|
||||
|
||||
// Change the number of frames (just one, the sprite sheet)
|
||||
undoTransaction.setNumberOfFrames(1);
|
||||
undoTransaction.setCurrentFrame(0);
|
||||
undoTransaction.setNumberOfFrames(FrameNumber(1));
|
||||
undoTransaction.setCurrentFrame(FrameNumber(0));
|
||||
|
||||
// Set the size of the sprite to the tile size.
|
||||
undoTransaction.setSpriteSize(sheet_w, sheet_h);
|
||||
|
@ -45,14 +45,16 @@ protected:
|
||||
void onExecute(Context* context);
|
||||
|
||||
private:
|
||||
enum {
|
||||
CURRENT_FRAME = 0,
|
||||
enum Target {
|
||||
ALL_FRAMES = -1,
|
||||
CURRENT_FRAME = 0,
|
||||
SPECIFIC_FRAME = 1
|
||||
};
|
||||
|
||||
// Frame to be shown. It can be ALL_FRAMES, CURRENT_FRAME, or a
|
||||
// number indicating a specific frame (1 is the first frame).
|
||||
int m_frame;
|
||||
Target m_target;
|
||||
FrameNumber m_frame;
|
||||
};
|
||||
|
||||
FramePropertiesCommand::FramePropertiesCommand()
|
||||
@ -66,13 +68,14 @@ void FramePropertiesCommand::onLoadParams(Params* params)
|
||||
{
|
||||
std::string frame = params->get("frame");
|
||||
if (frame == "all") {
|
||||
m_frame = ALL_FRAMES;
|
||||
m_target = ALL_FRAMES;
|
||||
}
|
||||
else if (frame == "current") {
|
||||
m_frame = CURRENT_FRAME;
|
||||
m_target = CURRENT_FRAME;
|
||||
}
|
||||
else {
|
||||
m_frame = base::convert_to<int>(frame);
|
||||
m_target = SPECIFIC_FRAME;
|
||||
m_frame = FrameNumber(base::convert_to<int>(frame)-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,22 +94,22 @@ void FramePropertiesCommand::onExecute(Context* context)
|
||||
Widget* frlen = app::find_widget<Widget>(window, "frlen");
|
||||
Widget* ok = app::find_widget<Widget>(window, "ok");
|
||||
|
||||
int sprite_frame = 0;
|
||||
switch (m_frame) {
|
||||
FrameNumber sprite_frame(0);
|
||||
switch (m_target) {
|
||||
|
||||
case ALL_FRAMES:
|
||||
break;
|
||||
|
||||
case CURRENT_FRAME:
|
||||
sprite_frame = sprite->getCurrentFrame()+1;
|
||||
sprite_frame = sprite->getCurrentFrame();
|
||||
break;
|
||||
|
||||
default:
|
||||
case SPECIFIC_FRAME:
|
||||
sprite_frame = m_frame;
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_frame == ALL_FRAMES)
|
||||
if (m_target == ALL_FRAMES)
|
||||
frame->setText("All");
|
||||
else
|
||||
frame->setTextf("%d", sprite_frame);
|
||||
@ -117,7 +120,7 @@ void FramePropertiesCommand::onExecute(Context* context)
|
||||
if (window->get_killer() == ok) {
|
||||
int num = strtol(frlen->getText(), NULL, 10);
|
||||
|
||||
if (m_frame == ALL_FRAMES) {
|
||||
if (m_target == ALL_FRAMES) {
|
||||
if (Alert::show("Warning"
|
||||
"<<Do you want to change the duration of all frames?"
|
||||
"||&Yes||&No") == 1) {
|
||||
@ -130,7 +133,7 @@ void FramePropertiesCommand::onExecute(Context* context)
|
||||
else {
|
||||
DocumentWriter document_writer(document);
|
||||
UndoTransaction undoTransaction(document_writer, "Frame Duration");
|
||||
undoTransaction.setFrameDuration(sprite_frame-1, num);
|
||||
undoTransaction.setFrameDuration(sprite_frame, num);
|
||||
undoTransaction.commit();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ void GotoFirstFrameCommand::onExecute(Context* context)
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
|
||||
sprite->setCurrentFrame(0);
|
||||
sprite->setCurrentFrame(FrameNumber(0));
|
||||
|
||||
update_screen_for_document(document);
|
||||
current_editor->updateStatusBar();
|
||||
@ -101,12 +101,12 @@ void GotoPreviousFrameCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
int frame = sprite->getCurrentFrame();
|
||||
FrameNumber frame = sprite->getCurrentFrame();
|
||||
|
||||
if (frame > 0)
|
||||
sprite->setCurrentFrame(frame-1);
|
||||
if (frame > FrameNumber(0))
|
||||
sprite->setCurrentFrame(frame.previous());
|
||||
else
|
||||
sprite->setCurrentFrame(sprite->getTotalFrames()-1);
|
||||
sprite->setCurrentFrame(sprite->getLastFrame());
|
||||
|
||||
update_screen_for_document(document);
|
||||
current_editor->updateStatusBar();
|
||||
@ -143,12 +143,12 @@ void GotoNextFrameCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
int frame = sprite->getCurrentFrame();
|
||||
FrameNumber frame = sprite->getCurrentFrame();
|
||||
|
||||
if (frame < sprite->getTotalFrames()-1)
|
||||
sprite->setCurrentFrame(frame+1);
|
||||
if (frame < sprite->getLastFrame())
|
||||
sprite->setCurrentFrame(frame.next());
|
||||
else
|
||||
sprite->setCurrentFrame(0);
|
||||
sprite->setCurrentFrame(FrameNumber(0));
|
||||
|
||||
update_screen_for_document(document);
|
||||
current_editor->updateStatusBar();
|
||||
@ -185,7 +185,7 @@ void GotoLastFrameCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
sprite->setCurrentFrame(sprite->getTotalFrames()-1);
|
||||
sprite->setCurrentFrame(sprite->getLastFrame());
|
||||
|
||||
update_screen_for_document(document);
|
||||
current_editor->updateStatusBar();
|
||||
@ -250,7 +250,7 @@ void GotoFrameCommand::onExecute(Context* context)
|
||||
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
int newFrame = MID(0, m_frame-1, sprite->getTotalFrames()-1);
|
||||
FrameNumber newFrame(MID(0, m_frame-1, sprite->getLastFrame()));
|
||||
|
||||
sprite->setCurrentFrame(newFrame);
|
||||
|
||||
|
@ -196,7 +196,7 @@ protected:
|
||||
animation[i] = NULL;
|
||||
|
||||
// Create the cel.
|
||||
UniquePtr<Cel> resultCel(new Cel(i, indexInStock));
|
||||
UniquePtr<Cel> resultCel(new Cel(FrameNumber(i), indexInStock));
|
||||
|
||||
// Add the cel in the layer.
|
||||
undoTransaction.addCel(resultLayer, resultCel);
|
||||
@ -213,8 +213,8 @@ protected:
|
||||
}
|
||||
|
||||
// Change the number of frames
|
||||
undoTransaction.setNumberOfFrames(animation.size());
|
||||
undoTransaction.setCurrentFrame(0);
|
||||
undoTransaction.setNumberOfFrames(FrameNumber(animation.size()));
|
||||
undoTransaction.setCurrentFrame(FrameNumber(0));
|
||||
|
||||
// Set the size of the sprite to the tile size.
|
||||
undoTransaction.setSpriteSize(m_rect.w, m_rect.h);
|
||||
|
@ -83,12 +83,12 @@ void MergeDownLayerCommand::onExecute(Context* context)
|
||||
Layer *src_layer, *dst_layer;
|
||||
Cel *src_cel, *dst_cel;
|
||||
Image *src_image, *dst_image;
|
||||
int frpos, index;
|
||||
int index;
|
||||
|
||||
src_layer = sprite->getCurrentLayer();
|
||||
dst_layer = sprite->getCurrentLayer()->get_prev();
|
||||
|
||||
for (frpos=0; frpos<sprite->getTotalFrames(); ++frpos) {
|
||||
for (FrameNumber frpos(0); frpos<sprite->getTotalFrames(); ++frpos) {
|
||||
// Get frames
|
||||
src_cel = static_cast<LayerImage*>(src_layer)->getCel(frpos);
|
||||
dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(frpos);
|
||||
|
@ -625,7 +625,7 @@ void PaletteEntryEditor::onRampClick(Event& ev)
|
||||
return;
|
||||
|
||||
Palette* src_palette = get_current_palette();
|
||||
Palette* dst_palette = new Palette(0, 256);
|
||||
Palette* dst_palette = new Palette(FrameNumber(0), 256);
|
||||
|
||||
src_palette->copyColorsTo(dst_palette);
|
||||
dst_palette->makeHorzRamp(index1, index2);
|
||||
|
@ -72,7 +72,7 @@ void PlayAnimationCommand::onExecute(Context* context)
|
||||
{
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite(document->getSprite());
|
||||
int old_frame, msecs;
|
||||
int msecs;
|
||||
bool done = false;
|
||||
bool onionskin_state = context->getSettings()->getUseOnionskin();
|
||||
Palette *oldpal, *newpal;
|
||||
@ -86,7 +86,7 @@ void PlayAnimationCommand::onExecute(Context* context)
|
||||
|
||||
ui::jmouse_hide();
|
||||
|
||||
old_frame = sprite->getCurrentFrame();
|
||||
FrameNumber old_frame = sprite->getCurrentFrame();
|
||||
|
||||
LOCK_VARIABLE(speed_timer);
|
||||
LOCK_FUNCTION(speed_timer_callback);
|
||||
@ -124,9 +124,9 @@ void PlayAnimationCommand::onExecute(Context* context)
|
||||
} while (!done && (speed_timer <= 0));
|
||||
|
||||
if (!done) {
|
||||
int frame = sprite->getCurrentFrame()+1;
|
||||
if (frame >= sprite->getTotalFrames())
|
||||
frame = 0;
|
||||
FrameNumber frame = sprite->getCurrentFrame().next();
|
||||
if (frame > sprite->getLastFrame())
|
||||
frame = FrameNumber(0);
|
||||
sprite->setCurrentFrame(frame);
|
||||
|
||||
speed_timer--;
|
||||
|
@ -93,7 +93,7 @@ void SpritePropertiesCommand::onExecute(Context* context)
|
||||
imgtype_text = "Grayscale";
|
||||
break;
|
||||
case IMAGE_INDEXED:
|
||||
sprintf(buf, "Indexed (%d colors)", sprite->getPalette(0)->size());
|
||||
sprintf(buf, "Indexed (%d colors)", sprite->getPalette(FrameNumber(0))->size());
|
||||
imgtype_text = buf;
|
||||
break;
|
||||
default:
|
||||
|
@ -117,9 +117,9 @@ protected:
|
||||
private:
|
||||
void setCursor(int x, int y);
|
||||
void getDrawableLayers(JRect clip, int* first_layer, int* last_layer);
|
||||
void getDrawableFrames(JRect clip, int* first_frame, int* last_frame);
|
||||
void getDrawableFrames(JRect clip, FrameNumber* first_frame, FrameNumber* last_frame);
|
||||
void drawHeader(JRect clip);
|
||||
void drawHeaderFrame(JRect clip, int frame);
|
||||
void drawHeaderFrame(JRect clip, FrameNumber frame);
|
||||
void drawHeaderPart(JRect clip, int x1, int y1, int x2, int y2,
|
||||
bool is_hot, bool is_clk,
|
||||
const char* line1, int align1,
|
||||
@ -127,12 +127,12 @@ private:
|
||||
void drawSeparator(JRect clip);
|
||||
void drawLayer(JRect clip, int layer_index);
|
||||
void drawLayerPadding();
|
||||
void drawCel(JRect clip, int layer_index, int frame, Cel* cel);
|
||||
bool drawPart(int part, int layer, int frame);
|
||||
void drawCel(JRect clip, int layer_index, FrameNumber frame, Cel* cel);
|
||||
bool drawPart(int part, int layer, FrameNumber frame);
|
||||
void regenerateLayers();
|
||||
void hotThis(int hot_part, int hot_layer, int hot_frame);
|
||||
void centerCel(int layer, int frame);
|
||||
void showCel(int layer, int frame);
|
||||
void hotThis(int hot_part, int hot_layer, FrameNumber hotFrame);
|
||||
void centerCel(int layer, FrameNumber frame);
|
||||
void showCel(int layer, FrameNumber frame);
|
||||
void showCurrentCel();
|
||||
void cleanClk();
|
||||
void setScroll(int x, int y, bool use_refresh_region);
|
||||
@ -150,11 +150,11 @@ private:
|
||||
// The 'hot' part is where the mouse is on top of
|
||||
int m_hot_part;
|
||||
int m_hot_layer;
|
||||
int m_hot_frame;
|
||||
FrameNumber m_hot_frame;
|
||||
// The 'clk' part is where the mouse's button was pressed (maybe for a drag & drop operation)
|
||||
int m_clk_part;
|
||||
int m_clk_layer;
|
||||
int m_clk_frame;
|
||||
FrameNumber m_clk_frame;
|
||||
// Keys
|
||||
bool m_space_pressed;
|
||||
};
|
||||
@ -245,7 +245,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
case JM_DRAW: {
|
||||
JRect clip = &msg->draw.rect;
|
||||
int layer, first_layer, last_layer;
|
||||
int frame, first_frame, last_frame;
|
||||
FrameNumber frame, first_frame, last_frame;
|
||||
|
||||
getDrawableLayers(clip, &first_layer, &last_layer);
|
||||
getDrawableFrames(clip, &first_frame, &last_frame);
|
||||
@ -254,7 +254,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
drawHeader(clip);
|
||||
|
||||
// Draw the header for each visible frame.
|
||||
for (frame=first_frame; frame<=last_frame; frame++)
|
||||
for (frame=first_frame; frame<=last_frame; ++frame)
|
||||
drawHeaderFrame(clip, frame);
|
||||
|
||||
// Draw the separator.
|
||||
@ -338,7 +338,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
const DocumentReader document(const_cast<Document*>(m_document));
|
||||
const Sprite* sprite = m_sprite;
|
||||
int old_layer = getLayerIndex(sprite->getCurrentLayer());
|
||||
int frame = m_sprite->getCurrentFrame();
|
||||
FrameNumber frame = m_sprite->getCurrentFrame();
|
||||
|
||||
// Did the user select another layer?
|
||||
if (old_layer != m_clk_layer) {
|
||||
@ -373,7 +373,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
const DocumentReader document(const_cast<Document*>(m_document));
|
||||
const Sprite* sprite = document->getSprite();
|
||||
int old_layer = getLayerIndex(sprite->getCurrentLayer());
|
||||
int old_frame = sprite->getCurrentFrame();
|
||||
FrameNumber old_frame = sprite->getCurrentFrame();
|
||||
|
||||
// Select the new clicked-part.
|
||||
if (old_layer != m_clk_layer ||
|
||||
@ -389,9 +389,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
// Redraw the old & new selected layer.
|
||||
if (old_layer != m_clk_layer) {
|
||||
drawPart(A_PART_LAYER, old_layer, old_frame);
|
||||
drawPart(A_PART_LAYER,
|
||||
m_clk_layer,
|
||||
m_clk_frame);
|
||||
drawPart(A_PART_LAYER, m_clk_layer, m_clk_frame);
|
||||
}
|
||||
// Redraw the old selected cel.
|
||||
drawPart(A_PART_CEL, old_layer, old_frame);
|
||||
@ -419,7 +417,7 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
case JM_MOTION: {
|
||||
int hot_part = A_PART_NOTHING;
|
||||
int hot_layer = -1;
|
||||
int hot_frame = -1;
|
||||
FrameNumber hot_frame(-1);
|
||||
int mx = msg->mouse.x - rc->x1;
|
||||
int my = msg->mouse.y - rc->y1;
|
||||
|
||||
@ -454,10 +452,10 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
// Is on a frame header?
|
||||
else {
|
||||
hot_part = A_PART_HEADER_FRAME;
|
||||
hot_frame = (mx
|
||||
- m_separator_x
|
||||
- m_separator_w
|
||||
+ m_scroll_x) / FRMSIZE;
|
||||
hot_frame = FrameNumber((mx
|
||||
- m_separator_x
|
||||
- m_separator_w
|
||||
+ m_scroll_x) / FRMSIZE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -495,10 +493,10 @@ bool AnimationEditor::onProcessMessage(Message* msg)
|
||||
}
|
||||
else {
|
||||
hot_part = A_PART_CEL;
|
||||
hot_frame = (mx
|
||||
- m_separator_x
|
||||
- m_separator_w
|
||||
+ m_scroll_x) / FRMSIZE;
|
||||
hot_frame = FrameNumber((mx
|
||||
- m_separator_x
|
||||
- m_separator_w
|
||||
+ m_scroll_x) / FRMSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -879,16 +877,16 @@ void AnimationEditor::setCursor(int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationEditor::getDrawableLayers(JRect clip, int *first_layer, int *last_layer)
|
||||
void AnimationEditor::getDrawableLayers(JRect clip, int* first_layer, int* last_layer)
|
||||
{
|
||||
*first_layer = 0;
|
||||
*last_layer = m_nlayers-1;
|
||||
}
|
||||
|
||||
void AnimationEditor::getDrawableFrames(JRect clip, int *first_frame, int *last_frame)
|
||||
void AnimationEditor::getDrawableFrames(JRect clip, FrameNumber* first_frame, FrameNumber* last_frame)
|
||||
{
|
||||
*first_frame = 0;
|
||||
*last_frame = m_sprite->getTotalFrames()-1;
|
||||
*first_frame = FrameNumber(0);
|
||||
*last_frame = m_sprite->getLastFrame();
|
||||
}
|
||||
|
||||
void AnimationEditor::drawHeader(JRect clip)
|
||||
@ -910,7 +908,7 @@ void AnimationEditor::drawHeader(JRect clip)
|
||||
"Layers", -1);
|
||||
}
|
||||
|
||||
void AnimationEditor::drawHeaderFrame(JRect clip, int frame)
|
||||
void AnimationEditor::drawHeaderFrame(JRect clip, FrameNumber frame)
|
||||
{
|
||||
bool is_hot = (m_hot_part == A_PART_HEADER_FRAME &&
|
||||
m_hot_frame == frame);
|
||||
@ -1152,7 +1150,7 @@ void AnimationEditor::drawLayerPadding()
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationEditor::drawCel(JRect clip, int layer_index, int frame, Cel* cel)
|
||||
void AnimationEditor::drawCel(JRect clip, int layer_index, FrameNumber frame, Cel* cel)
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
Layer *layer = m_layers[layer_index];
|
||||
@ -1258,7 +1256,7 @@ void AnimationEditor::drawCel(JRect clip, int layer_index, int frame, Cel* cel)
|
||||
set_clip_rect(ji_screen, cx1, cy1, cx2, cy2);
|
||||
}
|
||||
|
||||
bool AnimationEditor::drawPart(int part, int layer, int frame)
|
||||
bool AnimationEditor::drawPart(int part, int layer, FrameNumber frame)
|
||||
{
|
||||
switch (part) {
|
||||
case A_PART_NOTHING:
|
||||
@ -1318,7 +1316,7 @@ void AnimationEditor::regenerateLayers()
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationEditor::hotThis(int hot_part, int hot_layer, int hot_frame)
|
||||
void AnimationEditor::hotThis(int hot_part, int hot_layer, FrameNumber hot_frame)
|
||||
{
|
||||
int old_hot_part;
|
||||
|
||||
@ -1349,7 +1347,7 @@ void AnimationEditor::hotThis(int hot_part, int hot_layer, int hot_frame)
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationEditor::centerCel(int layer, int frame)
|
||||
void AnimationEditor::centerCel(int layer, FrameNumber frame)
|
||||
{
|
||||
int target_x = (this->rc->x1 + m_separator_x + m_separator_w + this->rc->x2)/2 - FRMSIZE/2;
|
||||
int target_y = (this->rc->y1 + HDRSIZE + this->rc->y2)/2 - LAYSIZE/2;
|
||||
@ -1359,7 +1357,7 @@ void AnimationEditor::centerCel(int layer, int frame)
|
||||
setScroll(scroll_x, scroll_y, false);
|
||||
}
|
||||
|
||||
void AnimationEditor::showCel(int layer, int frame)
|
||||
void AnimationEditor::showCel(int layer, FrameNumber frame)
|
||||
{
|
||||
int scroll_x, scroll_y;
|
||||
int x1, y1, x2, y2;
|
||||
|
@ -78,7 +78,7 @@ Document* Document::createBasicDocument(PixelFormat format, int width, int heigh
|
||||
{
|
||||
// Create the sprite.
|
||||
UniquePtr<Sprite> sprite(new Sprite(format, width, height, ncolors));
|
||||
sprite->setTotalFrames(1);
|
||||
sprite->setTotalFrames(FrameNumber(1));
|
||||
|
||||
// Create the main image.
|
||||
int indexInStock;
|
||||
@ -100,7 +100,7 @@ Document* Document::createBasicDocument(PixelFormat format, int width, int heigh
|
||||
|
||||
// Create the cel.
|
||||
{
|
||||
UniquePtr<Cel> cel(new Cel(0, indexInStock));
|
||||
UniquePtr<Cel> cel(new Cel(FrameNumber(0), indexInStock));
|
||||
cel->setPosition(0, 0);
|
||||
|
||||
// Add the cel in the layer.
|
||||
@ -237,7 +237,7 @@ void Document::prepareExtraCel(int x, int y, int w, int h, int opacity)
|
||||
ASSERT(getSprite() != NULL);
|
||||
|
||||
if (!m_extraCel)
|
||||
m_extraCel = new Cel(0, 0); // Ignored fields for this cell (frame, and image index)
|
||||
m_extraCel = new Cel(FrameNumber(0), 0); // Ignored fields for this cell (frame, and image index)
|
||||
|
||||
m_extraCel->setPosition(x, y);
|
||||
m_extraCel->setOpacity(opacity);
|
||||
@ -398,7 +398,8 @@ Document* Document::duplicate(DuplicateType type) const
|
||||
const Sprite* sourceSprite = getSprite();
|
||||
UniquePtr<Sprite> spriteCopyPtr(new Sprite(sourceSprite->getPixelFormat(),
|
||||
sourceSprite->getWidth(),
|
||||
sourceSprite->getHeight(), sourceSprite->getPalette(0)->size()));
|
||||
sourceSprite->getHeight(),
|
||||
sourceSprite->getPalette(FrameNumber(0))->size()));
|
||||
UniquePtr<Document> documentCopy(new Document(spriteCopyPtr));
|
||||
Sprite* spriteCopy = spriteCopyPtr.release();
|
||||
|
||||
@ -406,7 +407,7 @@ Document* Document::duplicate(DuplicateType type) const
|
||||
spriteCopy->setCurrentFrame(sourceSprite->getCurrentFrame());
|
||||
|
||||
// Copy frames duration
|
||||
for (int i = 0; i < sourceSprite->getTotalFrames(); ++i)
|
||||
for (FrameNumber i(0); i < sourceSprite->getTotalFrames(); ++i)
|
||||
spriteCopy->setFrameDuration(i, sourceSprite->getFrameDuration(i));
|
||||
|
||||
// Copy color palettes
|
||||
@ -447,7 +448,7 @@ Document* Document::duplicate(DuplicateType type) const
|
||||
(spriteCopy,
|
||||
sourceSprite->getFolder(),
|
||||
gfx::Rect(0, 0, sourceSprite->getWidth(), sourceSprite->getHeight()),
|
||||
0, sourceSprite->getTotalFrames()-1);
|
||||
FrameNumber(0), sourceSprite->getLastFrame());
|
||||
|
||||
// Add and select the new flat layer
|
||||
spriteCopy->getFolder()->add_layer(flatLayer);
|
||||
|
@ -85,7 +85,7 @@ static void ase_file_prepare_frame_header(FILE *f, ASE_FrameHeader *frame_header
|
||||
static void ase_file_write_frame_header(FILE *f, ASE_FrameHeader *frame_header);
|
||||
|
||||
static void ase_file_write_layers(FILE *f, Layer *layer);
|
||||
static void ase_file_write_cels(FILE *f, Sprite *sprite, Layer *layer, int frame);
|
||||
static void ase_file_write_cels(FILE *f, Sprite *sprite, Layer *layer, FrameNumber frame);
|
||||
|
||||
static void ase_file_read_padding(FILE *f, int bytes);
|
||||
static void ase_file_write_padding(FILE *f, int bytes);
|
||||
@ -95,12 +95,12 @@ static void ase_file_write_string(FILE *f, const std::string& string);
|
||||
static void ase_file_write_start_chunk(FILE *f, int type);
|
||||
static void ase_file_write_close_chunk(FILE *f);
|
||||
|
||||
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, int frame);
|
||||
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, int frame);
|
||||
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, FrameNumber frame);
|
||||
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, FrameNumber frame);
|
||||
static void ase_file_write_color2_chunk(FILE *f, Palette *pal);
|
||||
static Layer *ase_file_read_layer_chunk(FILE *f, Sprite *sprite, Layer **previous_layer, int *current_level);
|
||||
static void ase_file_write_layer_chunk(FILE *f, Layer *layer);
|
||||
static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, PixelFormat pixelFormat, FileOp *fop, ASE_Header *header, size_t chunk_end);
|
||||
static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, FrameNumber frame, PixelFormat pixelFormat, FileOp *fop, ASE_Header *header, size_t chunk_end);
|
||||
static void ase_file_write_cel_chunk(FILE *f, Cel *cel, LayerImage *layer, Sprite *sprite);
|
||||
static Mask *ase_file_read_mask_chunk(FILE *f);
|
||||
static void ase_file_write_mask_chunk(FILE *f, Mask *mask);
|
||||
@ -134,36 +134,27 @@ FileFormat* CreateAseFormat()
|
||||
|
||||
bool AseFormat::onLoad(FileOp *fop)
|
||||
{
|
||||
Sprite *sprite = NULL;
|
||||
ASE_Header header;
|
||||
ASE_FrameHeader frame_header;
|
||||
int current_level;
|
||||
int frame_pos;
|
||||
int chunk_pos;
|
||||
int chunk_size;
|
||||
int chunk_type;
|
||||
int c, frame;
|
||||
|
||||
FileHandle f(fop->filename.c_str(), "rb");
|
||||
if (!f)
|
||||
return false;
|
||||
|
||||
ASE_Header header;
|
||||
if (!ase_file_read_header(f, &header)) {
|
||||
fop_error(fop, "Error reading header\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the new sprite
|
||||
sprite = new Sprite(header.depth == 32 ? IMAGE_RGB:
|
||||
header.depth == 16 ? IMAGE_GRAYSCALE: IMAGE_INDEXED,
|
||||
header.width, header.height, header.ncolors);
|
||||
Sprite *sprite = new Sprite(header.depth == 32 ? IMAGE_RGB:
|
||||
header.depth == 16 ? IMAGE_GRAYSCALE: IMAGE_INDEXED,
|
||||
header.width, header.height, header.ncolors);
|
||||
if (!sprite) {
|
||||
fop_error(fop, "Error creating sprite with file spec\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set frames and speed
|
||||
sprite->setTotalFrames(header.frames);
|
||||
sprite->setTotalFrames(FrameNumber(header.frames));
|
||||
sprite->setDurationForAllFrames(header.speed);
|
||||
|
||||
// Set transparent entry
|
||||
@ -171,15 +162,16 @@ bool AseFormat::onLoad(FileOp *fop)
|
||||
|
||||
// Prepare variables for layer chunks
|
||||
Layer* last_layer = sprite->getFolder();
|
||||
current_level = -1;
|
||||
int current_level = -1;
|
||||
|
||||
/* read frame by frame to end-of-file */
|
||||
for (frame=0; frame<sprite->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<sprite->getTotalFrames(); ++frame) {
|
||||
/* start frame position */
|
||||
frame_pos = ftell(f);
|
||||
int frame_pos = ftell(f);
|
||||
fop_progress(fop, (float)frame_pos / (float)header.size);
|
||||
|
||||
/* read frame header */
|
||||
ASE_FrameHeader frame_header;
|
||||
ase_file_read_frame_header(f, &frame_header);
|
||||
|
||||
/* correct frame type */
|
||||
@ -189,14 +181,14 @@ bool AseFormat::onLoad(FileOp *fop)
|
||||
sprite->setFrameDuration(frame, frame_header.duration);
|
||||
|
||||
/* read chunks */
|
||||
for (c=0; c<frame_header.chunks; c++) {
|
||||
for (int c=0; c<frame_header.chunks; c++) {
|
||||
/* start chunk position */
|
||||
chunk_pos = ftell(f);
|
||||
int chunk_pos = ftell(f);
|
||||
fop_progress(fop, (float)chunk_pos / (float)header.size);
|
||||
|
||||
/* read chunk information */
|
||||
chunk_size = fgetl(f);
|
||||
chunk_type = fgetw(f);
|
||||
int chunk_size = fgetl(f);
|
||||
int chunk_type = fgetw(f);
|
||||
|
||||
switch (chunk_type) {
|
||||
|
||||
@ -206,8 +198,8 @@ bool AseFormat::onLoad(FileOp *fop)
|
||||
/* fop_error(fop, "Color chunk\n"); */
|
||||
|
||||
if (sprite->getPixelFormat() == IMAGE_INDEXED) {
|
||||
Palette *prev_pal = sprite->getPalette(frame);
|
||||
Palette *pal =
|
||||
Palette* prev_pal = sprite->getPalette(frame);
|
||||
Palette* pal =
|
||||
chunk_type == ASE_FILE_CHUNK_FLI_COLOR ?
|
||||
ase_file_read_color_chunk(f, sprite, frame):
|
||||
ase_file_read_color2_chunk(f, sprite, frame);
|
||||
@ -295,7 +287,6 @@ bool AseFormat::onSave(FileOp *fop)
|
||||
Sprite* sprite = fop->document->getSprite();
|
||||
ASE_Header header;
|
||||
ASE_FrameHeader frame_header;
|
||||
int frame;
|
||||
|
||||
FileHandle f(fop->filename.c_str(), "wb");
|
||||
|
||||
@ -303,7 +294,7 @@ bool AseFormat::onSave(FileOp *fop)
|
||||
ase_file_prepare_header(f, &header, sprite);
|
||||
|
||||
/* write frame */
|
||||
for (frame=0; frame<sprite->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<sprite->getTotalFrames(); ++frame) {
|
||||
/* prepare the header */
|
||||
ase_file_prepare_frame_header(f, &frame_header);
|
||||
|
||||
@ -313,7 +304,7 @@ bool AseFormat::onSave(FileOp *fop)
|
||||
/* the sprite is indexed and the palette changes? (or is the first frame) */
|
||||
if (sprite->getPixelFormat() == IMAGE_INDEXED &&
|
||||
(frame == 0 ||
|
||||
sprite->getPalette(frame-1)->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) {
|
||||
sprite->getPalette(frame.previous())->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) {
|
||||
/* write the color chunk */
|
||||
ase_file_write_color2_chunk(f, sprite->getPalette(frame));
|
||||
}
|
||||
@ -336,7 +327,7 @@ bool AseFormat::onSave(FileOp *fop)
|
||||
|
||||
/* progress */
|
||||
if (sprite->getTotalFrames() > 1)
|
||||
fop_progress(fop, (float)(frame+1) / (float)(sprite->getTotalFrames()));
|
||||
fop_progress(fop, (float)(frame.next()) / (float)(sprite->getTotalFrames()));
|
||||
}
|
||||
|
||||
/* write the header */
|
||||
@ -393,14 +384,14 @@ static void ase_file_prepare_header(FILE *f, ASE_Header *header, const Sprite* s
|
||||
sprite->getPixelFormat() == IMAGE_GRAYSCALE ? 16:
|
||||
sprite->getPixelFormat() == IMAGE_INDEXED ? 8: 0);
|
||||
header->flags = 0;
|
||||
header->speed = sprite->getFrameDuration(0);
|
||||
header->speed = sprite->getFrameDuration(FrameNumber(0));
|
||||
header->next = 0;
|
||||
header->frit = 0;
|
||||
header->transparent_index = sprite->getTransparentColor();
|
||||
header->ignore[0] = 0;
|
||||
header->ignore[1] = 0;
|
||||
header->ignore[2] = 0;
|
||||
header->ncolors = sprite->getPalette(0)->size();
|
||||
header->ncolors = sprite->getPalette(FrameNumber(0))->size();
|
||||
|
||||
fseek(f, header->pos+128, SEEK_SET);
|
||||
}
|
||||
@ -486,7 +477,7 @@ static void ase_file_write_layers(FILE *f, Layer *layer)
|
||||
}
|
||||
}
|
||||
|
||||
static void ase_file_write_cels(FILE *f, Sprite *sprite, Layer *layer, int frame)
|
||||
static void ase_file_write_cels(FILE *f, Sprite *sprite, Layer *layer, FrameNumber frame)
|
||||
{
|
||||
if (layer->is_image()) {
|
||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
||||
@ -563,7 +554,7 @@ static void ase_file_write_close_chunk(FILE *f)
|
||||
fseek(f, chunk_end, SEEK_SET);
|
||||
}
|
||||
|
||||
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, int frame)
|
||||
static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, FrameNumber frame)
|
||||
{
|
||||
int i, c, r, g, b, packets, skip, size;
|
||||
Palette* pal = new Palette(*sprite->getPalette(frame));
|
||||
@ -591,7 +582,7 @@ static Palette *ase_file_read_color_chunk(FILE *f, Sprite *sprite, int frame)
|
||||
return pal;
|
||||
}
|
||||
|
||||
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, int frame)
|
||||
static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, FrameNumber frame)
|
||||
{
|
||||
int i, c, r, g, b, packets, skip, size;
|
||||
Palette* pal = new Palette(*sprite->getPalette(frame));
|
||||
@ -989,7 +980,7 @@ static void write_compressed_image(FILE* f, Image* image)
|
||||
// Cel Chunk
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame,
|
||||
static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, FrameNumber frame,
|
||||
PixelFormat pixelFormat,
|
||||
FileOp *fop, ASE_Header *header, size_t chunk_end)
|
||||
{
|
||||
@ -1053,7 +1044,7 @@ static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame,
|
||||
|
||||
case ASE_FILE_LINK_CEL: {
|
||||
// Read link position
|
||||
int link_frame = fgetw(f);
|
||||
FrameNumber link_frame = FrameNumber(fgetw(f));
|
||||
Cel* link = static_cast<LayerImage*>(layer)->getCel(link_frame);
|
||||
|
||||
if (link) {
|
||||
|
@ -350,7 +350,7 @@ FileOp* fop_to_save_document(Document* document)
|
||||
// To save more frames
|
||||
else {
|
||||
char buf[256], left[256], right[256];
|
||||
int frame, width, start_from;
|
||||
int width, start_from;
|
||||
|
||||
start_from = split_filename(fop->document->getFilename(), left, right, &width);
|
||||
if (start_from < 0) {
|
||||
@ -361,7 +361,7 @@ FileOp* fop_to_save_document(Document* document)
|
||||
(fop->document->getSprite()->getTotalFrames() < 1000)? 3: 4;
|
||||
}
|
||||
|
||||
for (frame=0; frame<fop->document->getSprite()->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<fop->document->getSprite()->getTotalFrames(); ++frame) {
|
||||
/* get the name for this frame */
|
||||
usprintf(buf, "%s%0*d%s", left, width, start_from+frame, right);
|
||||
fop->seq.filename_list.push_back(buf);
|
||||
@ -408,7 +408,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress)
|
||||
fop->format->support(FILE_SUPPORT_LOAD)) {
|
||||
// Load a sequence
|
||||
if (fop->is_sequence()) {
|
||||
int frame, frames, image_index = 0;
|
||||
int image_index = 0;
|
||||
Image* old_image;
|
||||
bool loadres;
|
||||
|
||||
@ -437,8 +437,8 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress)
|
||||
} while (0)
|
||||
|
||||
/* load the sequence */
|
||||
frames = fop->seq.filename_list.size();
|
||||
frame = 0;
|
||||
FrameNumber frames(fop->seq.filename_list.size());
|
||||
FrameNumber frame(0);
|
||||
old_image = NULL;
|
||||
|
||||
fop->seq.has_alpha = false;
|
||||
@ -506,7 +506,7 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress)
|
||||
#endif
|
||||
}
|
||||
|
||||
frame++;
|
||||
++frame;
|
||||
fop->seq.progress_offset += fop->seq.progress_fraction;
|
||||
}
|
||||
fop->filename = *fop->seq.filename_list.begin();
|
||||
@ -548,13 +548,13 @@ void fop_operate(FileOp *fop, IFileOpProgress* progress)
|
||||
sprite->getWidth(),
|
||||
sprite->getHeight());
|
||||
if (fop->seq.image != NULL) {
|
||||
int old_frame = sprite->getCurrentFrame();
|
||||
FrameNumber old_frame = sprite->getCurrentFrame();
|
||||
|
||||
fop->seq.progress_offset = 0.0f;
|
||||
fop->seq.progress_fraction = 1.0f / (double)sprite->getTotalFrames();
|
||||
|
||||
// For each frame in the sprite.
|
||||
for (int frame=0; frame < sprite->getTotalFrames(); ++frame) {
|
||||
for (FrameNumber frame(0); frame < sprite->getTotalFrames(); ++frame) {
|
||||
// Draw the "frame" in "fop->seq.image"
|
||||
sprite->setCurrentFrame(frame);
|
||||
sprite->render(fop->seq.image, 0, 0);
|
||||
@ -658,7 +658,7 @@ void fop_post_load(FileOp* fop)
|
||||
// Creates a suitable palette for RGB images
|
||||
if (fop->document->getSprite()->getPixelFormat() == IMAGE_RGB &&
|
||||
fop->document->getSprite()->getPalettes().size() <= 1 &&
|
||||
fop->document->getSprite()->getPalette(0)->isBlack()) {
|
||||
fop->document->getSprite()->getPalette(FrameNumber(0))->isBlack()) {
|
||||
SharedPtr<Palette> palette(quantization::create_palette_from_rgb(fop->document->getSprite()));
|
||||
|
||||
fop->document->getSprite()->resetPalettes();
|
||||
@ -817,7 +817,7 @@ static FileOp* fop_new(FileOpType type)
|
||||
fop->seq.image = NULL;
|
||||
fop->seq.progress_offset = 0.0f;
|
||||
fop->seq.progress_fraction = 0.0f;
|
||||
fop->seq.frame = 0;
|
||||
fop->seq.frame = FrameNumber(0);
|
||||
fop->seq.layer = NULL;
|
||||
fop->seq.last_cel = NULL;
|
||||
|
||||
@ -826,7 +826,7 @@ static FileOp* fop_new(FileOpType type)
|
||||
|
||||
static void fop_prepare_for_sequence(FileOp* fop)
|
||||
{
|
||||
fop->seq.palette = new Palette(0, 256);
|
||||
fop->seq.palette = new Palette(FrameNumber(0), 256);
|
||||
fop->seq.format_options.reset();
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,12 @@
|
||||
#define FILE_FILE_H_INCLUDED
|
||||
|
||||
#include "base/shared_ptr.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/pixel_format.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define FILE_LOAD_SEQUENCE_NONE 0x00000001
|
||||
#define FILE_LOAD_SEQUENCE_ASK 0x00000002
|
||||
@ -82,7 +83,7 @@ struct FileOp
|
||||
double progress_offset; // Progress offset from the current frame.
|
||||
double progress_fraction; // Progress fraction for one frame.
|
||||
// To load sequences.
|
||||
int frame;
|
||||
FrameNumber frame;
|
||||
bool has_alpha;
|
||||
LayerImage* layer;
|
||||
Cel* last_cel;
|
||||
|
@ -75,8 +75,8 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
LayerImage *layer;
|
||||
Palette *pal;
|
||||
int c, w, h;
|
||||
int frpos_in;
|
||||
int frpos_out;
|
||||
FrameNumber frpos_in;
|
||||
FrameNumber frpos_out;
|
||||
int index = 0;
|
||||
Cel *cel;
|
||||
|
||||
@ -98,7 +98,7 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
/* create the bitmaps */
|
||||
bmp = Image::create(IMAGE_INDEXED, w, h);
|
||||
old = Image::create(IMAGE_INDEXED, w, h);
|
||||
pal = new Palette(0, 256);
|
||||
pal = new Palette(FrameNumber(0), 256);
|
||||
if (!bmp || !old || !pal) {
|
||||
fop_error(fop, "Not enough memory.\n");
|
||||
if (bmp) image_free(bmp);
|
||||
@ -114,13 +114,13 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
layer->configureAsBackground();
|
||||
|
||||
// Set frames and speed
|
||||
sprite->setTotalFrames(fli_header.frames);
|
||||
sprite->setTotalFrames(FrameNumber(fli_header.frames));
|
||||
sprite->setDurationForAllFrames(fli_header.speed);
|
||||
|
||||
/* write frame by frame */
|
||||
for (frpos_in=frpos_out=0;
|
||||
frpos_in<sprite->getTotalFrames();
|
||||
frpos_in++) {
|
||||
for (frpos_in = frpos_out = FrameNumber(0);
|
||||
frpos_in < sprite->getTotalFrames();
|
||||
++frpos_in) {
|
||||
/* read the frame */
|
||||
fli_read_frame(f, &fli_header,
|
||||
(unsigned char *)old->dat, omap,
|
||||
@ -135,7 +135,7 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
) {
|
||||
/* the image changes? */
|
||||
if (frpos_in != 0)
|
||||
frpos_out++;
|
||||
++frpos_out;
|
||||
|
||||
/* add the new frame */
|
||||
image = Image::createCopy(bmp);
|
||||
@ -161,7 +161,7 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
#ifdef USE_LINK
|
||||
/* the palette changes */
|
||||
else if (memcmp(omap, cmap, 768) != 0) {
|
||||
frpos_out++;
|
||||
++frpos_out;
|
||||
SETPAL();
|
||||
|
||||
// Add link
|
||||
@ -190,7 +190,7 @@ bool FliFormat::onLoad(FileOp* fop)
|
||||
}
|
||||
|
||||
// Update number of frames
|
||||
sprite->setTotalFrames(frpos_out+1);
|
||||
sprite->setTotalFrames(frpos_out.next());
|
||||
|
||||
// Destroy the bitmaps
|
||||
image_free(bmp);
|
||||
@ -207,7 +207,7 @@ bool FliFormat::onSave(FileOp* fop)
|
||||
unsigned char cmap[768];
|
||||
unsigned char omap[768];
|
||||
s_fli_header fli_header;
|
||||
int c, frpos, times;
|
||||
int c, times;
|
||||
Image *bmp, *old;
|
||||
Palette *pal;
|
||||
|
||||
@ -247,9 +247,9 @@ bool FliFormat::onSave(FileOp* fop)
|
||||
}
|
||||
|
||||
/* write frame by frame */
|
||||
for (frpos=0;
|
||||
frpos<sprite->getTotalFrames();
|
||||
frpos++) {
|
||||
for (FrameNumber frpos(0);
|
||||
frpos < sprite->getTotalFrames();
|
||||
++frpos) {
|
||||
/* get color map */
|
||||
pal = sprite->getPalette(frpos);
|
||||
for (c=0; c<256; c++) {
|
||||
@ -282,7 +282,7 @@ bool FliFormat::onSave(FileOp* fop)
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
fop_progress(fop, (float)(frpos+1) / (float)(sprite->getTotalFrames()));
|
||||
fop_progress(fop, (float)(frpos.next()) / (float)(sprite->getTotalFrames()));
|
||||
}
|
||||
|
||||
/* write the header and close the file */
|
||||
@ -298,10 +298,9 @@ bool FliFormat::onSave(FileOp* fop)
|
||||
static int get_time_precision(Sprite *sprite)
|
||||
{
|
||||
int precision = 1000;
|
||||
int c, len;
|
||||
|
||||
for (c = 0; c < sprite->getTotalFrames() && precision > 1; c++) {
|
||||
len = sprite->getFrameDuration(c);
|
||||
for (FrameNumber c(0); c < sprite->getTotalFrames() && precision > 1; ++c) {
|
||||
int len = sprite->getFrameDuration(c);
|
||||
|
||||
while (len / precision == 0)
|
||||
precision /= 10;
|
||||
|
@ -111,8 +111,8 @@ bool GifFormat::onLoad(FileOp* fop)
|
||||
data->sprite_w = gif_file->SWidth;
|
||||
data->sprite_h = gif_file->SHeight;
|
||||
|
||||
UniquePtr<Palette> current_palette(new Palette(0, 256));
|
||||
UniquePtr<Palette> previous_palette(new Palette(0, 256));
|
||||
UniquePtr<Palette> current_palette(new Palette(FrameNumber(0), 256));
|
||||
UniquePtr<Palette> previous_palette(new Palette(FrameNumber(0), 256));
|
||||
|
||||
// If the GIF image has a global palette, it has a valid
|
||||
// background color (so the GIF is not transparent).
|
||||
@ -133,7 +133,7 @@ bool GifFormat::onLoad(FileOp* fop)
|
||||
|
||||
// Scan the content of the GIF file (read record by record)
|
||||
GifRecordType record_type;
|
||||
size_t frame_num = 0;
|
||||
FrameNumber frame_num(0);
|
||||
DisposalMethod disposal_method = DISPOSAL_METHOD_NONE;
|
||||
int transparent_index = -1;
|
||||
int frame_delay = -1;
|
||||
@ -159,8 +159,8 @@ bool GifFormat::onLoad(FileOp* fop)
|
||||
throw base::Exception("Image %d is out of sprite bounds.\n", frame_num);
|
||||
|
||||
// Add a new frames.
|
||||
if (frame_num >= data->frames.size())
|
||||
data->frames.resize(frame_num+1);
|
||||
if (frame_num >= FrameNumber(data->frames.size()))
|
||||
data->frames.resize(frame_num.next());
|
||||
|
||||
data->frames[frame_num].x = frame_x;
|
||||
data->frames[frame_num].y = frame_y;
|
||||
@ -358,10 +358,10 @@ bool GifFormat::onPostLoad(FileOp* fop)
|
||||
image_clear(previous_image, bgcolor);
|
||||
|
||||
// Add all frames in the sprite.
|
||||
sprite->setTotalFrames(data->frames.size());
|
||||
sprite->setTotalFrames(FrameNumber(data->frames.size()));
|
||||
Palette* current_palette = NULL;
|
||||
|
||||
size_t frame_num = 0;
|
||||
FrameNumber frame_num(0);
|
||||
for (GifFrames::iterator
|
||||
frame_it=data->frames.begin(),
|
||||
frame_end=data->frames.end(); frame_it != frame_end; ++frame_it, ++frame_num) {
|
||||
@ -496,7 +496,7 @@ bool GifFormat::onSave(FileOp* fop)
|
||||
int background_color = (sprite_format == IMAGE_INDEXED ? sprite->getTransparentColor(): 0);
|
||||
int transparent_index = (sprite->getBackgroundLayer() ? -1: sprite->getTransparentColor());
|
||||
|
||||
Palette* current_palette = sprite->getPalette(0);
|
||||
Palette* current_palette = sprite->getPalette(FrameNumber(0));
|
||||
Palette* previous_palette = current_palette;
|
||||
ColorMapObject* color_map = MakeMapObject(current_palette->size(), NULL);
|
||||
for (int i = 0; i < current_palette->size(); ++i) {
|
||||
@ -525,7 +525,7 @@ bool GifFormat::onSave(FileOp* fop)
|
||||
image_clear(current_image, background_color);
|
||||
image_clear(previous_image, background_color);
|
||||
|
||||
for (int frame_num=0; frame_num<sprite->getTotalFrames(); ++frame_num) {
|
||||
for (FrameNumber frame_num(0); frame_num<sprite->getTotalFrames(); ++frame_num) {
|
||||
current_palette = sprite->getPalette(frame_num);
|
||||
|
||||
// If the sprite is RGB or Grayscale, we must to convert it to Indexed on the fly.
|
||||
|
@ -138,7 +138,7 @@ bool IcoFormat::onLoad(FileOp* fop)
|
||||
// Create the first image/cel
|
||||
Image* image = Image::create(pixelFormat, width, height);
|
||||
int image_index = sprite->getStock()->addImage(image);
|
||||
Cel* cel = new Cel(0, image_index);
|
||||
Cel* cel = new Cel(FrameNumber(0), image_index);
|
||||
layer->addCel(cel);
|
||||
image_clear(image, 0);
|
||||
|
||||
@ -161,7 +161,7 @@ bool IcoFormat::onLoad(FileOp* fop)
|
||||
|
||||
// Read the palette
|
||||
if (entry.bpp <= 8) {
|
||||
Palette* pal = new Palette(0, numcolors);
|
||||
Palette* pal = new Palette(FrameNumber(0), numcolors);
|
||||
|
||||
for (int i=0; i<numcolors; ++i) {
|
||||
int b = fgetc(f);
|
||||
@ -235,9 +235,9 @@ bool IcoFormat::onSave(FileOp* fop)
|
||||
{
|
||||
Sprite* sprite = fop->document->getSprite();
|
||||
int bpp, bw, bitsw;
|
||||
int size, offset, n, i;
|
||||
int size, offset, i;
|
||||
int c, x, y, b, m, v;
|
||||
int num = sprite->getTotalFrames();
|
||||
FrameNumber n, num = sprite->getTotalFrames();
|
||||
|
||||
FileHandle f(fop->filename.c_str(), "wb");
|
||||
|
||||
@ -249,7 +249,7 @@ bool IcoFormat::onSave(FileOp* fop)
|
||||
fputw(num, f); // number of icons
|
||||
|
||||
// Entries
|
||||
for (n=0; n<num; ++n) {
|
||||
for (n=FrameNumber(0); n<num; ++n) {
|
||||
bpp = (sprite->getPixelFormat() == IMAGE_INDEXED) ? 8 : 24;
|
||||
bw = (((sprite->getWidth() * bpp / 8) + 3) / 4) * 4;
|
||||
bitsw = ((((sprite->getWidth() + 7) / 8) + 3) / 4) * 4;
|
||||
@ -275,7 +275,7 @@ bool IcoFormat::onSave(FileOp* fop)
|
||||
sprite->getWidth(),
|
||||
sprite->getHeight());
|
||||
|
||||
for (n=0; n<num; ++n) {
|
||||
for (n=FrameNumber(0); n<num; ++n) {
|
||||
image_clear(image, 0);
|
||||
layer_render(sprite->getFolder(), image, 0, 0, n);
|
||||
|
||||
|
@ -21,19 +21,21 @@
|
||||
#include "base/unique_ptr.h"
|
||||
#include "gfx/rect.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/layer.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "raster/stock.h"
|
||||
|
||||
static bool has_cels(const Layer* layer, int frame);
|
||||
static bool has_cels(const Layer* layer, FrameNumber frame);
|
||||
|
||||
LayerImage* create_flatten_layer_copy(Sprite* dstSprite, const Layer* srcLayer,
|
||||
const gfx::Rect& bounds, int frmin, int frmax)
|
||||
const gfx::Rect& bounds,
|
||||
FrameNumber frmin, FrameNumber frmax)
|
||||
{
|
||||
UniquePtr<LayerImage> flatLayer(new LayerImage(dstSprite));
|
||||
|
||||
for (int frame=frmin; frame<=frmax; frame++) {
|
||||
for (FrameNumber frame=frmin; frame<=frmax; ++frame) {
|
||||
// Does this frame have cels to render?
|
||||
if (has_cels(srcLayer, frame)) {
|
||||
// Create a new image to render each frame.
|
||||
@ -62,7 +64,7 @@ LayerImage* create_flatten_layer_copy(Sprite* dstSprite, const Layer* srcLayer,
|
||||
|
||||
// Returns true if the "layer" or its children have any cel to render
|
||||
// in the given "frame".
|
||||
static bool has_cels(const Layer* layer, int frame)
|
||||
static bool has_cels(const Layer* layer, FrameNumber frame)
|
||||
{
|
||||
if (!layer->is_readable())
|
||||
return false;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define FLATTEN_H_INCLUDED
|
||||
|
||||
#include "gfx/Rect.h"
|
||||
#include "raster/frame_number.h"
|
||||
|
||||
class Sprite;
|
||||
class Layer;
|
||||
@ -33,6 +34,7 @@ class LayerImage;
|
||||
// it, so you'll be able to add the flatten layer only into the given
|
||||
// sprite.
|
||||
LayerImage* create_flatten_layer_copy(Sprite* dstSprite, const Layer* srcLayer,
|
||||
const gfx::Rect& bounds, int frmin, int frmax);
|
||||
const gfx::Rect& bounds,
|
||||
FrameNumber frmin, FrameNumber frmax);
|
||||
|
||||
#endif
|
||||
|
@ -43,10 +43,10 @@ static Palette* ase_current_palette = NULL;
|
||||
|
||||
int init_module_palette()
|
||||
{
|
||||
ase_default_palette = new Palette(0, 256);
|
||||
ase_default_palette = new Palette(FrameNumber(0), 256);
|
||||
ase_default_palette->fromAllegro(default_palette);
|
||||
|
||||
ase_current_palette = new Palette(0, 256);
|
||||
ase_current_palette = new Palette(FrameNumber(0), 256);
|
||||
ase_current_palette->fromAllegro(black_palette);
|
||||
|
||||
return 0;
|
||||
@ -106,7 +106,7 @@ bool set_current_palette(const Palette *_palette, bool forced)
|
||||
|
||||
void set_black_palette()
|
||||
{
|
||||
Palette* p = new Palette(0, 256);
|
||||
Palette* p = new Palette(FrameNumber(0), 256);
|
||||
set_current_palette(p, true);
|
||||
delete p;
|
||||
}
|
||||
|
@ -20,11 +20,11 @@
|
||||
|
||||
#include "raster/cel.h"
|
||||
|
||||
Cel::Cel(int frame, int image)
|
||||
Cel::Cel(FrameNumber frame, int image)
|
||||
: GfxObj(GFXOBJ_CEL)
|
||||
, m_frame(frame)
|
||||
, m_image(image)
|
||||
{
|
||||
m_frame = frame;
|
||||
m_image = image;
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_opacity = 255;
|
||||
@ -32,9 +32,9 @@ Cel::Cel(int frame, int image)
|
||||
|
||||
Cel::Cel(const Cel& cel)
|
||||
: GfxObj(cel)
|
||||
, m_frame(cel.m_frame)
|
||||
, m_image(cel.m_image)
|
||||
{
|
||||
m_frame = cel.m_frame;
|
||||
m_image = cel.m_image;
|
||||
m_x = cel.m_x;
|
||||
m_y = cel.m_y;
|
||||
m_opacity = cel.m_opacity;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef RASTER_CEL_H_INCLUDED
|
||||
#define RASTER_CEL_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
class LayerImage;
|
||||
@ -26,17 +27,17 @@ class LayerImage;
|
||||
class Cel : public GfxObj
|
||||
{
|
||||
public:
|
||||
Cel(int frame, int image);
|
||||
Cel(FrameNumber frame, int image);
|
||||
Cel(const Cel& cel);
|
||||
virtual ~Cel();
|
||||
|
||||
int getFrame() const { return m_frame; }
|
||||
FrameNumber getFrame() const { return m_frame; }
|
||||
int getImage() const { return m_image; }
|
||||
int getX() const { return m_x; }
|
||||
int getY() const { return m_y; }
|
||||
int getOpacity() const { return m_opacity; }
|
||||
|
||||
void setFrame(int frame) { m_frame = frame; }
|
||||
void setFrame(FrameNumber frame) { m_frame = frame; }
|
||||
void setImage(int image) { m_image = image; }
|
||||
void setPosition(int x, int y) { m_x = x; m_y = y; }
|
||||
void setOpacity(int opacity) { m_opacity = opacity; }
|
||||
@ -46,7 +47,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int m_frame; // Frame position
|
||||
FrameNumber m_frame; // Frame position
|
||||
int m_image; // Image index of stock
|
||||
int m_x, m_y; // X/Y screen position
|
||||
int m_opacity; // Opacity level
|
||||
|
@ -56,7 +56,7 @@ Cel* read_cel(std::istream& is)
|
||||
{
|
||||
// ObjectId cel_id = read32();
|
||||
|
||||
int frame = read16(is);
|
||||
FrameNumber frame(read16(is));
|
||||
int imageIndex = read16(is);
|
||||
int x = (int16_t)read16(is);
|
||||
int y = (int16_t)read16(is);
|
||||
|
57
src/raster/frame_number.h
Normal file
57
src/raster/frame_number.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef RASTER_FRAME_NUMBER_H_INCLUDED
|
||||
#define RASTER_FRAME_NUMBER_H_INCLUDED
|
||||
|
||||
class FrameNumber {
|
||||
public:
|
||||
FrameNumber() : m_value(0) { }
|
||||
explicit FrameNumber(int value) : m_value(value) { }
|
||||
|
||||
FrameNumber next(int i = 1) const { return FrameNumber(m_value+i); };
|
||||
FrameNumber previous(int i = 1) const { return FrameNumber(m_value-i); };
|
||||
|
||||
operator int() { return m_value; }
|
||||
operator const int() const { return m_value; }
|
||||
|
||||
FrameNumber& operator=(const FrameNumber& o) { m_value = o.m_value; return *this; }
|
||||
FrameNumber& operator++() { ++m_value; return *this; }
|
||||
FrameNumber& operator--() { --m_value; return *this; }
|
||||
FrameNumber operator++(int) { FrameNumber old(*this); ++m_value; return old; }
|
||||
FrameNumber operator--(int) { FrameNumber old(*this); --m_value; return old; }
|
||||
bool operator<(const FrameNumber& o) const { return m_value < o.m_value; }
|
||||
bool operator>(const FrameNumber& o) const { return m_value > o.m_value; }
|
||||
bool operator<=(const FrameNumber& o) const { return m_value <= o.m_value; }
|
||||
bool operator>=(const FrameNumber& o) const { return m_value >= o.m_value; }
|
||||
bool operator==(const FrameNumber& o) const { return m_value == o.m_value; }
|
||||
bool operator!=(const FrameNumber& o) const { return m_value != o.m_value; }
|
||||
|
||||
private:
|
||||
int m_value;
|
||||
};
|
||||
|
||||
inline FrameNumber operator+(const FrameNumber& x, const FrameNumber& y) {
|
||||
return FrameNumber((int)x + (int)y);
|
||||
}
|
||||
|
||||
inline FrameNumber operator-(const FrameNumber& x, const FrameNumber& y) {
|
||||
return FrameNumber((int)x - (int)y);
|
||||
}
|
||||
|
||||
#endif
|
@ -39,7 +39,6 @@ ImagesCollector::ImagesCollector(const Sprite* sprite, bool allLayers, bool allF
|
||||
void ImagesCollector::collectFromLayer(Layer* layer)
|
||||
{
|
||||
const Sprite* sprite = layer->getSprite();
|
||||
int frame = sprite->getCurrentFrame();
|
||||
|
||||
if (!layer->is_readable())
|
||||
return;
|
||||
@ -51,13 +50,14 @@ void ImagesCollector::collectFromLayer(Layer* layer)
|
||||
|
||||
case GFXOBJ_LAYER_IMAGE: {
|
||||
if (m_allFrames) {
|
||||
for (frame=0; frame<sprite->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<sprite->getTotalFrames(); ++frame) {
|
||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
||||
if (cel != NULL)
|
||||
collectImage(layer, cel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
FrameNumber frame = sprite->getCurrentFrame();
|
||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame);
|
||||
if (cel != NULL)
|
||||
collectImage(layer, cel);
|
||||
|
@ -175,7 +175,7 @@ void LayerImage::removeCel(Cel *cel)
|
||||
m_cels.erase(it);
|
||||
}
|
||||
|
||||
const Cel* LayerImage::getCel(int frame) const
|
||||
const Cel* LayerImage::getCel(FrameNumber frame) const
|
||||
{
|
||||
CelConstIterator it = getCelBegin();
|
||||
CelConstIterator end = getCelEnd();
|
||||
@ -189,7 +189,7 @@ const Cel* LayerImage::getCel(int frame) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Cel* LayerImage::getCel(int frame)
|
||||
Cel* LayerImage::getCel(FrameNumber frame)
|
||||
{
|
||||
return const_cast<Cel*>(static_cast<const LayerImage*>(this)->getCel(frame));
|
||||
}
|
||||
@ -301,7 +301,7 @@ void LayerFolder::move_layer(Layer* layer, Layer* after)
|
||||
// jlist_prepend(m_layers, layer);
|
||||
}
|
||||
|
||||
void layer_render(const Layer* layer, Image* image, int x, int y, int frame)
|
||||
void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber frame)
|
||||
{
|
||||
if (!layer->is_readable())
|
||||
return;
|
||||
|
@ -19,9 +19,11 @@
|
||||
#ifndef RASTER_LAYER_H_INCLUDED
|
||||
#define RASTER_LAYER_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "raster/gfxobj.h"
|
||||
#include "raster/blend.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class Cel;
|
||||
class Image;
|
||||
@ -101,8 +103,8 @@ public:
|
||||
|
||||
void addCel(Cel *cel);
|
||||
void removeCel(Cel *cel);
|
||||
const Cel* getCel(int frame) const;
|
||||
Cel* getCel(int frame);
|
||||
const Cel* getCel(FrameNumber frame) const;
|
||||
Cel* getCel(FrameNumber frame);
|
||||
|
||||
void getCels(CelList& cels);
|
||||
|
||||
@ -150,6 +152,6 @@ private:
|
||||
LayerList m_layers;
|
||||
};
|
||||
|
||||
void layer_render(const Layer* layer, Image *image, int x, int y, int frame);
|
||||
void layer_render(const Layer* layer, Image *image, int x, int y, FrameNumber frame);
|
||||
|
||||
#endif
|
||||
|
@ -32,7 +32,7 @@ using namespace gfx;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
Palette::Palette(int frame, int ncolors)
|
||||
Palette::Palette(FrameNumber frame, int ncolors)
|
||||
: GfxObj(GFXOBJ_PALETTE)
|
||||
{
|
||||
ASSERT(ncolors >= 1 && ncolors <= MaxColors);
|
||||
@ -58,7 +58,7 @@ Palette::~Palette()
|
||||
|
||||
Palette* Palette::createGrayscale()
|
||||
{
|
||||
Palette* graypal = new Palette(0, MaxColors);
|
||||
Palette* graypal = new Palette(FrameNumber(0), MaxColors);
|
||||
for (int c=0; c<MaxColors; c++)
|
||||
graypal->setEntry(c, _rgba(c, c, c, 255));
|
||||
return graypal;
|
||||
@ -81,7 +81,7 @@ void Palette::resize(int ncolors)
|
||||
++m_modifications;
|
||||
}
|
||||
|
||||
void Palette::setFrame(int frame)
|
||||
void Palette::setFrame(FrameNumber frame)
|
||||
{
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
@ -445,7 +445,7 @@ Palette* Palette::load(const char *filename)
|
||||
if (bmp) {
|
||||
destroy_bitmap(bmp);
|
||||
|
||||
pal = new Palette(0, MaxColors);
|
||||
pal = new Palette(FrameNumber(0), MaxColors);
|
||||
pal->fromAllegro(rgbpal);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@
|
||||
#ifndef RASTER_PALETTE_H_INCLUDED
|
||||
#define RASTER_PALETTE_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/gfxobj.h"
|
||||
|
||||
#include <allegro/color.h>
|
||||
#include <vector>
|
||||
|
||||
@ -55,7 +57,7 @@ class Palette : public GfxObj
|
||||
public:
|
||||
enum { MaxColors = 256 };
|
||||
|
||||
Palette(int frame, int ncolors);
|
||||
Palette(FrameNumber frame, int ncolors);
|
||||
Palette(const Palette& palette);
|
||||
~Palette();
|
||||
|
||||
@ -66,8 +68,8 @@ public:
|
||||
|
||||
int getModifications() const { return m_modifications; }
|
||||
|
||||
int getFrame() const { return m_frame; }
|
||||
void setFrame(int frame);
|
||||
FrameNumber getFrame() const { return m_frame; }
|
||||
void setFrame(FrameNumber frame);
|
||||
|
||||
uint32_t getEntry(int i) const {
|
||||
ASSERT(i >= 0 && i < size());
|
||||
@ -98,7 +100,7 @@ public:
|
||||
int findBestfit(int r, int g, int b) const;
|
||||
|
||||
private:
|
||||
int m_frame;
|
||||
FrameNumber m_frame;
|
||||
std::vector<uint32_t> m_colors;
|
||||
int m_modifications;
|
||||
};
|
||||
|
@ -51,8 +51,8 @@ void write_palette(std::ostream& os, Palette* palette)
|
||||
|
||||
Palette* read_palette(std::istream& is)
|
||||
{
|
||||
int frame = read16(is); // Frame
|
||||
int ncolors = read16(is); // Number of colors
|
||||
FrameNumber frame(read16(is)); // Frame
|
||||
int ncolors = read16(is); // Number of colors
|
||||
|
||||
UniquePtr<Palette> palette(new Palette(frame, ncolors));
|
||||
|
||||
|
@ -46,7 +46,7 @@ static void create_palette_from_bitmaps(const std::vector<Image*>& images, Palet
|
||||
Palette* quantization::create_palette_from_rgb(const Sprite* sprite)
|
||||
{
|
||||
bool has_background_layer = (sprite->getBackgroundLayer() != NULL);
|
||||
Palette* palette = new Palette(0, 256);
|
||||
Palette* palette = new Palette(FrameNumber(0), 256);
|
||||
Image* flat_image;
|
||||
|
||||
ImagesCollector images(sprite,
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "raster/blend.h"
|
||||
#include "raster/cel.h"
|
||||
#include "raster/dirty.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/gfxobj.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/layer.h"
|
||||
|
@ -38,18 +38,18 @@ Sprite::Sprite(PixelFormat format, int width, int height, int ncolors)
|
||||
, m_format(format)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_frames(1)
|
||||
, m_frame(0)
|
||||
{
|
||||
ASSERT(width > 0 && height > 0);
|
||||
|
||||
m_frames = 1;
|
||||
m_frlens.push_back(100); // First frame with 100 msecs of duration
|
||||
m_frame = 0;
|
||||
m_stock = new Stock(format);
|
||||
m_folder = new LayerFolder(this);
|
||||
m_layer = NULL;
|
||||
|
||||
// Generate palette
|
||||
Palette pal(0, ncolors);
|
||||
Palette pal(FrameNumber(0), ncolors);
|
||||
|
||||
switch (format) {
|
||||
|
||||
@ -197,7 +197,7 @@ int Sprite::layerToIndex(const Layer* layer) const
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Palettes
|
||||
|
||||
Palette* Sprite::getPalette(int frame) const
|
||||
Palette* Sprite::getPalette(FrameNumber frame) const
|
||||
{
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
@ -285,7 +285,7 @@ RgbMap* Sprite::getRgbMap()
|
||||
return getRgbMap(getCurrentFrame());
|
||||
}
|
||||
|
||||
RgbMap* Sprite::getRgbMap(int frame)
|
||||
RgbMap* Sprite::getRgbMap(FrameNumber frame)
|
||||
{
|
||||
if (m_rgbMap == NULL) {
|
||||
m_rgbMap = new RgbMap();
|
||||
@ -300,21 +300,20 @@ RgbMap* Sprite::getRgbMap(int frame)
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Frames
|
||||
|
||||
void Sprite::setTotalFrames(int frames)
|
||||
void Sprite::setTotalFrames(FrameNumber frames)
|
||||
{
|
||||
frames = MAX(1, frames);
|
||||
frames = MAX(FrameNumber(1), frames);
|
||||
m_frlens.resize(frames);
|
||||
|
||||
if (frames > m_frames) {
|
||||
int c;
|
||||
for (c=m_frames; c<frames; c++)
|
||||
m_frlens[c] = m_frlens[m_frames-1];
|
||||
for (FrameNumber c=m_frames; c<frames; ++c)
|
||||
m_frlens[c] = m_frlens[m_frames.previous()];
|
||||
}
|
||||
|
||||
m_frames = frames;
|
||||
}
|
||||
|
||||
int Sprite::getFrameDuration(int frame) const
|
||||
int Sprite::getFrameDuration(FrameNumber frame) const
|
||||
{
|
||||
if (frame >= 0 && frame < m_frames)
|
||||
return m_frlens[frame];
|
||||
@ -322,7 +321,7 @@ int Sprite::getFrameDuration(int frame) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sprite::setFrameDuration(int frame, int msecs)
|
||||
void Sprite::setFrameDuration(FrameNumber frame, int msecs)
|
||||
{
|
||||
if (frame >= 0 && frame < m_frames)
|
||||
m_frlens[frame] = MID(1, msecs, 65535);
|
||||
@ -333,7 +332,7 @@ void Sprite::setDurationForAllFrames(int msecs)
|
||||
std::fill(m_frlens.begin(), m_frlens.end(), MID(1, msecs, 65535));
|
||||
}
|
||||
|
||||
void Sprite::setCurrentFrame(int frame)
|
||||
void Sprite::setCurrentFrame(FrameNumber frame)
|
||||
{
|
||||
m_frame = frame;
|
||||
}
|
||||
@ -373,7 +372,7 @@ void Sprite::getCels(CelList& cels)
|
||||
getFolder()->getCels(cels);
|
||||
}
|
||||
|
||||
void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping)
|
||||
void Sprite::remapImages(FrameNumber frameFrom, FrameNumber frameTo, const std::vector<uint8_t>& mapping)
|
||||
{
|
||||
ASSERT(m_format == IMAGE_INDEXED);
|
||||
ASSERT(mapping.size() == 256);
|
||||
@ -385,8 +384,8 @@ void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t
|
||||
Cel* cel = *it;
|
||||
|
||||
// Remap this Cel because is inside the specified range
|
||||
if (cel->getFrame() >= frame_from &&
|
||||
cel->getFrame() <= frame_to) {
|
||||
if (cel->getFrame() >= frameFrom &&
|
||||
cel->getFrame() <= frameTo) {
|
||||
Image* image = getStock()->getImage(cel->getImage());
|
||||
|
||||
for (int y=0; y<image->h; ++y) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define RASTER_SPRITE_H_INCLUDED
|
||||
|
||||
#include "base/disable_copying.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/gfxobj.h"
|
||||
#include "raster/pixel_format.h"
|
||||
|
||||
@ -85,7 +86,7 @@ public:
|
||||
////////////////////////////////////////
|
||||
// Palettes
|
||||
|
||||
Palette* getPalette(int frame) const;
|
||||
Palette* getPalette(FrameNumber frame) const;
|
||||
const PalettesList& getPalettes() const;
|
||||
|
||||
void setPalette(const Palette* pal, bool truncate);
|
||||
@ -98,24 +99,25 @@ public:
|
||||
Palette* getCurrentPalette() const;
|
||||
|
||||
RgbMap* getRgbMap();
|
||||
RgbMap* getRgbMap(int frame);
|
||||
RgbMap* getRgbMap(FrameNumber frame);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Frames
|
||||
|
||||
int getTotalFrames() const { return m_frames; }
|
||||
FrameNumber getTotalFrames() const { return m_frames; }
|
||||
FrameNumber getLastFrame() const { return m_frames.previous(); }
|
||||
|
||||
// Changes the quantity of frames
|
||||
void setTotalFrames(int frames);
|
||||
void setTotalFrames(FrameNumber frames);
|
||||
|
||||
int getFrameDuration(int frame) const;
|
||||
void setFrameDuration(int frame, int msecs);
|
||||
int getFrameDuration(FrameNumber frame) const;
|
||||
void setFrameDuration(FrameNumber frame, int msecs);
|
||||
|
||||
// Sets a constant frame-rate.
|
||||
void setDurationForAllFrames(int msecs);
|
||||
|
||||
int getCurrentFrame() const { return m_frame; }
|
||||
void setCurrentFrame(int frame);
|
||||
FrameNumber getCurrentFrame() const { return m_frame; }
|
||||
void setCurrentFrame(FrameNumber frame);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Images
|
||||
@ -126,7 +128,7 @@ public:
|
||||
|
||||
void getCels(CelList& cels);
|
||||
|
||||
void remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping);
|
||||
void remapImages(FrameNumber frameFrom, FrameNumber frameTo, const std::vector<uint8_t>& mapping);
|
||||
|
||||
// Draws the sprite in the given image at the given position. Before
|
||||
// drawing the sprite, this function clears (with the sprite's
|
||||
@ -144,9 +146,9 @@ private:
|
||||
PixelFormat m_format; // pixel format
|
||||
int m_width; // image width (in pixels)
|
||||
int m_height; // image height (in pixels)
|
||||
int m_frames; // how many frames has this sprite
|
||||
FrameNumber m_frames; // how many frames has this sprite
|
||||
std::vector<int> m_frlens; // duration per frame
|
||||
int m_frame; // current frame, range [0,frames)
|
||||
FrameNumber m_frame; // current frame, range [0,frames)
|
||||
PalettesList m_palettes; // list of palettes
|
||||
Stock* m_stock; // stock to get images
|
||||
LayerFolder* m_folder; // main folder of layers
|
||||
|
@ -72,7 +72,7 @@ private:
|
||||
NULL;
|
||||
if (!fop_is_stop(m_fop) && sprite) {
|
||||
// The palette to convert the Image to a BITMAP
|
||||
m_palette.reset(new Palette(*sprite->getPalette(0)));
|
||||
m_palette.reset(new Palette(*sprite->getPalette(FrameNumber(0))));
|
||||
|
||||
// Render the 'sprite' in one plain 'image'
|
||||
UniquePtr<Image> image(Image::create(sprite->getPixelFormat(),
|
||||
|
@ -150,7 +150,7 @@ undo::ObjectsContainer* UndoTransaction::getObjects() const
|
||||
return m_undo->getObjects();
|
||||
}
|
||||
|
||||
void UndoTransaction::setNumberOfFrames(int frames)
|
||||
void UndoTransaction::setNumberOfFrames(FrameNumber frames)
|
||||
{
|
||||
ASSERT(frames >= 1);
|
||||
|
||||
@ -162,7 +162,7 @@ void UndoTransaction::setNumberOfFrames(int frames)
|
||||
m_sprite->setTotalFrames(frames);
|
||||
}
|
||||
|
||||
void UndoTransaction::setCurrentFrame(int frame)
|
||||
void UndoTransaction::setCurrentFrame(FrameNumber frame)
|
||||
{
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
@ -215,7 +215,7 @@ void UndoTransaction::cropSprite(const gfx::Rect& bounds, int bgcolor)
|
||||
|
||||
void UndoTransaction::trimSprite(int bgcolor)
|
||||
{
|
||||
int old_frame = m_sprite->getCurrentFrame();
|
||||
FrameNumber old_frame = m_sprite->getCurrentFrame();
|
||||
gfx::Rect bounds;
|
||||
|
||||
UniquePtr<Image> image_wrap(Image::create(m_sprite->getPixelFormat(),
|
||||
@ -223,7 +223,7 @@ void UndoTransaction::trimSprite(int bgcolor)
|
||||
m_sprite->getHeight()));
|
||||
Image* image = image_wrap.get();
|
||||
|
||||
for (int frame=0; frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
for (FrameNumber frame(0); frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
image->clear(0);
|
||||
|
||||
m_sprite->setCurrentFrame(frame);
|
||||
@ -295,7 +295,7 @@ void UndoTransaction::setPixelFormat(PixelFormat newFormat, DitheringMethod dith
|
||||
}
|
||||
|
||||
m_undo->pushUndoer(new undoers::AddPalette(
|
||||
m_undo->getObjects(), m_sprite, 0));
|
||||
m_undo->getObjects(), m_sprite, FrameNumber(0)));
|
||||
}
|
||||
|
||||
// It's a UniquePtr because setPalette'll create a copy of "graypal".
|
||||
@ -419,12 +419,12 @@ void UndoTransaction::removeLayer(Layer* layer)
|
||||
delete layer;
|
||||
}
|
||||
|
||||
void UndoTransaction::moveLayerAfter(Layer* layer, Layer* after_this)
|
||||
void UndoTransaction::moveLayerAfter(Layer* layer, Layer* afterThis)
|
||||
{
|
||||
if (isEnabled())
|
||||
m_undo->pushUndoer(new undoers::MoveLayer(m_undo->getObjects(), layer));
|
||||
|
||||
layer->get_parent()->move_layer(layer, after_this);
|
||||
layer->get_parent()->move_layer(layer, afterThis);
|
||||
}
|
||||
|
||||
void UndoTransaction::cropLayer(Layer* layer, int x, int y, int w, int h, int bgcolor)
|
||||
@ -522,7 +522,7 @@ void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor)
|
||||
}
|
||||
|
||||
// Fill all empty cels with a flat-image filled with bgcolor
|
||||
for (int frame=0; frame<m_sprite->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
Cel* cel = layer->getCel(frame);
|
||||
if (!cel) {
|
||||
Image* cel_image = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight());
|
||||
@ -563,7 +563,6 @@ void UndoTransaction::flattenLayers(int bgcolor)
|
||||
{
|
||||
Image* cel_image;
|
||||
Cel* cel;
|
||||
int frame;
|
||||
|
||||
// create a temporary image
|
||||
UniquePtr<Image> image_wrap(Image::create(m_sprite->getPixelFormat(),
|
||||
@ -591,7 +590,7 @@ void UndoTransaction::flattenLayers(int bgcolor)
|
||||
}
|
||||
|
||||
/* copy all frames to the background */
|
||||
for (frame=0; frame<m_sprite->getTotalFrames(); frame++) {
|
||||
for (FrameNumber frame(0); frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
/* clear the image and render this frame */
|
||||
image_clear(image, bgcolor);
|
||||
layer_render(m_sprite->getFolder(), image, 0, 0, frame);
|
||||
@ -671,18 +670,19 @@ void UndoTransaction::configureLayerAsBackground(LayerImage* layer)
|
||||
|
||||
void UndoTransaction::newFrame()
|
||||
{
|
||||
FrameNumber newFrame = m_sprite->getCurrentFrame().next();
|
||||
|
||||
// add a new cel to every layer
|
||||
newFrameForLayer(m_sprite->getFolder(),
|
||||
m_sprite->getCurrentFrame()+1);
|
||||
newFrameForLayer(m_sprite->getFolder(), newFrame);
|
||||
|
||||
// increment frames counter in the sprite
|
||||
setNumberOfFrames(m_sprite->getTotalFrames()+1);
|
||||
setNumberOfFrames(m_sprite->getTotalFrames() + FrameNumber(1));
|
||||
|
||||
// go to next frame (the new one)
|
||||
setCurrentFrame(m_sprite->getCurrentFrame()+1);
|
||||
setCurrentFrame(newFrame);
|
||||
}
|
||||
|
||||
void UndoTransaction::newFrameForLayer(Layer* layer, int frame)
|
||||
void UndoTransaction::newFrameForLayer(Layer* layer, FrameNumber frame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(frame >= 0);
|
||||
@ -691,10 +691,10 @@ void UndoTransaction::newFrameForLayer(Layer* layer, int frame)
|
||||
|
||||
case GFXOBJ_LAYER_IMAGE:
|
||||
// displace all cels in '>=frame' to the next frame
|
||||
for (int c=m_sprite->getTotalFrames()-1; c>=frame; --c) {
|
||||
for (FrameNumber c=m_sprite->getLastFrame(); c>=frame; --c) {
|
||||
Cel* cel = static_cast<LayerImage*>(layer)->getCel(c);
|
||||
if (cel)
|
||||
setCelFramePosition(cel, cel->getFrame()+1);
|
||||
setCelFramePosition(cel, cel->getFrame().next());
|
||||
}
|
||||
|
||||
copyPreviousFrame(layer, frame);
|
||||
@ -712,7 +712,7 @@ void UndoTransaction::newFrameForLayer(Layer* layer, int frame)
|
||||
}
|
||||
}
|
||||
|
||||
void UndoTransaction::removeFrame(int frame)
|
||||
void UndoTransaction::removeFrame(FrameNumber frame)
|
||||
{
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
@ -721,17 +721,17 @@ void UndoTransaction::removeFrame(int frame)
|
||||
removeFrameOfLayer(m_sprite->getFolder(), frame);
|
||||
|
||||
// New value for totalFrames propety
|
||||
int newTotalFrames = m_sprite->getTotalFrames()-1;
|
||||
FrameNumber newTotalFrames = m_sprite->getTotalFrames() - FrameNumber(1);
|
||||
|
||||
// Move backward if we will be outside the range of frames
|
||||
if (m_sprite->getCurrentFrame() >= newTotalFrames)
|
||||
setCurrentFrame(newTotalFrames-1);
|
||||
setCurrentFrame(newTotalFrames.previous());
|
||||
|
||||
// Decrement frames counter in the sprite
|
||||
setNumberOfFrames(newTotalFrames);
|
||||
}
|
||||
|
||||
void UndoTransaction::removeFrameOfLayer(Layer* layer, int frame)
|
||||
void UndoTransaction::removeFrameOfLayer(Layer* layer, FrameNumber frame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(frame >= 0);
|
||||
@ -744,7 +744,7 @@ void UndoTransaction::removeFrameOfLayer(Layer* layer, int frame)
|
||||
|
||||
for (++frame; frame<m_sprite->getTotalFrames(); ++frame)
|
||||
if (Cel* cel = static_cast<LayerImage*>(layer)->getCel(frame))
|
||||
setCelFramePosition(cel, cel->getFrame()-1);
|
||||
setCelFramePosition(cel, cel->getFrame().previous());
|
||||
break;
|
||||
|
||||
case GFXOBJ_LAYER_FOLDER: {
|
||||
@ -762,13 +762,13 @@ void UndoTransaction::removeFrameOfLayer(Layer* layer, int frame)
|
||||
/**
|
||||
* Copies the previous cel of @a frame to @frame.
|
||||
*/
|
||||
void UndoTransaction::copyPreviousFrame(Layer* layer, int frame)
|
||||
void UndoTransaction::copyPreviousFrame(Layer* layer, FrameNumber frame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(frame > 0);
|
||||
|
||||
// create a copy of the previous cel
|
||||
Cel* src_cel = static_cast<LayerImage*>(layer)->getCel(frame-1);
|
||||
Cel* src_cel = static_cast<LayerImage*>(layer)->getCel(frame.previous());
|
||||
Image* src_image = src_cel ? m_sprite->getStock()->getImage(src_cel->getImage()):
|
||||
NULL;
|
||||
|
||||
@ -811,7 +811,7 @@ void UndoTransaction::removeCel(LayerImage* layer, Cel* cel)
|
||||
// find if the image that use the cel to remove, is used by
|
||||
// another cels
|
||||
bool used = false;
|
||||
for (int frame=0; frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
for (FrameNumber frame(0); frame<m_sprite->getTotalFrames(); ++frame) {
|
||||
Cel* it = layer->getCel(frame);
|
||||
if (it && it != cel && it->getImage() == cel->getImage()) {
|
||||
used = true;
|
||||
@ -835,7 +835,7 @@ void UndoTransaction::removeCel(LayerImage* layer, Cel* cel)
|
||||
delete cel;
|
||||
}
|
||||
|
||||
void UndoTransaction::setCelFramePosition(Cel* cel, int frame)
|
||||
void UndoTransaction::setCelFramePosition(Cel* cel, FrameNumber frame)
|
||||
{
|
||||
ASSERT(cel);
|
||||
ASSERT(frame >= 0);
|
||||
@ -856,7 +856,7 @@ void UndoTransaction::setCelPosition(Cel* cel, int x, int y)
|
||||
cel->setPosition(x, y);
|
||||
}
|
||||
|
||||
void UndoTransaction::setFrameDuration(int frame, int msecs)
|
||||
void UndoTransaction::setFrameDuration(FrameNumber frame, int msecs)
|
||||
{
|
||||
if (isEnabled())
|
||||
m_undo->pushUndoer(new undoers::SetFrameDuration(
|
||||
@ -868,7 +868,7 @@ void UndoTransaction::setFrameDuration(int frame, int msecs)
|
||||
void UndoTransaction::setConstantFrameRate(int msecs)
|
||||
{
|
||||
if (isEnabled()) {
|
||||
for (int fr=0; fr<m_sprite->getTotalFrames(); ++fr)
|
||||
for (FrameNumber fr(0); fr<m_sprite->getTotalFrames(); ++fr)
|
||||
m_undo->pushUndoer(new undoers::SetFrameDuration(
|
||||
m_undo->getObjects(), m_sprite, fr));
|
||||
}
|
||||
@ -876,38 +876,37 @@ void UndoTransaction::setConstantFrameRate(int msecs)
|
||||
m_sprite->setDurationForAllFrames(msecs);
|
||||
}
|
||||
|
||||
void UndoTransaction::moveFrameBefore(int frame, int before_frame)
|
||||
void UndoTransaction::moveFrameBefore(FrameNumber frame, FrameNumber beforeFrame)
|
||||
{
|
||||
if (frame != before_frame &&
|
||||
if (frame != beforeFrame &&
|
||||
frame >= 0 &&
|
||||
frame < m_sprite->getTotalFrames() &&
|
||||
before_frame >= 0 &&
|
||||
before_frame < m_sprite->getTotalFrames()) {
|
||||
// change the frame-lengths...
|
||||
|
||||
frame <= m_sprite->getLastFrame() &&
|
||||
beforeFrame >= 0 &&
|
||||
beforeFrame <= m_sprite->getLastFrame()) {
|
||||
// Change the frame-lengths...
|
||||
int frlen_aux = m_sprite->getFrameDuration(frame);
|
||||
|
||||
// moving the frame to the future
|
||||
if (frame < before_frame) {
|
||||
for (int c=frame; c<before_frame-1; c++)
|
||||
setFrameDuration(c, m_sprite->getFrameDuration(c+1));
|
||||
// Moving the frame to the future.
|
||||
if (frame < beforeFrame) {
|
||||
for (FrameNumber c=frame; c<beforeFrame.previous(); ++c)
|
||||
setFrameDuration(c, m_sprite->getFrameDuration(c.next()));
|
||||
|
||||
setFrameDuration(before_frame-1, frlen_aux);
|
||||
setFrameDuration(beforeFrame.previous(), frlen_aux);
|
||||
}
|
||||
// moving the frame to the past
|
||||
else if (before_frame < frame) {
|
||||
for (int c=frame; c>before_frame; c--)
|
||||
setFrameDuration(c, m_sprite->getFrameDuration(c-1));
|
||||
// Moving the frame to the past.
|
||||
else if (beforeFrame < frame) {
|
||||
for (FrameNumber c=frame; c>beforeFrame; --c)
|
||||
setFrameDuration(c, m_sprite->getFrameDuration(c.previous()));
|
||||
|
||||
setFrameDuration(before_frame, frlen_aux);
|
||||
setFrameDuration(beforeFrame, frlen_aux);
|
||||
}
|
||||
|
||||
// change the cels of position...
|
||||
moveFrameBeforeLayer(m_sprite->getFolder(), frame, before_frame);
|
||||
moveFrameBeforeLayer(m_sprite->getFolder(), frame, beforeFrame);
|
||||
}
|
||||
}
|
||||
|
||||
void UndoTransaction::moveFrameBeforeLayer(Layer* layer, int frame, int before_frame)
|
||||
void UndoTransaction::moveFrameBeforeLayer(Layer* layer, FrameNumber frame, FrameNumber beforeFrame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
|
||||
@ -919,31 +918,31 @@ void UndoTransaction::moveFrameBeforeLayer(Layer* layer, int frame, int before_f
|
||||
|
||||
for (; it != end; ++it) {
|
||||
Cel* cel = *it;
|
||||
int new_frame = cel->getFrame();
|
||||
FrameNumber newFrame = cel->getFrame();
|
||||
|
||||
// moving the frame to the future
|
||||
if (frame < before_frame) {
|
||||
if (frame < beforeFrame) {
|
||||
if (cel->getFrame() == frame) {
|
||||
new_frame = before_frame-1;
|
||||
newFrame = beforeFrame.previous();
|
||||
}
|
||||
else if (cel->getFrame() > frame &&
|
||||
cel->getFrame() < before_frame) {
|
||||
new_frame--;
|
||||
cel->getFrame() < beforeFrame) {
|
||||
--newFrame;
|
||||
}
|
||||
}
|
||||
// moving the frame to the past
|
||||
else if (before_frame < frame) {
|
||||
else if (beforeFrame < frame) {
|
||||
if (cel->getFrame() == frame) {
|
||||
new_frame = before_frame;
|
||||
newFrame = beforeFrame;
|
||||
}
|
||||
else if (cel->getFrame() >= before_frame &&
|
||||
else if (cel->getFrame() >= beforeFrame &&
|
||||
cel->getFrame() < frame) {
|
||||
new_frame++;
|
||||
++newFrame;
|
||||
}
|
||||
}
|
||||
|
||||
if (cel->getFrame() != new_frame)
|
||||
setCelFramePosition(cel, new_frame);
|
||||
if (cel->getFrame() != newFrame)
|
||||
setCelFramePosition(cel, newFrame);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -953,7 +952,7 @@ void UndoTransaction::moveFrameBeforeLayer(Layer* layer, int frame, int before_f
|
||||
LayerIterator end = static_cast<LayerFolder*>(layer)->get_layer_end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
moveFrameBeforeLayer(*it, frame, before_frame);
|
||||
moveFrameBeforeLayer(*it, frame, beforeFrame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "gfx/rect.h"
|
||||
#include "raster/algorithm/flip_type.h"
|
||||
#include "raster/dithering_method.h"
|
||||
#include "raster/frame_number.h"
|
||||
#include "raster/pixel_format.h"
|
||||
#include "undo/modification.h"
|
||||
|
||||
@ -79,8 +80,8 @@ public:
|
||||
undo::ObjectsContainer* getObjects() const;
|
||||
|
||||
// for sprite
|
||||
void setNumberOfFrames(int frames);
|
||||
void setCurrentFrame(int frame);
|
||||
void setNumberOfFrames(FrameNumber frames);
|
||||
void setCurrentFrame(FrameNumber frame);
|
||||
void setCurrentLayer(Layer* layer);
|
||||
void setSpriteSize(int w, int h);
|
||||
void cropSprite(const gfx::Rect& bounds, int bgcolor);
|
||||
@ -95,7 +96,7 @@ public:
|
||||
// for layers
|
||||
LayerImage* newLayer();
|
||||
void removeLayer(Layer* layer);
|
||||
void moveLayerAfter(Layer *layer, Layer *after_this);
|
||||
void moveLayerAfter(Layer* layer, Layer* afterThis);
|
||||
void cropLayer(Layer* layer, int x, int y, int w, int h, int bgcolor);
|
||||
void displaceLayers(Layer* layer, int dx, int dy);
|
||||
void backgroundFromLayer(LayerImage* layer, int bgcolor);
|
||||
@ -104,19 +105,19 @@ public:
|
||||
|
||||
// for frames
|
||||
void newFrame();
|
||||
void newFrameForLayer(Layer* layer, int frame);
|
||||
void removeFrame(int frame);
|
||||
void removeFrameOfLayer(Layer* layer, int frame);
|
||||
void copyPreviousFrame(Layer* layer, int frame);
|
||||
void setFrameDuration(int frame, int msecs);
|
||||
void newFrameForLayer(Layer* layer, FrameNumber frame);
|
||||
void removeFrame(FrameNumber frame);
|
||||
void removeFrameOfLayer(Layer* layer, FrameNumber frame);
|
||||
void copyPreviousFrame(Layer* layer, FrameNumber frame);
|
||||
void setFrameDuration(FrameNumber frame, int msecs);
|
||||
void setConstantFrameRate(int msecs);
|
||||
void moveFrameBefore(int frame, int before_frame);
|
||||
void moveFrameBeforeLayer(Layer* layer, int frame, int before_frame);
|
||||
void moveFrameBefore(FrameNumber frame, FrameNumber beforeFrame);
|
||||
void moveFrameBeforeLayer(Layer* layer, FrameNumber frame, FrameNumber beforeFrame);
|
||||
|
||||
// for cels
|
||||
void addCel(LayerImage* layer, Cel* cel);
|
||||
void removeCel(LayerImage* layer, Cel* cel);
|
||||
void setCelFramePosition(Cel* cel, int frame);
|
||||
void setCelFramePosition(Cel* cel, FrameNumber frame);
|
||||
void setCelPosition(Cel* cel, int x, int y);
|
||||
Cel* getCurrentCel();
|
||||
void cropCel(Cel* cel, int x, int y, int w, int h, int bgcolor);
|
||||
|
@ -28,7 +28,7 @@
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
AddPalette::AddPalette(ObjectsContainer* objects, Sprite* sprite, int paletteFrame)
|
||||
AddPalette::AddPalette(ObjectsContainer* objects, Sprite* sprite, FrameNumber paletteFrame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_paletteFrame(paletteFrame)
|
||||
{
|
||||
@ -42,9 +42,9 @@ void AddPalette::dispose()
|
||||
void AddPalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
{
|
||||
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
|
||||
Palette* palette = sprite->getPalette(m_paletteFrame);
|
||||
Palette* palette = sprite->getPalette(FrameNumber(m_paletteFrame));
|
||||
|
||||
redoers->pushUndoer(new RemovePalette(objects, sprite, m_paletteFrame));
|
||||
redoers->pushUndoer(new RemovePalette(objects, sprite, FrameNumber(m_paletteFrame)));
|
||||
|
||||
sprite->deletePalette(palette);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_ADD_PALETTE_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -29,7 +30,7 @@ namespace undoers {
|
||||
class AddPalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
AddPalette(undo::ObjectsContainer* objects, Sprite* sprite, int palette_frame);
|
||||
AddPalette(undo::ObjectsContainer* objects, Sprite* sprite, FrameNumber palette_frame);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
size_t getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
@ -37,7 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
int m_paletteFrame;
|
||||
FrameNumber m_paletteFrame;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
@ -29,7 +29,9 @@
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemapPalette::RemapPalette(ObjectsContainer* objects, Sprite* sprite, int frameFrom, int frameTo, const std::vector<uint8_t>& mapping)
|
||||
RemapPalette::RemapPalette(ObjectsContainer* objects, Sprite* sprite,
|
||||
FrameNumber frameFrom, FrameNumber frameTo,
|
||||
const std::vector<uint8_t>& mapping)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frameFrom(frameFrom)
|
||||
, m_frameTo(frameTo)
|
||||
@ -53,7 +55,9 @@ void RemapPalette::revert(ObjectsContainer* objects, UndoersCollector* redoers)
|
||||
inverse_mapping[m_mapping[c]] = c;
|
||||
|
||||
// Push an RemapPalette as redoer
|
||||
redoers->pushUndoer(new RemapPalette(objects, sprite, m_frameFrom, m_frameTo, inverse_mapping));
|
||||
redoers->pushUndoer(new RemapPalette(objects, sprite,
|
||||
m_frameFrom,
|
||||
m_frameTo, inverse_mapping));
|
||||
|
||||
// Remap in inverse order
|
||||
sprite->remapImages(m_frameFrom, m_frameTo, inverse_mapping);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_REMAP_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_REMAP_PALETTE_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -31,7 +32,9 @@ namespace undoers {
|
||||
class RemapPalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemapPalette(undo::ObjectsContainer* objects, Sprite* sprite, int frameFrom, int frameTo, const std::vector<uint8_t>& mapping);
|
||||
RemapPalette(undo::ObjectsContainer* objects, Sprite* sprite,
|
||||
FrameNumber frameFrom, FrameNumber frameTo,
|
||||
const std::vector<uint8_t>& mapping);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
size_t getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
@ -39,8 +42,8 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frameFrom;
|
||||
uint32_t m_frameTo;
|
||||
FrameNumber m_frameFrom;
|
||||
FrameNumber m_frameTo;
|
||||
std::vector<uint8_t> m_mapping;
|
||||
};
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
RemovePalette::RemovePalette(ObjectsContainer* objects, Sprite* sprite, int paletteFrame)
|
||||
RemovePalette::RemovePalette(ObjectsContainer* objects, Sprite* sprite, FrameNumber paletteFrame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
{
|
||||
raster::write_palette(m_stream, sprite->getPalette(paletteFrame));
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_REMOVE_PALETTE_H_INCLUDED
|
||||
#define UNDOERS_REMOVE_PALETTE_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -31,7 +32,7 @@ namespace undoers {
|
||||
class RemovePalette : public UndoerBase
|
||||
{
|
||||
public:
|
||||
RemovePalette(undo::ObjectsContainer* objects, Sprite* sprite, int paletteFrame);
|
||||
RemovePalette(undo::ObjectsContainer* objects, Sprite* sprite, FrameNumber paletteFrame);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
size_t getMemSize() const OVERRIDE { return sizeof(*this) + getStreamSize(); }
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_SET_CEL_FRAME_H_INCLUDED
|
||||
#define UNDOERS_SET_CEL_FRAME_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -38,7 +39,7 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_celId;
|
||||
int m_frame;
|
||||
FrameNumber m_frame;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_SET_CURRENT_FRAME_H_INCLUDED
|
||||
#define UNDOERS_SET_CURRENT_FRAME_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -39,7 +40,7 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
FrameNumber m_frame;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
@ -27,7 +27,7 @@
|
||||
using namespace undo;
|
||||
using namespace undoers;
|
||||
|
||||
SetFrameDuration::SetFrameDuration(ObjectsContainer* objects, Sprite* sprite, int frame)
|
||||
SetFrameDuration::SetFrameDuration(ObjectsContainer* objects, Sprite* sprite, FrameNumber frame)
|
||||
: m_spriteId(objects->addObject(sprite))
|
||||
, m_frame(frame)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_SET_FRAME_DURATION_H_INCLUDED
|
||||
#define UNDOERS_SET_FRAME_DURATION_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -29,7 +30,7 @@ namespace undoers {
|
||||
class SetFrameDuration : public UndoerBase
|
||||
{
|
||||
public:
|
||||
SetFrameDuration(undo::ObjectsContainer* objects, Sprite* sprite, int frame);
|
||||
SetFrameDuration(undo::ObjectsContainer* objects, Sprite* sprite, FrameNumber frame);
|
||||
|
||||
void dispose() OVERRIDE;
|
||||
size_t getMemSize() const OVERRIDE { return sizeof(*this); }
|
||||
@ -37,7 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
FrameNumber m_frame;
|
||||
uint32_t m_duration;
|
||||
};
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_SET_PALETTE_COLORS_H_INCLUDED
|
||||
#define UNDOERS_SET_PALETTE_COLORS_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -44,7 +45,7 @@ private:
|
||||
}
|
||||
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_frame;
|
||||
FrameNumber m_frame;
|
||||
uint8_t m_from;
|
||||
uint8_t m_to;
|
||||
std::stringstream m_stream;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
#define UNDOERS_SET_TOTAL_FRAMES_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
#include "undo/object_id.h"
|
||||
#include "undoers/undoer_base.h"
|
||||
|
||||
@ -39,7 +40,7 @@ public:
|
||||
|
||||
private:
|
||||
undo::ObjectId m_spriteId;
|
||||
uint32_t m_totalFrames;
|
||||
FrameNumber m_totalFrames;
|
||||
};
|
||||
|
||||
} // namespace undoers
|
||||
|
@ -47,13 +47,13 @@
|
||||
frame indicates where to move it) */
|
||||
static Layer* src_layer = NULL; // TODO warning not thread safe
|
||||
static Layer* dst_layer = NULL;
|
||||
static int src_frame = 0;
|
||||
static int dst_frame = 0;
|
||||
static FrameNumber src_frame = FrameNumber(0);
|
||||
static FrameNumber dst_frame = FrameNumber(0);
|
||||
|
||||
static void remove_cel(Sprite* sprite, UndoTransaction& undo, LayerImage *layer, Cel *cel);
|
||||
|
||||
void set_frame_to_handle(Layer *_src_layer, int _src_frame,
|
||||
Layer *_dst_layer, int _dst_frame)
|
||||
void set_frame_to_handle(Layer *_src_layer, FrameNumber _src_frame,
|
||||
Layer *_dst_layer, FrameNumber _dst_frame)
|
||||
{
|
||||
src_layer = _src_layer;
|
||||
src_frame = _src_frame;
|
||||
@ -147,7 +147,7 @@ void move_cel(DocumentWriter& document)
|
||||
|
||||
undo.commit();
|
||||
|
||||
set_frame_to_handle(NULL, 0, NULL, 0);
|
||||
set_frame_to_handle(NULL, FrameNumber(0), NULL, FrameNumber(0));
|
||||
}
|
||||
|
||||
void copy_cel(DocumentWriter& document)
|
||||
@ -230,21 +230,20 @@ void copy_cel(DocumentWriter& document)
|
||||
|
||||
undo.commit();
|
||||
|
||||
set_frame_to_handle(NULL, 0, NULL, 0);
|
||||
set_frame_to_handle(NULL, FrameNumber(0), NULL, FrameNumber(0));
|
||||
}
|
||||
|
||||
static void remove_cel(Sprite* sprite, UndoTransaction& undo, LayerImage *layer, Cel *cel)
|
||||
{
|
||||
Image *image;
|
||||
Cel *it;
|
||||
int frame;
|
||||
bool used;
|
||||
|
||||
if (sprite != NULL && layer->is_image() && cel != NULL) {
|
||||
/* find if the image that use the cel to remove, is used by
|
||||
another cels */
|
||||
used = false;
|
||||
for (frame=0; frame<sprite->getTotalFrames(); ++frame) {
|
||||
for (FrameNumber frame(0); frame<sprite->getTotalFrames(); ++frame) {
|
||||
it = layer->getCel(frame);
|
||||
if (it != NULL && it != cel && it->getImage() == cel->getImage()) {
|
||||
used = true;
|
||||
|
@ -19,13 +19,15 @@
|
||||
#ifndef UTIL_CELMOVE_H_INCLUDED
|
||||
#define UTIL_CELMOVE_H_INCLUDED
|
||||
|
||||
#include "raster/frame_number.h"
|
||||
|
||||
class Cel;
|
||||
class Layer;
|
||||
class Sprite;
|
||||
class DocumentWriter;
|
||||
|
||||
void set_frame_to_handle(Layer* src_layer, int src_frame,
|
||||
Layer* dst_layer, int dst_frame);
|
||||
void set_frame_to_handle(Layer* src_layer, FrameNumber src_frame,
|
||||
Layer* dst_layer, FrameNumber dst_frame);
|
||||
|
||||
void move_cel(DocumentWriter& document);
|
||||
void copy_cel(DocumentWriter& document);
|
||||
|
@ -283,7 +283,7 @@ static void get_win32_clipboard_bitmap(Image*& image, Palette*& palette)
|
||||
// 8 BPP
|
||||
case 8: {
|
||||
int colors = bi->bmiHeader.biClrUsed > 0 ? bi->bmiHeader.biClrUsed: 256;
|
||||
palette = new Palette(0, colors);
|
||||
palette = new Palette(FrameNumber(0), colors);
|
||||
for (int c=0; c<colors; ++c) {
|
||||
palette->setEntry(c, _rgba(bi->bmiColors[c].rgbRed,
|
||||
bi->bmiColors[c].rgbGreen,
|
||||
|
@ -52,7 +52,7 @@ Palette *load_col_file(const char *filename)
|
||||
|
||||
/* Animator format */
|
||||
if (!pro) {
|
||||
pal = new Palette(0, 256);
|
||||
pal = new Palette(FrameNumber(0), 256);
|
||||
|
||||
for (c=0; c<256; c++) {
|
||||
r = fgetc(f);
|
||||
@ -80,7 +80,7 @@ Palette *load_col_file(const char *filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pal = new Palette(0, MIN(d.quot, 256));
|
||||
pal = new Palette(FrameNumber(0), MIN(d.quot, 256));
|
||||
|
||||
for (c=0; c<pal->size(); c++) {
|
||||
r = fgetc(f);
|
||||
|
@ -40,7 +40,7 @@ Palette* load_gpl_file(const char *filename)
|
||||
base::trim_string(line, line);
|
||||
if (line != "GIMP Palette") return NULL;
|
||||
|
||||
UniquePtr<Palette> pal(new Palette(0, 256));
|
||||
UniquePtr<Palette> pal(new Palette(FrameNumber(0), 256));
|
||||
int entryCounter = 0;
|
||||
|
||||
while (std::getline(f, line)) {
|
||||
|
@ -370,7 +370,7 @@ Image* RenderEngine::renderSprite(const Document* document,
|
||||
const Sprite* sprite,
|
||||
int source_x, int source_y,
|
||||
int width, int height,
|
||||
int frame, int zoom,
|
||||
FrameNumber frame, int zoom,
|
||||
bool draw_tiled_bg)
|
||||
{
|
||||
void (*zoomed_func)(Image*, const Image*, const Palette*, int, int, int, int, int);
|
||||
@ -425,8 +425,8 @@ Image* RenderEngine::renderSprite(const Document* document,
|
||||
int opacity_base = settings->getOnionskinOpacityBase();
|
||||
int opacity_step = settings->getOnionskinOpacityStep();
|
||||
|
||||
for (int f=frame-prevs; f <= frame+nexts; ++f) {
|
||||
if (f == frame || f < 0 || f >= sprite->getTotalFrames())
|
||||
for (FrameNumber f=frame.previous(prevs); f <= frame.next(nexts); ++f) {
|
||||
if (f == frame || f < 0 || f > sprite->getLastFrame())
|
||||
continue;
|
||||
else if (f < frame)
|
||||
global_opacity = opacity_base - opacity_step * ((frame - f)-1);
|
||||
@ -553,7 +553,7 @@ void RenderEngine::renderLayer(const Document* document,
|
||||
const Layer* layer,
|
||||
Image *image,
|
||||
int source_x, int source_y,
|
||||
int frame, int zoom,
|
||||
FrameNumber frame, int zoom,
|
||||
void (*zoomed_func)(Image*, const Image*, const Palette*, int, int, int, int, int),
|
||||
bool render_background,
|
||||
bool render_transparent)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define UTIL_RENDER_H_INCLUDED
|
||||
|
||||
#include "app/color.h"
|
||||
#include "raster/frame_number.h"
|
||||
|
||||
class Document;
|
||||
class Image;
|
||||
@ -61,7 +62,7 @@ public:
|
||||
const Sprite* sprite,
|
||||
int source_x, int source_y,
|
||||
int width, int height,
|
||||
int frpos, int zoom,
|
||||
FrameNumber frame, int zoom,
|
||||
bool draw_tiled_bg);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -80,7 +81,7 @@ private:
|
||||
const Layer* layer,
|
||||
Image* image,
|
||||
int source_x, int source_y,
|
||||
int frame, int zoom,
|
||||
FrameNumber frame, int zoom,
|
||||
void (*zoomed_func)(Image*, const Image*, const Palette*, int, int, int, int, int),
|
||||
bool render_background,
|
||||
bool render_transparent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user