diff --git a/data/gui.xml b/data/gui.xml index e8da5457d..1444469a7 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -238,17 +238,17 @@ - - + + - - + + - - + + - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b6189def5..aea721dfb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -286,9 +286,9 @@ add_library(aseprite-library undoers/set_mask.cpp undoers/set_mask_position.cpp undoers/set_palette_colors.cpp - undoers/set_sprite_imgtype.cpp + undoers/set_sprite_pixel_format.cpp undoers/set_sprite_size.cpp - undoers/set_stock_imgtype.cpp + undoers/set_stock_pixel_format.cpp undoers/set_total_frames.cpp util/autocrop.cpp util/boundary.cpp diff --git a/src/app.cpp b/src/app.cpp index a37455c25..a894f3efb 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -464,14 +464,14 @@ bool app_rebuild_recent_list() return true; } -int app_get_current_image_type() +PixelFormat app_get_current_pixel_format() { Context* context = UIContext::instance(); ASSERT(context != NULL); Document* document = context->getActiveDocument(); if (document != NULL) - return document->getSprite()->getImgType(); + return document->getSprite()->getPixelFormat(); else if (screen != NULL && bitmap_color_depth(screen) == 8) return IMAGE_INDEXED; else diff --git a/src/app.h b/src/app.h index 42e6b5d4a..53c9083ed 100644 --- a/src/app.h +++ b/src/app.h @@ -22,6 +22,7 @@ #include "base/signal.h" #include "base/string.h" #include "gui/base.h" +#include "raster/pixel_format.h" #include @@ -96,7 +97,7 @@ void app_update_document_tab(const Document* document); // Updates the list of recent files. bool app_rebuild_recent_list(); -int app_get_current_image_type(); +PixelFormat app_get_current_pixel_format(); Frame* app_get_top_window(); MenuBar* app_get_menubar(); diff --git a/src/app/color.cpp b/src/app/color.cpp index 71c0f5764..3e0cfa70b 100644 --- a/src/app/color.cpp +++ b/src/app/color.cpp @@ -76,11 +76,11 @@ Color Color::fromIndex(int index) } // static -Color Color::fromImage(int imgtype, int c) +Color Color::fromImage(PixelFormat pixelFormat, int c) { Color color = Color::fromMask(); - switch (imgtype) { + switch (pixelFormat) { case IMAGE_RGB: if (_rgba_geta(c) > 0) { @@ -108,7 +108,7 @@ Color Color::fromImage(int imgtype, int c) Color Color::fromImageGetPixel(Image *image, int x, int y) { if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h)) - return Color::fromImage(image->imgtype, image_getpixel(image, x, y)); + return Color::fromImage(image->getPixelFormat(), image_getpixel(image, x, y)); else return Color::fromMask(); } @@ -186,7 +186,7 @@ std::string Color::toString() const return result.str(); } -std::string Color::toFormalString(int imgtype, bool long_format) const +std::string Color::toFormalString(PixelFormat pixelFormat, bool long_format) const { std::stringstream result; @@ -199,7 +199,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const break; case Color::RgbType: - if (imgtype == IMAGE_GRAYSCALE) { + if (pixelFormat == IMAGE_GRAYSCALE) { result << "Gray " << getGray(); } else { @@ -208,14 +208,14 @@ std::string Color::toFormalString(int imgtype, bool long_format) const << m_value.rgb.g << " " << m_value.rgb.b; - if (imgtype == IMAGE_INDEXED) + if (pixelFormat == IMAGE_INDEXED) result << " Index " - << color_utils::color_for_image(*this, imgtype); + << color_utils::color_for_image(*this, pixelFormat); } break; case Color::HsvType: - if (imgtype == IMAGE_GRAYSCALE) { + if (pixelFormat == IMAGE_GRAYSCALE) { result << "Gray " << getGray(); } else { @@ -224,8 +224,8 @@ std::string Color::toFormalString(int imgtype, bool long_format) const << m_value.hsv.s << " " << m_value.hsv.v; - if (imgtype == IMAGE_INDEXED) - result << " Index " << color_utils::color_for_image(*this, imgtype); + if (pixelFormat == IMAGE_INDEXED) + result << " Index " << color_utils::color_for_image(*this, pixelFormat); } break; @@ -265,7 +265,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const break; case Color::RgbType: - if (imgtype == IMAGE_GRAYSCALE) { + if (pixelFormat == IMAGE_GRAYSCALE) { result << "Gry-" << getGray(); } else { @@ -277,7 +277,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const break; case Color::HsvType: - if (imgtype == IMAGE_GRAYSCALE) { + if (pixelFormat == IMAGE_GRAYSCALE) { result << "Gry-" << getGray(); } else { diff --git a/src/app/color.h b/src/app/color.h index fb1b32bea..ead652d1f 100644 --- a/src/app/color.h +++ b/src/app/color.h @@ -19,6 +19,8 @@ #ifndef APP_COLOR_H_INCLUDED #define APP_COLOR_H_INCLUDED +#include "raster/pixel_format.h" + #include class Image; @@ -43,12 +45,12 @@ public: static Color fromGray(int g); static Color fromIndex(int index); - static Color fromImage(int imgtype, int pixel); + static Color fromImage(PixelFormat pixelFormat, int pixel); static Color fromImageGetPixel(Image* image, int x, int y); static Color fromString(const std::string& str); std::string toString() const; - std::string toFormalString(int imgtype, bool long_format) const; + std::string toFormalString(PixelFormat format, bool long_format) const; bool operator==(const Color& other) const; bool operator!=(const Color& other) const { diff --git a/src/app/color_utils.cpp b/src/app/color_utils.cpp index 55e114356..cb75d8d74 100644 --- a/src/app/color_utils.cpp +++ b/src/app/color_utils.cpp @@ -108,14 +108,14 @@ int color_utils::color_for_allegro(const Color& color, int depth) return c; } -int color_utils::color_for_image(const Color& color, int imgtype) +int color_utils::color_for_image(const Color& color, PixelFormat format) { if (color.getType() == Color::MaskType) return 0; int c = -1; - switch (imgtype) { + switch (format) { case IMAGE_RGB: c = _rgba(color.getRed(), color.getGreen(), color.getBlue(), 255); break; @@ -141,8 +141,8 @@ int color_utils::color_for_layer(const Color& color, Layer* layer) pixel_color = layer->getSprite()->getTransparentColor(); } else { - int imgtype = layer->getSprite()->getImgType(); - pixel_color = color_for_image(color, imgtype); + PixelFormat format = layer->getSprite()->getPixelFormat(); + pixel_color = color_for_image(color, format); } return fixup_color_for_layer(layer, pixel_color); @@ -151,14 +151,14 @@ int color_utils::color_for_layer(const Color& color, Layer* layer) int color_utils::fixup_color_for_layer(Layer *layer, int color) { if (layer->is_background()) - return fixup_color_for_background(layer->getSprite()->getImgType(), color); + return fixup_color_for_background(layer->getSprite()->getPixelFormat(), color); else return color; } -int color_utils::fixup_color_for_background(int imgtype, int color) +int color_utils::fixup_color_for_background(PixelFormat format, int color) { - switch (imgtype) { + switch (format) { case IMAGE_RGB: if (_rgba_geta(color) < 255) { return _rgba(_rgba_getr(color), diff --git a/src/app/color_utils.h b/src/app/color_utils.h index 287b2caba..54b805d9e 100644 --- a/src/app/color_utils.h +++ b/src/app/color_utils.h @@ -20,6 +20,7 @@ #define APP_COLOR_UTILS_H_INCLUDED #include "app/color.h" +#include "raster/pixel_format.h" class Layer; @@ -29,11 +30,11 @@ int blackandwhite(int r, int g, int b); int blackandwhite_neg(int r, int g, int b); int color_for_allegro(const Color& color, int depth); -int color_for_image(const Color& color, int imgtype); +int color_for_image(const Color& color, PixelFormat format); int color_for_layer(const Color& color, Layer* layer); int fixup_color_for_layer(Layer* layer, int color); -int fixup_color_for_background(int imgtype, int color); +int fixup_color_for_background(PixelFormat format, int color); } diff --git a/src/commands/cmd_background_from_layer.cpp b/src/commands/cmd_background_from_layer.cpp index f6e8e42b6..f0754dd18 100644 --- a/src/commands/cmd_background_from_layer.cpp +++ b/src/commands/cmd_background_from_layer.cpp @@ -63,8 +63,8 @@ void BackgroundFromLayerCommand::onExecute(Context* context) // each frame of the layer to be converted as `Background' must be // cleared using the selected background color in the color-bar - int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType()); - bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor); + int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getPixelFormat()); + bgcolor = color_utils::fixup_color_for_background(sprite->getPixelFormat(), bgcolor); { UndoTransaction undo_transaction(document, "Background from Layer"); diff --git a/src/commands/cmd_canvas_size.cpp b/src/commands/cmd_canvas_size.cpp index cef471988..6f9530096 100644 --- a/src/commands/cmd_canvas_size.cpp +++ b/src/commands/cmd_canvas_size.cpp @@ -204,8 +204,8 @@ void CanvasSizeCommand::onExecute(Context* context) { DocumentWriter documentWriter(document); UndoTransaction undoTransaction(documentWriter, "Canvas Size"); - int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType()); - bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor); + int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getPixelFormat()); + bgcolor = color_utils::fixup_color_for_background(sprite->getPixelFormat(), bgcolor); undoTransaction.cropSprite(gfx::Rect(x1, y1, x2-x1, y2-y1), bgcolor); undoTransaction.commit(); diff --git a/src/commands/cmd_change_image_type.cpp b/src/commands/cmd_change_image_type.cpp index 31c201897..b402d5e83 100644 --- a/src/commands/cmd_change_image_type.cpp +++ b/src/commands/cmd_change_image_type.cpp @@ -30,13 +30,13 @@ #include -class ChangeImageTypeCommand : public Command +class ChangePixelFormatCommand : public Command { - int m_imgtype; + PixelFormat m_format; DitheringMethod m_dithering; public: - ChangeImageTypeCommand(); - Command* clone() const { return new ChangeImageTypeCommand(*this); } + ChangePixelFormatCommand(); + Command* clone() const { return new ChangePixelFormatCommand(*this); } protected: void onLoadParams(Params* params); @@ -45,21 +45,21 @@ protected: void onExecute(Context* context); }; -ChangeImageTypeCommand::ChangeImageTypeCommand() - : Command("ChangeImageType", - "Change Image Type", +ChangePixelFormatCommand::ChangePixelFormatCommand() + : Command("ChangePixelFormat", + "Change Pixel Format", CmdUIOnlyFlag) { - m_imgtype = IMAGE_RGB; + m_format = IMAGE_RGB; m_dithering = DITHERING_NONE; } -void ChangeImageTypeCommand::onLoadParams(Params* params) +void ChangePixelFormatCommand::onLoadParams(Params* params) { - std::string imgtype = params->get("imgtype"); - if (imgtype == "rgb") m_imgtype = IMAGE_RGB; - else if (imgtype == "grayscale") m_imgtype = IMAGE_GRAYSCALE; - else if (imgtype == "indexed") m_imgtype = IMAGE_INDEXED; + std::string format = params->get("format"); + if (format == "rgb") m_format = IMAGE_RGB; + else if (format == "grayscale") m_format = IMAGE_GRAYSCALE; + else if (format == "indexed") m_format = IMAGE_INDEXED; std::string dithering = params->get("dithering"); if (dithering == "ordered") @@ -68,42 +68,42 @@ void ChangeImageTypeCommand::onLoadParams(Params* params) m_dithering = DITHERING_NONE; } -bool ChangeImageTypeCommand::onEnabled(Context* context) +bool ChangePixelFormatCommand::onEnabled(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite(document ? document->getSprite(): 0); if (sprite != NULL && - sprite->getImgType() == IMAGE_INDEXED && - m_imgtype == IMAGE_INDEXED && + sprite->getPixelFormat() == IMAGE_INDEXED && + m_format == IMAGE_INDEXED && m_dithering == DITHERING_ORDERED) return false; return sprite != NULL; } -bool ChangeImageTypeCommand::onChecked(Context* context) +bool ChangePixelFormatCommand::onChecked(Context* context) { const ActiveDocumentReader document(context); const Sprite* sprite(document ? document->getSprite(): 0); if (sprite != NULL && - sprite->getImgType() == IMAGE_INDEXED && - m_imgtype == IMAGE_INDEXED && + sprite->getPixelFormat() == IMAGE_INDEXED && + m_format == IMAGE_INDEXED && m_dithering == DITHERING_ORDERED) return false; return sprite != NULL && - sprite->getImgType() == m_imgtype; + sprite->getPixelFormat() == m_format; } -void ChangeImageTypeCommand::onExecute(Context* context) +void ChangePixelFormatCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); { UndoTransaction undoTransaction(document, "Color Mode Change"); - undoTransaction.setImgType(m_imgtype, m_dithering); + undoTransaction.setPixelFormat(m_format, m_dithering); undoTransaction.commit(); } app_refresh_screen(document); @@ -112,7 +112,7 @@ void ChangeImageTypeCommand::onExecute(Context* context) ////////////////////////////////////////////////////////////////////// // CommandFactory -Command* CommandFactory::createChangeImageTypeCommand() +Command* CommandFactory::createChangePixelFormatCommand() { - return new ChangeImageTypeCommand; + return new ChangePixelFormatCommand; } diff --git a/src/commands/cmd_crop.cpp b/src/commands/cmd_crop.cpp index d3fb6d7c4..4f4b341dd 100644 --- a/src/commands/cmd_crop.cpp +++ b/src/commands/cmd_crop.cpp @@ -66,7 +66,7 @@ void CropSpriteCommand::onExecute(Context* context) const Mask* mask(document->getMask()); { UndoTransaction undoTransaction(document, "Sprite Crop"); - int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType()); + int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getPixelFormat()); undoTransaction.cropSprite(mask->getBounds(), bgcolor); undoTransaction.commit(); @@ -107,7 +107,7 @@ void AutocropSpriteCommand::onExecute(Context* context) ActiveDocumentWriter document(context); Sprite* sprite(document->getSprite()); { - int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType()); + int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getPixelFormat()); UndoTransaction undoTransaction(document, "Sprite Autocrop"); undoTransaction.autocropSprite(bgcolor); diff --git a/src/commands/cmd_export_sprite_sheet.cpp b/src/commands/cmd_export_sprite_sheet.cpp index e2b5127b5..11c9865ad 100644 --- a/src/commands/cmd_export_sprite_sheet.cpp +++ b/src/commands/cmd_export_sprite_sheet.cpp @@ -139,7 +139,7 @@ protected: int sheet_w = sprite->getWidth()*columns; int sheet_h = sprite->getHeight()*((nframes/columns)+((nframes%columns)>0?1:0)); - UniquePtr resultImage(Image::create(sprite->getImgType(), sheet_w, sheet_h)); + UniquePtr resultImage(Image::create(sprite->getPixelFormat(), sheet_w, sheet_h)); image_clear(resultImage, 0); int oldFrame = sprite->getCurrentFrame(); diff --git a/src/commands/cmd_eyedropper.cpp b/src/commands/cmd_eyedropper.cpp index c7e96bfc0..0f828e349 100644 --- a/src/commands/cmd_eyedropper.cpp +++ b/src/commands/cmd_eyedropper.cpp @@ -81,7 +81,7 @@ void EyedropperCommand::onExecute(Context* context) editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); // get the color from the image - Color color = Color::fromImage(sprite->getImgType(), + Color color = Color::fromImage(sprite->getPixelFormat(), sprite->getPixel(x, y)); // TODO replace the color in the "context", not directly from the color-bar diff --git a/src/commands/cmd_flatten_layers.cpp b/src/commands/cmd_flatten_layers.cpp index c424add97..1e28f8757 100644 --- a/src/commands/cmd_flatten_layers.cpp +++ b/src/commands/cmd_flatten_layers.cpp @@ -57,7 +57,7 @@ void FlattenLayersCommand::onExecute(Context* context) { ActiveDocumentWriter document(context); Sprite* sprite = document->getSprite(); - int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getImgType()); + int bgcolor = color_utils::color_for_image(app_get_colorbar()->getBgColor(), sprite->getPixelFormat()); { UndoTransaction undoTransaction(document, "Flatten Layers"); undoTransaction.flattenLayers(bgcolor); diff --git a/src/commands/cmd_import_sprite_sheet.cpp b/src/commands/cmd_import_sprite_sheet.cpp index 28681f699..2d1a8eb80 100644 --- a/src/commands/cmd_import_sprite_sheet.cpp +++ b/src/commands/cmd_import_sprite_sheet.cpp @@ -159,7 +159,7 @@ protected: // As first step, we cut each tile and add them into "animation" list. for (int y=m_rect.y; ygetHeight(); y += m_rect.h) { for (int x=m_rect.x; xgetWidth(); x += m_rect.w) { - UniquePtr resultImage(Image::create(sprite->getImgType(), m_rect.w, m_rect.h)); + UniquePtr resultImage(Image::create(sprite->getPixelFormat(), m_rect.w, m_rect.h)); // Clear the image with mask color. image_clear(resultImage, 0); diff --git a/src/commands/cmd_new_file.cpp b/src/commands/cmd_new_file.cpp index b663ed528..1b9753845 100644 --- a/src/commands/cmd_new_file.cpp +++ b/src/commands/cmd_new_file.cpp @@ -69,7 +69,8 @@ NewFileCommand::NewFileCommand() void NewFileCommand::onExecute(Context* context) { JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box; - int imgtype, w, h, bg, ncolors; + PixelFormat format; + int w, h, bg, ncolors; char buf[1024]; Color bg_table[] = { Color::fromMask(), @@ -92,8 +93,11 @@ void NewFileCommand::onExecute(Context* context) "bg_box", &bg_box, NULL); // Default values: Indexed, 320x240, Background color - imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED); - imgtype = MID(IMAGE_RGB, imgtype, IMAGE_INDEXED); + format = static_cast(get_config_int("NewSprite", "Type", IMAGE_INDEXED)); + // Invalid format in config file. + if (format != IMAGE_RGB && format != IMAGE_INDEXED && format != IMAGE_GRAYSCALE) { + format = IMAGE_INDEXED; + } w = get_config_int("NewSprite", "Width", 320); h = get_config_int("NewSprite", "Height", 240); bg = get_config_int("NewSprite", "Background", 4); // Default = Background color @@ -112,7 +116,7 @@ void NewFileCommand::onExecute(Context* context) colors->setTextf("%d", MID(2, ncolors, 256)); // Select image-type - switch (imgtype) { + switch (format) { case IMAGE_RGB: radio1->setSelected(true); break; case IMAGE_GRAYSCALE: radio2->setSelected(true); break; case IMAGE_INDEXED: radio3->setSelected(true); break; @@ -128,9 +132,9 @@ void NewFileCommand::onExecute(Context* context) bool ok = false; // Get the options - if (radio1->isSelected()) imgtype = IMAGE_RGB; - else if (radio2->isSelected()) imgtype = IMAGE_GRAYSCALE; - else if (radio3->isSelected()) imgtype = IMAGE_INDEXED; + if (radio1->isSelected()) format = IMAGE_RGB; + else if (radio2->isSelected()) format = IMAGE_GRAYSCALE; + else if (radio3->isSelected()) format = IMAGE_INDEXED; w = width->getTextInt(); h = height->getTextInt(); @@ -151,19 +155,19 @@ void NewFileCommand::onExecute(Context* context) if (ok) { // Save the configuration - set_config_int("NewSprite", "Type", imgtype); + set_config_int("NewSprite", "Type", format); set_config_int("NewSprite", "Width", w); set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Background", bg); // Create the new sprite - ASSERT(imgtype == IMAGE_RGB || imgtype == IMAGE_GRAYSCALE || imgtype == IMAGE_INDEXED); + ASSERT(format == IMAGE_RGB || format == IMAGE_GRAYSCALE || format == IMAGE_INDEXED); ASSERT(w >= 1 && w <= 9999); ASSERT(h >= 1 && h <= 9999); UniquePtr document( - Document::createBasicDocument(imgtype, w, h, - (imgtype == IMAGE_INDEXED ? ncolors: 256))); + Document::createBasicDocument(format, w, h, + (format == IMAGE_INDEXED ? ncolors: 256))); Sprite* sprite(document->getSprite()); get_default_palette()->copyColorsTo(sprite->getCurrentPalette()); @@ -179,7 +183,7 @@ void NewFileCommand::onExecute(Context* context) ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); static_cast(sprite->getCurrentLayer())->configureAsBackground(); - image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, imgtype)); + image_clear(sprite->getCurrentImage(), color_utils::color_for_image(color, format)); } // Show the sprite to the user diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp index cda89c573..6810bc0a5 100644 --- a/src/commands/cmd_palette_editor.cpp +++ b/src/commands/cmd_palette_editor.cpp @@ -578,7 +578,7 @@ void PaletteEntryEditor::onQuantizeCommand(Event& ev) return; } - if (sprite->getImgType() != IMAGE_RGB) { + if (sprite->getPixelFormat() != IMAGE_RGB) { Alert::show("Error< -#include -#if defined ALLEGRO_WINDOWS && defined DEBUGMODE - #include - #include -#endif - #include "app.h" #include "commands/command.h" #include "gui/system.h" @@ -33,6 +26,12 @@ #include "document_wrappers.h" #include "widgets/statebar.h" +#include +#if defined ALLEGRO_WINDOWS && defined DEBUGMODE + #include + #include +#endif + ////////////////////////////////////////////////////////////////////// // refresh diff --git a/src/commands/cmd_rotate_canvas.cpp b/src/commands/cmd_rotate_canvas.cpp index ec473b912..7ad33f4ea 100644 --- a/src/commands/cmd_rotate_canvas.cpp +++ b/src/commands/cmd_rotate_canvas.cpp @@ -109,7 +109,7 @@ protected: continue; // rotate the image - Image* new_image = Image::create(image->imgtype, + Image* new_image = Image::create(image->getPixelFormat(), m_angle == 180 ? image->w: image->h, m_angle == 180 ? image->h: image->w); image_rotate(image, new_image, m_angle); diff --git a/src/commands/cmd_sprite_properties.cpp b/src/commands/cmd_sprite_properties.cpp index dae23b7c7..eed91e9c5 100644 --- a/src/commands/cmd_sprite_properties.cpp +++ b/src/commands/cmd_sprite_properties.cpp @@ -83,7 +83,7 @@ void SpritePropertiesCommand::onExecute(Context* context) const Sprite* sprite(document ? document->getSprite(): NULL); // Update widgets values - switch (sprite->getImgType()) { + switch (sprite->getPixelFormat()) { case IMAGE_RGB: imgtype_text = "RGB"; break; @@ -117,7 +117,7 @@ void SpritePropertiesCommand::onExecute(Context* context) // How many frames frames->setTextf("%d", sprite->getTotalFrames()); - if (sprite->getImgType() == IMAGE_INDEXED) { + if (sprite->getPixelFormat() == IMAGE_INDEXED) { color_button = new ColorButton(Color::fromIndex(sprite->getTransparentColor()), IMAGE_INDEXED); diff --git a/src/commands/cmd_sprite_size.cpp b/src/commands/cmd_sprite_size.cpp index 31a09bca1..92aa89c23 100644 --- a/src/commands/cmd_sprite_size.cpp +++ b/src/commands/cmd_sprite_size.cpp @@ -91,7 +91,7 @@ protected: // Resize the image int w = scale_x(image->w); int h = scale_y(image->h); - Image* new_image = Image::create(image->imgtype, MAX(1, w), MAX(1, h)); + Image* new_image = Image::create(image->getPixelFormat(), MAX(1, w), MAX(1, h)); image_fixup_transparent_colors(image); image_resize(image, new_image, diff --git a/src/commands/commands_list.h b/src/commands/commands_list.h index 4d06b7ac8..0d41244cf 100644 --- a/src/commands/commands_list.h +++ b/src/commands/commands_list.h @@ -24,8 +24,8 @@ FOR_EACH_COMMAND(Cancel) FOR_EACH_COMMAND(CanvasSize) FOR_EACH_COMMAND(CelProperties) FOR_EACH_COMMAND(ChangeColor) -FOR_EACH_COMMAND(ChangeImageType) FOR_EACH_COMMAND(ChangePen) +FOR_EACH_COMMAND(ChangePixelFormat) FOR_EACH_COMMAND(Clear) FOR_EACH_COMMAND(CloseAllFiles) FOR_EACH_COMMAND(CloseEditor) diff --git a/src/commands/filters/filter_manager_impl.cpp b/src/commands/filters/filter_manager_impl.cpp index b6b014571..6628f8bb5 100644 --- a/src/commands/filters/filter_manager_impl.cpp +++ b/src/commands/filters/filter_manager_impl.cpp @@ -86,9 +86,9 @@ void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate) m_progressDelegate = progressDelegate; } -int FilterManagerImpl::getImgType() const +PixelFormat FilterManagerImpl::getPixelFormat() const { - return m_sprite->getImgType(); + return m_sprite->getPixelFormat(); } void FilterManagerImpl::setTarget(int target) @@ -175,7 +175,7 @@ bool FilterManagerImpl::applyStep() else m_mask_address = NULL; - switch (m_sprite->getImgType()) { + switch (m_sprite->getPixelFormat()) { case IMAGE_RGB: m_filter->applyToRgba(this); break; case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break; case IMAGE_INDEXED: m_filter->applyToIndexed(this); break; @@ -295,7 +295,7 @@ void FilterManagerImpl::flush() const void* FilterManagerImpl::getSourceAddress() { - switch (m_sprite->getImgType()) { + switch (m_sprite->getPixelFormat()) { case IMAGE_RGB: return ((uint32_t**)m_src->line)[m_row+m_y]+m_x; case IMAGE_GRAYSCALE: return ((uint16_t**)m_src->line)[m_row+m_y]+m_x; case IMAGE_INDEXED: return ((uint8_t**)m_src->line)[m_row+m_y]+m_x; @@ -305,7 +305,7 @@ const void* FilterManagerImpl::getSourceAddress() void* FilterManagerImpl::getDestinationAddress() { - switch (m_sprite->getImgType()) { + switch (m_sprite->getPixelFormat()) { case IMAGE_RGB: return ((uint32_t**)m_dst->line)[m_row+m_y]+m_x; case IMAGE_GRAYSCALE: return ((uint16_t**)m_dst->line)[m_row+m_y]+m_x; case IMAGE_INDEXED: return ((uint8_t**)m_dst->line)[m_row+m_y]+m_x; diff --git a/src/commands/filters/filter_manager_impl.h b/src/commands/filters/filter_manager_impl.h index bc9ef12d3..653e965ce 100644 --- a/src/commands/filters/filter_manager_impl.h +++ b/src/commands/filters/filter_manager_impl.h @@ -19,13 +19,15 @@ #ifndef COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED #define COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED -#include -#include - #include "base/exception.h" +#include "base/exception.h" +#include "document_wrappers.h" #include "filters/filter_indexed_data.h" #include "filters/filter_manager.h" -#include "document_wrappers.h" +#include "raster/pixel_format.h" + +#include +#include class Filter; class Image; @@ -70,7 +72,7 @@ public: void setProgressDelegate(IProgressDelegate* progressDelegate); - int getImgType() const; + PixelFormat getPixelFormat() const; void setTarget(Target target); diff --git a/src/commands/filters/filter_window.cpp b/src/commands/filters/filter_window.cpp index 0faded392..2b3199d20 100644 --- a/src/commands/filters/filter_window.cpp +++ b/src/commands/filters/filter_window.cpp @@ -40,7 +40,7 @@ FilterWindow::FilterWindow(const char* title, const char* cfgSection, , m_okButton("&OK") , m_cancelButton("&Cancel") , m_preview(filterMgr) - , m_targetButton(filterMgr->getImgType(), (withChannels == WithChannelsSelector)) + , m_targetButton(filterMgr->getPixelFormat(), (withChannels == WithChannelsSelector)) , m_showPreview("&Preview") , m_tiledCheck(withTiled == WithTiledCheckBox ? new CheckBox("&Tiled") : NULL) { diff --git a/src/dialogs/drawtext.cpp b/src/dialogs/drawtext.cpp index d7707250f..7d99ef668 100644 --- a/src/dialogs/drawtext.cpp +++ b/src/dialogs/drawtext.cpp @@ -198,7 +198,7 @@ static Image* render_text(Sprite* sprite, FONT *f, const char *text, int color) clear_to_color(bmp, makecol32 (255, 0, 255)); textout_ex(bmp, f, text, 0, 0, makecol32 (255, 255, 255), -1); - image = Image::create(sprite->getImgType(), w, h); + image = Image::create(sprite->getPixelFormat(), w, h); if (!image) { destroy_bitmap(bmp); return NULL; @@ -207,7 +207,7 @@ static Image* render_text(Sprite* sprite, FONT *f, const char *text, int color) image_clear(image, 0); acquire_bitmap(bmp); - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: DO(uint32_t, _rgba(_rgba_getr(color), diff --git a/src/dialogs/maskcol.cpp b/src/dialogs/maskcol.cpp index 321d552f3..b1e45d89a 100644 --- a/src/dialogs/maskcol.cpp +++ b/src/dialogs/maskcol.cpp @@ -83,7 +83,7 @@ void dialogs_mask_color(Document* document) button_color = new ColorButton (get_config_color("MaskColor", "Color", app_get_colorbar()->getFgColor()), - sprite->getImgType()); + sprite->getPixelFormat()); button_1 = new Button("1"); button_2 = new Button("2"); label_tolerance = new Label("Tolerance:"); @@ -183,7 +183,7 @@ static Mask* gen_mask(const Sprite* sprite) const Image* image = sprite->getCurrentImage(&xpos, &ypos, NULL); - color = color_utils::color_for_image(button_color->getColor(), sprite->getImgType()); + color = color_utils::color_for_image(button_color->getColor(), sprite->getPixelFormat()); tolerance = slider_tolerance->getValue(); UniquePtr mask(new Mask()); diff --git a/src/document.cpp b/src/document.cpp index ac4167853..c5cbc0860 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -77,16 +77,16 @@ Document::~Document() destroyExtraCel(); } -Document* Document::createBasicDocument(int imgtype, int width, int height, int ncolors) +Document* Document::createBasicDocument(PixelFormat format, int width, int height, int ncolors) { // Create the sprite. - UniquePtr sprite(new Sprite(imgtype, width, height, ncolors)); + UniquePtr sprite(new Sprite(format, width, height, ncolors)); sprite->setTotalFrames(1); // Create the main image. int indexInStock; { - UniquePtr image(Image::create(imgtype, width, height)); + UniquePtr image(Image::create(format, width, height)); // Clear the image with mask color. image_clear(image, 0); @@ -246,11 +246,11 @@ void Document::prepareExtraCel(int x, int y, int w, int h, int opacity) m_extraCel->setOpacity(opacity); if (!m_extraImage || - m_extraImage->imgtype != getSprite()->getImgType() || + m_extraImage->getPixelFormat() != getSprite()->getPixelFormat() || m_extraImage->w != w || m_extraImage->h != h) { delete m_extraImage; // image - m_extraImage = Image::create(getSprite()->getImgType(), w, h); + m_extraImage = Image::create(getSprite()->getPixelFormat(), w, h); image_clear(m_extraImage, m_extraImage->mask_color = 0); } @@ -399,7 +399,7 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La Document* Document::duplicate(DuplicateType type) const { const Sprite* sourceSprite = getSprite(); - UniquePtr spriteCopyPtr(new Sprite(sourceSprite->getImgType(), + UniquePtr spriteCopyPtr(new Sprite(sourceSprite->getPixelFormat(), sourceSprite->getWidth(), sourceSprite->getHeight(), sourceSprite->getPalette(0)->size())); UniquePtr documentCopy(new Document(spriteCopyPtr)); diff --git a/src/document.h b/src/document.h index afe0a072d..ea835ebb5 100644 --- a/src/document.h +++ b/src/document.h @@ -24,6 +24,7 @@ #include "base/unique_ptr.h" #include "document_id.h" #include "gfx/transformation.h" +#include "raster/pixel_format.h" #include @@ -68,7 +69,7 @@ public: // Creates a document with one sprite, with one transparent layer, // and one frame. - static Document* createBasicDocument(int imgtype, int width, int height, int ncolors); + static Document* createBasicDocument(PixelFormat format, int width, int height, int ncolors); Document(Sprite* sprite); ~Document(); diff --git a/src/file/ase_format.cpp b/src/file/ase_format.cpp index b5319d941..55a5ee789 100644 --- a/src/file/ase_format.cpp +++ b/src/file/ase_format.cpp @@ -99,7 +99,7 @@ static Palette *ase_file_read_color2_chunk(FILE *f, Sprite *sprite, int 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, int imgtype, FileOp *fop, ASE_Header *header, size_t chunk_end); +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 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); @@ -207,7 +207,7 @@ bool AseFormat::onLoad(FileOp *fop) case ASE_FILE_CHUNK_FLI_COLOR2: /* fop_error(fop, "Color chunk\n"); */ - if (sprite->getImgType() == IMAGE_INDEXED) { + if (sprite->getPixelFormat() == IMAGE_INDEXED) { Palette *prev_pal = sprite->getPalette(frame); Palette *pal = chunk_type == ASE_FILE_CHUNK_FLI_COLOR ? @@ -237,7 +237,7 @@ bool AseFormat::onLoad(FileOp *fop) /* fop_error(fop, "Cel chunk\n"); */ ase_file_read_cel_chunk(f, sprite, frame, - sprite->getImgType(), fop, &header, + sprite->getPixelFormat(), fop, &header, chunk_pos+chunk_size); break; } @@ -318,7 +318,7 @@ bool AseFormat::onSave(FileOp *fop) frame_header.duration = sprite->getFrameDuration(frame); /* the sprite is indexed and the palette changes? (or is the first frame) */ - if (sprite->getImgType() == IMAGE_INDEXED && + if (sprite->getPixelFormat() == IMAGE_INDEXED && (frame == 0 || sprite->getPalette(frame-1)->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) { /* write the color chunk */ @@ -398,9 +398,9 @@ static void ase_file_prepare_header(FILE *f, ASE_Header *header, const Sprite* s header->frames = sprite->getTotalFrames(); header->width = sprite->getWidth(); header->height = sprite->getHeight(); - header->depth = (sprite->getImgType() == IMAGE_RGB ? 32: - sprite->getImgType() == IMAGE_GRAYSCALE ? 16: - sprite->getImgType() == IMAGE_INDEXED ? 8: 0); + header->depth = (sprite->getPixelFormat() == IMAGE_RGB ? 32: + sprite->getPixelFormat() == IMAGE_GRAYSCALE ? 16: + sprite->getPixelFormat() == IMAGE_INDEXED ? 8: 0); header->flags = 0; header->speed = sprite->getFrameDuration(0); header->next = 0; @@ -997,7 +997,9 @@ static void write_compressed_image(FILE* f, Image* image) // Cel Chunk ////////////////////////////////////////////////////////////////////// -static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgtype, FileOp *fop, ASE_Header *header, size_t chunk_end) +static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, + PixelFormat pixelFormat, + FileOp *fop, ASE_Header *header, size_t chunk_end) { Cel *cel; /* read chunk data */ @@ -1035,7 +1037,7 @@ static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgt int h = fgetw(f); if (w > 0 && h > 0) { - Image* image = Image::create(imgtype, w, h); + Image* image = Image::create(pixelFormat, w, h); if (!image) { delete cel; // Not enough memory for frame's image @@ -1043,7 +1045,7 @@ static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgt } // Read pixel data - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: read_raw_image(f, image, fop, header); @@ -1087,7 +1089,7 @@ static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgt int h = fgetw(f); if (w > 0 && h > 0) { - Image* image = Image::create(imgtype, w, h); + Image* image = Image::create(pixelFormat, w, h); if (!image) { delete cel; // Not enough memory for frame's image @@ -1095,7 +1097,7 @@ static Cel *ase_file_read_cel_chunk(FILE *f, Sprite *sprite, int frame, int imgt } // Read pixel data - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: read_compressed_image(f, image, chunk_end, fop, header); @@ -1146,7 +1148,7 @@ static void ase_file_write_cel_chunk(FILE *f, Cel *cel, LayerImage *layer, Sprit fputw(image->h, f); // Pixel data - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: write_raw_image(f, image); @@ -1184,7 +1186,7 @@ static void ase_file_write_cel_chunk(FILE *f, Cel *cel, LayerImage *layer, Sprit fputw(image->h, f); // Pixel data - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: write_compressed_image(f, image); diff --git a/src/file/bmp_format.cpp b/src/file/bmp_format.cpp index 3e1f1592f..36f9d8060 100644 --- a/src/file/bmp_format.cpp +++ b/src/file/bmp_format.cpp @@ -603,7 +603,8 @@ bool BmpFormat::onLoad(FileOp *fop) Image *image; FILE *f; unsigned long biSize; - int type, format; + PixelFormat pixelFormat; + int format; f = fopen(fop->filename.c_str(), "rb"); if (!f) @@ -645,9 +646,9 @@ bool BmpFormat::onLoad(FileOp *fop) if ((infoheader.biBitCount == 32) || (infoheader.biBitCount == 24) || (infoheader.biBitCount == 16)) - type = IMAGE_RGB; + pixelFormat = IMAGE_RGB; else - type = IMAGE_INDEXED; + pixelFormat = IMAGE_INDEXED; /* bitfields have the 'mask' for each component */ if (infoheader.biCompression == BI_BITFIELDS) { @@ -658,7 +659,7 @@ bool BmpFormat::onLoad(FileOp *fop) else rmask = gmask = bmask = 0; - image = fop_sequence_image(fop, type, + image = fop_sequence_image(fop, pixelFormat, infoheader.biWidth, ABS((int)infoheader.biHeight)); if (!image) { @@ -666,7 +667,7 @@ bool BmpFormat::onLoad(FileOp *fop) return false; } - if (type == IMAGE_RGB) + if (pixelFormat == IMAGE_RGB) image_clear(image, _rgba(0, 0, 0, 255)); else image_clear(image, 0); @@ -730,7 +731,7 @@ bool BmpFormat::onSave(FileOp *fop) FILE *f; int bfSize; int biSizeImage; - int bpp = (image->imgtype == IMAGE_RGB) ? 24 : 8; + int bpp = (image->getPixelFormat() == IMAGE_RGB) ? 24 : 8; int filler = 3 - ((image->w*(bpp/8)-1) & 3); int c, i, j, r, g, b; @@ -795,9 +796,9 @@ bool BmpFormat::onSave(FileOp *fop) for (i=image->h-1; i>=0; i--) { for (j=0; jw; j++) { if (bpp == 8) { - if (image->imgtype == IMAGE_INDEXED) + if (image->getPixelFormat() == IMAGE_INDEXED) fputc(image_getpixel_fast(image, j, i), f); - else if (image->imgtype == IMAGE_GRAYSCALE) + else if (image->getPixelFormat() == IMAGE_GRAYSCALE) fputc(_graya_getv(image_getpixel_fast(image, j, i)), f); } else { diff --git a/src/file/file.cpp b/src/file/file.cpp index 97f9a90e4..8bbec9f6c 100644 --- a/src/file/file.cpp +++ b/src/file/file.cpp @@ -254,7 +254,7 @@ FileOp* fop_to_save_document(Document* document) fatal = false; /* check image type support */ - switch (fop->document->getSprite()->getImgType()) { + switch (fop->document->getSprite()->getPixelFormat()) { case IMAGE_RGB: if (!(fop->format->support(FILE_SUPPORT_RGB))) { @@ -542,7 +542,7 @@ void fop_operate(FileOp *fop) Sprite* sprite = fop->document->getSprite(); // Create a temporary bitmap - fop->seq.image = Image::create(sprite->getImgType(), + fop->seq.image = Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()); if (fop->seq.image != NULL) { @@ -654,7 +654,7 @@ void fop_post_load(FileOp* fop) } // Creates a suitable palette for RGB images - if (fop->document->getSprite()->getImgType() == IMAGE_RGB && + if (fop->document->getSprite()->getPixelFormat() == IMAGE_RGB && fop->document->getSprite()->getPalettes().size() <= 1 && fop->document->getSprite()->getPalette(0)->isBlack()) { SharedPtr palette(quantization::create_palette_from_rgb(fop->document->getSprite())); @@ -687,13 +687,13 @@ void fop_sequence_get_color(FileOp *fop, int index, int *r, int *g, int *b) *b = _rgba_getb(c); } -Image* fop_sequence_image(FileOp* fop, int imgtype, int w, int h) +Image* fop_sequence_image(FileOp* fop, PixelFormat pixelFormat, int w, int h) { Sprite* sprite; // Create the image if (!fop->document) { - sprite = new Sprite(imgtype, w, h, 256); + sprite = new Sprite(pixelFormat, w, h, 256); try { LayerImage* layer = new LayerImage(sprite); @@ -712,7 +712,7 @@ Image* fop_sequence_image(FileOp* fop, int imgtype, int w, int h) else { sprite = fop->document->getSprite(); - if (sprite->getImgType() != imgtype) + if (sprite->getPixelFormat() != pixelFormat) return NULL; } @@ -722,7 +722,7 @@ Image* fop_sequence_image(FileOp* fop, int imgtype, int w, int h) } // Create a bitmap - Image* image = Image::create(imgtype, w, h); + Image* image = Image::create(pixelFormat, w, h); fop->seq.image = image; fop->seq.last_cel = new Cel(fop->seq.frame++, 0); diff --git a/src/file/file.h b/src/file/file.h index 54cf975fa..8be08ac95 100644 --- a/src/file/file.h +++ b/src/file/file.h @@ -20,6 +20,7 @@ #define FILE_FILE_H_INCLUDED #include "base/shared_ptr.h" +#include "raster/pixeL_format.h" #include #include @@ -115,7 +116,7 @@ void fop_post_load(FileOp* fop); void fop_sequence_set_format_options(FileOp* fop, const SharedPtr& format_options); void fop_sequence_set_color(FileOp* fop, int index, int r, int g, int b); void fop_sequence_get_color(FileOp* fop, int index, int *r, int *g, int *b); -Image* fop_sequence_image(FileOp* fi, int imgtype, int w, int h); +Image* fop_sequence_image(FileOp* fi, PixelFormat pixelFormat, int w, int h); void fop_error(FileOp* fop, const char *error, ...); void fop_progress(FileOp* fop, float progress); diff --git a/src/file/gif_format.cpp b/src/file/gif_format.cpp index 60a8b2c93..7a6d69548 100644 --- a/src/file/gif_format.cpp +++ b/src/file/gif_format.cpp @@ -274,7 +274,7 @@ bool GifFormat::onPostLoad(FileOp* fop) if (!data) return true; - int imgtype = IMAGE_INDEXED; + PixelFormat pixelFormat = IMAGE_INDEXED; bool askForConversion = false; if (!fop->oneframe) { @@ -326,19 +326,19 @@ bool GifFormat::onPostLoad(FileOp* fop) fop->document->getFilename()); if (result == 1) - imgtype = IMAGE_RGB; + pixelFormat = IMAGE_RGB; else if (result != 2) return false; } // Create the sprite with the GIF dimension - UniquePtr sprite(new Sprite(imgtype, data->sprite_w, data->sprite_h, 256)); + UniquePtr sprite(new Sprite(pixelFormat, data->sprite_w, data->sprite_h, 256)); // Create the main layer LayerImage* layer = new LayerImage(sprite); sprite->getFolder()->add_layer(layer); - if (imgtype == IMAGE_INDEXED) { + if (pixelFormat == IMAGE_INDEXED) { if (data->bgcolor_index >= 0) sprite->setTransparentColor(data->bgcolor_index); else @@ -348,11 +348,11 @@ bool GifFormat::onPostLoad(FileOp* fop) // The previous image is used to support the special disposal method // of GIF frames DISPOSAL_METHOD_RESTORE_PREVIOUS (number 3 in // Graphics Extension) - UniquePtr current_image(Image::create(imgtype, data->sprite_w, data->sprite_h)); - UniquePtr previous_image(Image::create(imgtype, data->sprite_w, data->sprite_h)); + UniquePtr current_image(Image::create(pixelFormat, data->sprite_w, data->sprite_h)); + UniquePtr previous_image(Image::create(pixelFormat, data->sprite_w, data->sprite_h)); // Clear both images with the transparent color (alpha = 0). - uint32_t bgcolor = (imgtype == IMAGE_RGB ? _rgba(0, 0, 0, 0): + uint32_t bgcolor = (pixelFormat == IMAGE_RGB ? _rgba(0, 0, 0, 0): (data->bgcolor_index >= 0 ? data->bgcolor_index: 0)); image_clear(current_image, bgcolor); image_clear(previous_image, bgcolor); @@ -375,7 +375,7 @@ bool GifFormat::onPostLoad(FileOp* fop) current_palette = frame_it->palette; } - switch (imgtype) { + switch (pixelFormat) { case IMAGE_INDEXED: for (int y = 0; y < frame_it->image->h; ++y) @@ -490,10 +490,10 @@ bool GifFormat::onSave(FileOp* fop) Sprite* sprite = fop->document->getSprite(); int sprite_w = sprite->getWidth(); int sprite_h = sprite->getHeight(); - int sprite_imgtype = sprite->getImgType(); + PixelFormat sprite_format = sprite->getPixelFormat(); bool interlace = false; int loop = 0; - int background_color = (sprite_imgtype == IMAGE_INDEXED ? sprite->getTransparentColor(): 0); + int background_color = (sprite_format == IMAGE_INDEXED ? sprite->getTransparentColor(): 0); int transparent_index = (sprite->getBackgroundLayer() ? -1: sprite->getTransparentColor()); Palette* current_palette = sprite->getPalette(0); @@ -519,8 +519,8 @@ bool GifFormat::onSave(FileOp* fop) // If the sprite is not Indexed type, we will need a temporary // buffer to render the full RGB or Grayscale sprite. - if (sprite_imgtype != IMAGE_INDEXED) - buffer_image.reset(Image::create(sprite_imgtype, sprite_w, sprite_h)); + if (sprite_format != IMAGE_INDEXED) + buffer_image.reset(Image::create(sprite_format, sprite_w, sprite_h)); image_clear(current_image, background_color); image_clear(previous_image, background_color); @@ -529,11 +529,11 @@ bool GifFormat::onSave(FileOp* fop) current_palette = sprite->getPalette(frame_num); // If the sprite is RGB or Grayscale, we must to convert it to Indexed on the fly. - if (sprite_imgtype != IMAGE_INDEXED) { + if (sprite_format != IMAGE_INDEXED) { image_clear(buffer_image, 0); layer_render(sprite->getFolder(), buffer_image, 0, 0, frame_num); - switch (sprite_imgtype) { + switch (sprite_format) { // Convert the RGB image to Indexed case IMAGE_RGB: diff --git a/src/file/ico_format.cpp b/src/file/ico_format.cpp index 8b90d3781..317c28d07 100644 --- a/src/file/ico_format.cpp +++ b/src/file/ico_format.cpp @@ -129,17 +129,17 @@ bool IcoFormat::onLoad(FileOp* fop) int width = (entry.width == 0 ? 256: entry.width); int height = (entry.height == 0 ? 256: entry.height); int numcolors = (entry.color_count == 0 ? 256: entry.color_count); - int imgtype = IMAGE_INDEXED; + PixelFormat pixelFormat = IMAGE_INDEXED; if (entry.bpp > 8) - imgtype = IMAGE_RGB; + pixelFormat = IMAGE_RGB; // Create the sprite with one background layer - Sprite* sprite = new Sprite(imgtype, width, height, numcolors); + Sprite* sprite = new Sprite(pixelFormat, width, height, numcolors); LayerImage* layer = new LayerImage(sprite); sprite->getFolder()->add_layer(layer); // Create the first image/cel - Image* image = Image::create(imgtype, width, height); + Image* image = Image::create(pixelFormat, width, height); int image_index = sprite->getStock()->addImage(image); Cel* cel = new Cel(0, image_index); layer->addCel(cel); @@ -258,7 +258,7 @@ bool IcoFormat::onSave(FileOp* fop) // Entries for (n=0; ngetImgType() == IMAGE_INDEXED) ? 8 : 24; + bpp = (sprite->getPixelFormat() == IMAGE_INDEXED) ? 8 : 24; bw = (((sprite->getWidth() * bpp / 8) + 3) / 4) * 4; bitsw = ((((sprite->getWidth() + 7) / 8) + 3) / 4) * 4; size = sprite->getHeight() * (bw + bitsw) + 40; @@ -279,7 +279,7 @@ bool IcoFormat::onSave(FileOp* fop) offset += size; } - Image* image = Image::create(sprite->getImgType(), + Image* image = Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()); @@ -287,7 +287,7 @@ bool IcoFormat::onSave(FileOp* fop) image_clear(image, 0); layer_render(sprite->getFolder(), image, 0, 0, n); - bpp = (sprite->getImgType() == IMAGE_INDEXED) ? 8 : 24; + bpp = (sprite->getPixelFormat() == IMAGE_INDEXED) ? 8 : 24; bw = (((image->w * bpp / 8) + 3) / 4) * 4; bitsw = ((((image->w + 7) / 8) + 3) / 4) * 4; size = image->h * (bw + bitsw) + 40; @@ -325,7 +325,7 @@ bool IcoFormat::onSave(FileOp* fop) // XOR MASK for (y=image->h-1; y>=0; --y) { for (x=0; xw; ++x) { - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: c = image_getpixel(image, x, y); @@ -364,7 +364,7 @@ bool IcoFormat::onSave(FileOp* fop) for (b=0; b<8; b++) { c = image_getpixel(image, x*8+b, y); - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: if (_rgba_geta(c) == 0) diff --git a/src/file/jpeg_format.cpp b/src/file/jpeg_format.cpp index 70fad40ac..62693000a 100644 --- a/src/file/jpeg_format.cpp +++ b/src/file/jpeg_format.cpp @@ -177,7 +177,7 @@ bool JpegFormat::onLoad(FileOp* fop) } // Generate a grayscale palette if is necessary. - if (image->imgtype == IMAGE_GRAYSCALE) + if (image->getPixelFormat() == IMAGE_GRAYSCALE) for (c=0; c<256; c++) fop_sequence_set_color(fop, c, c, c, c); @@ -190,7 +190,7 @@ bool JpegFormat::onLoad(FileOp* fop) num_scanlines = jpeg_read_scanlines(&cinfo, buffer, buffer_height); /* RGB */ - if (image->imgtype == IMAGE_RGB) { + if (image->getPixelFormat() == IMAGE_RGB) { uint8_t* src_address; uint32_t* dst_address; int x, y, r, g, b; @@ -269,7 +269,7 @@ bool JpegFormat::onSave(FileOp* fop) cinfo.image_width = image->w; cinfo.image_height = image->h; - if (image->imgtype == IMAGE_GRAYSCALE) { + if (image->getPixelFormat() == IMAGE_GRAYSCALE) { cinfo.input_components = 1; cinfo.in_color_space = JCS_GRAYSCALE; } @@ -313,7 +313,7 @@ bool JpegFormat::onSave(FileOp* fop) // Write each scan line. while (cinfo.next_scanline < cinfo.image_height) { // RGB - if (image->imgtype == IMAGE_RGB) { + if (image->getPixelFormat() == IMAGE_RGB) { uint32_t* src_address; uint8_t* dst_address; int x, y; diff --git a/src/file/pcx_format.cpp b/src/file/pcx_format.cpp index ed6f63336..e62783d7e 100644 --- a/src/file/pcx_format.cpp +++ b/src/file/pcx_format.cpp @@ -202,7 +202,7 @@ bool PcxFormat::onSave(FileOp* fop) return false; } - if (image->imgtype == IMAGE_RGB) { + if (image->getPixelFormat() == IMAGE_RGB) { depth = 24; planes = 3; } @@ -243,9 +243,9 @@ bool PcxFormat::onSave(FileOp* fop) runchar = 0; for (x=0; xw*planes; x++) { /* for each pixel... */ if (depth == 8) { - if (image->imgtype == IMAGE_INDEXED) + if (image->getPixelFormat() == IMAGE_INDEXED) ch = image_getpixel_fast(image, x, y); - else if (image->imgtype == IMAGE_GRAYSCALE) { + else if (image->getPixelFormat() == IMAGE_GRAYSCALE) { c = image_getpixel_fast(image, x, y); ch = _graya_getv(c); } diff --git a/src/file/png_format.cpp b/src/file/png_format.cpp index c515c6a9d..3be1c1d8a 100644 --- a/src/file/png_format.cpp +++ b/src/file/png_format.cpp @@ -75,8 +75,8 @@ bool PngFormat::onLoad(FileOp* fop) png_colorp palette; png_bytep row_pointer; Image *image; - int imgtype; FILE *fp; + PixelFormat pixelFormat; fp = fopen(fop->filename.c_str(), "rb"); if (!fp) @@ -167,17 +167,17 @@ bool PngFormat::onLoad(FileOp* fop) case PNG_COLOR_TYPE_RGB_ALPHA: fop->seq.has_alpha = true; case PNG_COLOR_TYPE_RGB: - imgtype = IMAGE_RGB; + pixelFormat = IMAGE_RGB; break; case PNG_COLOR_TYPE_GRAY_ALPHA: fop->seq.has_alpha = true; case PNG_COLOR_TYPE_GRAY: - imgtype = IMAGE_GRAYSCALE; + pixelFormat = IMAGE_GRAYSCALE; break; case PNG_COLOR_TYPE_PALETTE: - imgtype = IMAGE_INDEXED; + pixelFormat = IMAGE_INDEXED; break; default: @@ -187,7 +187,7 @@ bool PngFormat::onLoad(FileOp* fop) return false; } - image = fop_sequence_image(fop, imgtype, info_ptr->width, info_ptr->height); + image = fop_sequence_image(fop, pixelFormat, info_ptr->width, info_ptr->height); if (!image) { fop_error(fop, "file_sequence_image %dx%d\n", info_ptr->width, info_ptr->height); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); @@ -395,7 +395,7 @@ bool PngFormat::onSave(FileOp* fop) width = image->w; height = image->h; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: color_type = fop->document->getSprite()->needAlpha() ? PNG_COLOR_TYPE_RGB_ALPHA: @@ -414,7 +414,7 @@ bool PngFormat::onSave(FileOp* fop) png_set_IHDR(png_ptr, info_ptr, width, height, 8, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - if (image->imgtype == IMAGE_INDEXED) { + if (image->getPixelFormat() == IMAGE_INDEXED) { int c, r, g, b; #if PNG_MAX_PALETTE_LENGTH != 256 @@ -544,7 +544,7 @@ bool PngFormat::onSave(FileOp* fop) libpng mallocs info_ptr->palette, libpng will free it). If you allocated it with malloc() instead of png_malloc(), use free() instead of png_free(). */ - if (image->imgtype == IMAGE_INDEXED) { + if (image->getPixelFormat() == IMAGE_INDEXED) { png_free(png_ptr, palette); palette = NULL; } diff --git a/src/file/tga_format.cpp b/src/file/tga_format.cpp index 8bb903184..f69d35299 100644 --- a/src/file/tga_format.cpp +++ b/src/file/tga_format.cpp @@ -204,7 +204,6 @@ bool TgaFormat::onLoad(FileOp* fop) Image *image; int compressed; FILE *f; - int type; f = fopen(fop->filename.c_str(), "rb"); if (!f) @@ -264,6 +263,8 @@ bool TgaFormat::onLoad(FileOp* fop) compressed = (image_type & 8); image_type &= 7; + PixelFormat pixelFormat; + switch (image_type) { /* paletted image */ @@ -280,7 +281,7 @@ bool TgaFormat::onLoad(FileOp* fop) image_palette[i][0]); } - type = IMAGE_INDEXED; + pixelFormat = IMAGE_INDEXED; break; /* truecolor image */ @@ -292,7 +293,7 @@ bool TgaFormat::onLoad(FileOp* fop) return false; } - type = IMAGE_RGB; + pixelFormat = IMAGE_RGB; break; /* grayscale image */ @@ -305,7 +306,7 @@ bool TgaFormat::onLoad(FileOp* fop) for (i=0; i<256; i++) fop_sequence_set_color(fop, i, i, i, i); - type = IMAGE_GRAYSCALE; + pixelFormat = IMAGE_GRAYSCALE; break; default: @@ -315,7 +316,7 @@ bool TgaFormat::onLoad(FileOp* fop) return false; } - image = fop_sequence_image(fop, type, image_width, image_height); + image = fop_sequence_image(fop, pixelFormat, image_width, image_height); if (!image) { fclose(f); return false; @@ -408,8 +409,8 @@ bool TgaFormat::onSave(FileOp* fop) Image *image = fop->seq.image; unsigned char image_palette[256][3]; int x, y, c, r, g, b; - int depth = (image->imgtype == IMAGE_RGB) ? 32 : 8; - bool need_pal = (image->imgtype == IMAGE_INDEXED)? true: false; + int depth = (image->getPixelFormat() == IMAGE_RGB) ? 32 : 8; + bool need_pal = (image->getPixelFormat() == IMAGE_INDEXED)? true: false; FILE *f; f = fopen(fop->filename.c_str(), "wb"); @@ -421,9 +422,9 @@ bool TgaFormat::onSave(FileOp* fop) fputc(0, f); /* id length (no id saved) */ fputc((need_pal) ? 1 : 0, f); /* palette type */ /* image type */ - fputc((image->imgtype == IMAGE_RGB ) ? 2 : - (image->imgtype == IMAGE_GRAYSCALE) ? 3 : - (image->imgtype == IMAGE_INDEXED ) ? 1 : 0, f); + fputc((image->getPixelFormat() == IMAGE_RGB ) ? 2 : + (image->getPixelFormat() == IMAGE_GRAYSCALE) ? 3 : + (image->getPixelFormat() == IMAGE_INDEXED ) ? 1 : 0, f); fputw(0, f); /* first colour */ fputw((need_pal) ? 256 : 0, f); /* number of colours */ fputc((need_pal) ? 24 : 0, f); /* palette entry size */ @@ -434,7 +435,7 @@ bool TgaFormat::onSave(FileOp* fop) fputc(depth, f); /* bits per pixel */ /* descriptor (bottom to top, 8-bit alpha) */ - fputc(image->imgtype == IMAGE_RGB ? 8: 0, f); + fputc(image->getPixelFormat() == IMAGE_RGB ? 8: 0, f); if (need_pal) { for (y=0; y<256; y++) { @@ -446,7 +447,7 @@ bool TgaFormat::onSave(FileOp* fop) fwrite(image_palette, 1, 768, f); } - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: for (y=image->h-1; y>=0; y--) { diff --git a/src/modules/gfx.cpp b/src/modules/gfx.cpp index a5b074941..e1045c2c8 100644 --- a/src/modules/gfx.cpp +++ b/src/modules/gfx.cpp @@ -355,7 +355,7 @@ void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, int color) center.x+size/2, center.y-size/2, color); } -void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color) +void draw_color(BITMAP* bmp, const Rect& rc, PixelFormat pixelFormat, const Color& color) { Color::Type type = color.getType(); BITMAP* graph; @@ -378,11 +378,11 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color) return; } - switch (imgtype) { + switch (pixelFormat) { case IMAGE_INDEXED: rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, - color_utils::color_for_allegro(Color::fromIndex(color_utils::color_for_image(color, imgtype)), + color_utils::color_for_allegro(Color::fromIndex(color_utils::color_for_image(color, pixelFormat)), bitmap_color_depth(bmp))); break; @@ -392,7 +392,7 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color) return; { - int rgb_bitmap_color = color_utils::color_for_image(color, imgtype); + int rgb_bitmap_color = color_utils::color_for_image(color, pixelFormat); Color color2 = Color::fromRgb(_rgba_getr(rgb_bitmap_color), _rgba_getg(rgb_bitmap_color), _rgba_getb(rgb_bitmap_color)); @@ -411,7 +411,7 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color) return; { - int gray_bitmap_color = color_utils::color_for_image(color, imgtype); + int gray_bitmap_color = color_utils::color_for_image(color, pixelFormat); Color color2 = Color::fromGray(_graya_getv(gray_bitmap_color)); rectfill(graph, 0, 0, rc.w-1, rc.h-1, color_utils::color_for_allegro(color2, 32)); @@ -428,7 +428,7 @@ void draw_color_button(BITMAP* bmp, const Rect& rc, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_se, bool outer_s, bool outer_sw, bool outer_w, - int imgtype, const Color& color, bool hot, bool drag) + PixelFormat pixelFormat, const Color& color, bool hot, bool drag) { SkinTheme* theme = (SkinTheme*)CurrentTheme::get(); int scale = jguiscale(); @@ -438,7 +438,7 @@ void draw_color_button(BITMAP* bmp, Rect(rc.x+1*jguiscale(), rc.y+1*jguiscale(), rc.w-((outer_e) ? 2*jguiscale(): 1*jguiscale()), - rc.h-((outer_s) ? 2*jguiscale(): 1*jguiscale())), imgtype, color); + rc.h-((outer_s) ? 2*jguiscale(): 1*jguiscale())), pixelFormat, color); // Draw opaque border { diff --git a/src/modules/gfx.h b/src/modules/gfx.h index 5f2fba3d7..679fe5ed7 100644 --- a/src/modules/gfx.h +++ b/src/modules/gfx.h @@ -49,12 +49,12 @@ void rectdotted(BITMAP* bmp, int x1, int y1, int x2, int y2, int fg, int bg); void rectgrid(BITMAP* bmp, int x1, int y1, int x2, int y2, int w, int h); void draw_emptyset_symbol(BITMAP* bmp, const gfx::Rect& rc, int color); -void draw_color(BITMAP* bmp, const gfx::Rect& rc, int imgtype, const Color& color); +void draw_color(BITMAP* bmp, const gfx::Rect& rc, PixelFormat pixelFormat, const Color& color); void draw_color_button(BITMAP* bmp, const gfx::Rect& rc, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_se, bool outer_s, bool outer_sw, bool outer_w, - int imgtype, const Color& color, + PixelFormat pixelFormat, const Color& color, bool hot, bool drag); void draw_progress_bar(BITMAP* bmp, int x1, int y1, int x2, int y2, diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index 126af050f..744747976 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -18,16 +18,6 @@ #include "config.h" -#include -#include -#include -#include -#include - -#ifdef ALLEGRO_WINDOWS -#include -#endif - #include "app.h" #include "base/memory.h" #include "base/shared_ptr.h" @@ -59,6 +49,16 @@ #include "widgets/toolbar.h" #include "xml_widgets.h" +#include +#include +#include +#include +#include + +#ifdef ALLEGRO_WINDOWS +#include +#endif + #define REFRESH_FULL_SCREEN 1 #define SYSTEM_WINDOW_RESIZE 2 diff --git a/src/raster/algofill.cpp b/src/raster/algofill.cpp index 614ef9b80..0f853cb96 100644 --- a/src/raster/algofill.cpp +++ b/src/raster/algofill.cpp @@ -19,14 +19,14 @@ #include "config.h" +#include "raster/algo.h" +#include "raster/image.h" + #include #include #include #include -#include "raster/algo.h" -#include "raster/image.h" - typedef struct FLOODED_LINE /* store segments which have been flooded */ @@ -112,7 +112,7 @@ static int flooder (Image *image, int x, int y, int left = 0, right = 0; int c; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: { diff --git a/src/raster/dirty.cpp b/src/raster/dirty.cpp index 21ed0af3e..22d652d91 100644 --- a/src/raster/dirty.cpp +++ b/src/raster/dirty.cpp @@ -18,20 +18,20 @@ #include "config.h" -#include - #include "raster/dirty.h" #include "raster/image.h" -Dirty::Dirty(int imgtype, int x1, int y1, int x2, int y2) - : m_imgtype(imgtype) +#include + +Dirty::Dirty(PixelFormat format, int x1, int y1, int x2, int y2) + : m_format(format) , m_x1(x1), m_y1(y1) , m_x2(x2), m_y2(y2) { } Dirty::Dirty(const Dirty& src) - : m_imgtype(src.m_imgtype) + : m_format(src.m_format) , m_x1(src.m_x1), m_y1(src.m_y1) , m_x2(src.m_x2), m_y2(src.m_y2) { @@ -53,7 +53,7 @@ Dirty::Dirty(const Dirty& src) } Dirty::Dirty(Image* image, Image* image_diff) - : m_imgtype(image->imgtype) + : m_format(image->getPixelFormat()) , m_x1(0), m_y1(0) , m_x2(image->w-1), m_y2(image->h-1) { diff --git a/src/raster/dirty.h b/src/raster/dirty.h index fd1d1ee58..d0440f6e6 100644 --- a/src/raster/dirty.h +++ b/src/raster/dirty.h @@ -52,14 +52,14 @@ public: Row(int y) : y(y) { } }; - Dirty(int imgtype, int x1, int y1, int x2, int y2); + Dirty(PixelFormat format, int x1, int y1, int x2, int y2); Dirty(const Dirty& src); Dirty(Image* image1, Image* image2); ~Dirty(); int getMemSize() const; - int getImgType() const { return m_imgtype; } + PixelFormat getPixelFormat() const { return m_format; } int x1() const { return m_x1; } int y1() const { return m_y1; } int x2() const { return m_x2; } @@ -69,7 +69,7 @@ public: const Row& getRow(int i) const { return *m_rows[i]; } inline int getLineSize(int width) const { - return imgtype_line_size(m_imgtype, width); + return pixelformat_line_size(m_format, width); } void saveImagePixels(Image* image); @@ -86,7 +86,7 @@ public: // a Dirty instance from a deserialization process, // remember to "privatize" these members when the // new Undo implementation is finished. - int m_imgtype; + PixelFormat m_format; int m_x1, m_y1; int m_x2, m_y2; RowsList m_rows; diff --git a/src/raster/dirty_io.cpp b/src/raster/dirty_io.cpp index 493ad42cd..0af79d58b 100644 --- a/src/raster/dirty_io.cpp +++ b/src/raster/dirty_io.cpp @@ -47,7 +47,7 @@ using namespace base::serialization::little_endian; void write_dirty(std::ostream& os, Dirty* dirty) { - write8(os, dirty->getImgType()); + write8(os, dirty->getPixelFormat()); write16(os, dirty->x1()); write16(os, dirty->y1()); write16(os, dirty->x2()); @@ -73,12 +73,12 @@ void write_dirty(std::ostream& os, Dirty* dirty) Dirty* read_dirty(std::istream& is) { int u, v, x, y, w; - int imgtype = read8(is); + int pixelFormat = read8(is); int x1 = read16(is); int y1 = read16(is); int x2 = read16(is); int y2 = read16(is); - UniquePtr dirty(new Dirty(imgtype, x1, y1, x2, y2)); + UniquePtr dirty(new Dirty(static_cast(pixelFormat), x1, y1, x2, y2)); int noRows = read16(is); if (noRows > 0) { diff --git a/src/raster/image.cpp b/src/raster/image.cpp index 938726292..893ba5e97 100644 --- a/src/raster/image.cpp +++ b/src/raster/image.cpp @@ -32,10 +32,10 @@ ////////////////////////////////////////////////////////////////////// -Image::Image(int imgtype, int w, int h) +Image::Image(PixelFormat format, int w, int h) : GfxObj(GFXOBJ_IMAGE) + , m_format(format) { - this->imgtype = imgtype; this->w = w; this->h = h; this->dat = NULL; @@ -53,7 +53,7 @@ int Image::getMemSize() const { int scanline_size = 0; - if (imgtype == IMAGE_BITMAP) + if (m_format == IMAGE_BITMAP) scanline_size = BitmapTraits::scanline_size(this->w); else scanline_size = image_line_size(this, this->w); @@ -61,11 +61,10 @@ int Image::getMemSize() const return sizeof(Image) + scanline_size*this->h; } -////////////////////////////////////////////////////////////////////// - -Image* Image::create(int imgtype, int w, int h) +// static +Image* Image::create(PixelFormat format, int w, int h) { - switch (imgtype) { + switch (format) { case IMAGE_RGB: return new ImageImpl(w, h); case IMAGE_GRAYSCALE: return new ImageImpl(w, h); case IMAGE_INDEXED: return new ImageImpl(w, h); @@ -74,6 +73,7 @@ Image* Image::create(int imgtype, int w, int h) return NULL; } +// static Image* Image::createCopy(const Image* image) { ASSERT(image); @@ -143,7 +143,7 @@ Image* image_crop(const Image* image, int x, int y, int w, int h, int bgcolor) if (w < 1) throw std::invalid_argument("image_crop: Width is less than 1"); if (h < 1) throw std::invalid_argument("image_crop: Height is less than 1"); - Image* trim = Image::create(image->imgtype, w, h); + Image* trim = Image::create(image->getPixelFormat(), w, h); trim->mask_color = image->mask_color; image_clear(trim, bgcolor); @@ -360,7 +360,7 @@ void image_fixup_transparent_colors(Image* image) { int x, y, u, v; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: { uint32_t c; @@ -518,7 +518,7 @@ void image_resize(const Image* src, Image* dst, ResizeMethod method, const Palet double u2 = 1 - u1; double v2 = 1 - v1; - switch (dst->imgtype) { + switch (dst->getPixelFormat()) { case IMAGE_RGB: { int r = ((_rgba_getr(color[0])*u2 + _rgba_getr(color[1])*u1)*v2 + (_rgba_getr(color[2])*u2 + _rgba_getr(color[3])*u1)*v1); @@ -575,12 +575,13 @@ int image_count_diff(const Image* i1, const Image* i2) { int c, size, diff = 0; - if ((i1->imgtype != i2->imgtype) || (i1->w != i2->w) || (i1->h != i2->h)) + if ((i1->getPixelFormat() != i2->getPixelFormat()) || + (i1->w != i2->w) || (i1->h != i2->h)) return -1; size = i1->w * i1->h; - switch (i1->imgtype) { + switch (i1->getPixelFormat()) { case IMAGE_RGB: { diff --git a/src/raster/image.h b/src/raster/image.h index 4ee8f5c5f..9b158e001 100644 --- a/src/raster/image.h +++ b/src/raster/image.h @@ -19,23 +19,17 @@ #ifndef RASTER_IMAGE_H_INCLUDED #define RASTER_IMAGE_H_INCLUDED -#include -#include "raster/gfxobj.h" #include "raster/blend.h" +#include "raster/gfxobj.h" +#include "raster/pixel_format.h" + +#include class Palette; class Pen; class RgbMap; -// Image Types -enum { - IMAGE_RGB, - IMAGE_GRAYSCALE, - IMAGE_INDEXED, - IMAGE_BITMAP -}; - enum ResizeMethod { RESIZE_METHOD_NEAREST_NEIGHBOR, RESIZE_METHOD_BILINEAR, @@ -46,18 +40,19 @@ struct BITMAP; class Image : public GfxObj { public: - int imgtype; int w, h; uint8_t* dat; // Pixmap data. uint8_t** line; // Start of each scanline. uint32_t mask_color; // Skipped color in merge process. - static Image* create(int imgtype, int w, int h); + static Image* create(PixelFormat format, int w, int h); static Image* createCopy(const Image* image); - Image(int imgtype, int w, int h); + Image(PixelFormat format, int w, int h); virtual ~Image(); + PixelFormat getPixelFormat() const { return m_format; } + int getMemSize() const; virtual int getpixel(int x, int y) const = 0; @@ -69,6 +64,9 @@ public: virtual void rectfill(int x1, int y1, int x2, int y2, int color) = 0; virtual void rectblend(int x1, int y1, int x2, int y2, int color, int opacity) = 0; virtual void to_allegro(BITMAP* bmp, int x, int y, const Palette* palette) const = 0; + +private: + PixelFormat m_format; }; void image_free(Image* image); @@ -102,20 +100,20 @@ void image_resize(const Image* src, Image* dst, ResizeMethod method, const Palet int image_count_diff(const Image* i1, const Image* i2); bool image_shrink_rect(Image *image, int *x1, int *y1, int *x2, int *y2, int refpixel); -inline int imgtype_shift(int imgtype) +inline int pixelformat_shift(PixelFormat pixelFormat) { - return ((imgtype == IMAGE_RGB)? 2: - (imgtype == IMAGE_GRAYSCALE)? 1: 0); + return ((pixelFormat == IMAGE_RGB)? 2: + (pixelFormat == IMAGE_GRAYSCALE)? 1: 0); +} + +inline int pixelformat_line_size(PixelFormat format, int width) +{ + return (width << pixelformat_shift(format)); } inline int image_shift(const Image* image) { - return imgtype_shift(image->imgtype); -} - -inline int imgtype_line_size(int imgtype, int width) -{ - return (width << imgtype_shift(imgtype)); + return pixelformat_shift(image->getPixelFormat()); } inline int image_line_size(const Image* image, int width) diff --git a/src/raster/image_impl.h b/src/raster/image_impl.h index 0027bd9b0..3d35266a8 100644 --- a/src/raster/image_impl.h +++ b/src/raster/image_impl.h @@ -52,7 +52,7 @@ public: // raw access to pixel-data public: ImageImpl(int w, int h) - : Image(Traits::imgtype, w, h) + : Image(static_cast(Traits::pixel_format), w, h) { int bytes_per_line = Traits::scanline_size(w); diff --git a/src/raster/image_io.cpp b/src/raster/image_io.cpp index 769099a45..3e1e712b8 100644 --- a/src/raster/image_io.cpp +++ b/src/raster/image_io.cpp @@ -45,7 +45,7 @@ using namespace base::serialization::little_endian; void write_image(std::ostream& os, Image* image) { - write8(os, image->imgtype); // Imgtype + write8(os, image->getPixelFormat()); // Pixel format write16(os, image->w); // Width write16(os, image->h); // Height write32(os, image->mask_color); // Mask color @@ -57,12 +57,12 @@ void write_image(std::ostream& os, Image* image) Image* read_image(std::istream& is) { - int imgtype = read8(is); // Imgtype + int pixelFormat = read8(is); // Pixel format int width = read16(is); // Width int height = read16(is); // Height uint32_t maskColor = read32(is); // Mask color - UniquePtr image(Image::create(imgtype, width, height)); + UniquePtr image(Image::create(static_cast(pixelFormat), width, height)); int size = image_line_size(image, image->w); for (int c=0; ch; c++) diff --git a/src/raster/image_traits.h b/src/raster/image_traits.h index 25e2503d0..676f66166 100644 --- a/src/raster/image_traits.h +++ b/src/raster/image_traits.h @@ -58,7 +58,7 @@ inline uint32_t _rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) struct RgbTraits { enum { - imgtype = IMAGE_RGB, + pixel_format = IMAGE_RGB, bits_per_pixel = 32, bytes_per_pixel = 4, channels = 4, @@ -107,7 +107,7 @@ inline uint16_t _graya(uint8_t v, uint8_t a) struct GrayscaleTraits { enum { - imgtype = IMAGE_GRAYSCALE, + pixel_format = IMAGE_GRAYSCALE, bits_per_pixel = 16, bytes_per_pixel = 2, channels = 2, @@ -137,7 +137,7 @@ struct GrayscaleTraits struct IndexedTraits { enum { - imgtype = IMAGE_INDEXED, + pixel_format = IMAGE_INDEXED, bits_per_pixel = 8, bytes_per_pixel = 1, channels = 1, @@ -161,7 +161,7 @@ struct IndexedTraits struct BitmapTraits { enum { - imgtype = IMAGE_BITMAP, + pixel_format = IMAGE_BITMAP, bits_per_pixel = 1, bytes_per_pixel = 1, channels = 1, diff --git a/src/raster/layer.cpp b/src/raster/layer.cpp index 5ba45a430..6562058da 100644 --- a/src/raster/layer.cpp +++ b/src/raster/layer.cpp @@ -324,7 +324,7 @@ LayerImage* layer_new_flatten_copy(Sprite* dst_sprite, const Layer* src_layer, // Does this frame have cels to render? if (has_cels(src_layer, frame)) { // Create a new image - Image* image = Image::create(flatLayer->getSprite()->getImgType(), w, h); + Image* image = Image::create(flatLayer->getSprite()->getPixelFormat(), w, h); try { // Create the new cel for the output layer (add the image to stock too). diff --git a/src/raster/mask.cpp b/src/raster/mask.cpp index 635083215..52bc245d9 100644 --- a/src/raster/mask.cpp +++ b/src/raster/mask.cpp @@ -206,7 +206,7 @@ void Mask::byColor(const Image *src, int color, int fuzziness) Image* dst = m_bitmap; - switch (src->imgtype) { + switch (src->getPixelFormat()) { case IMAGE_RGB: { uint32_t* src_address; diff --git a/src/raster/path.cpp b/src/raster/path.cpp index b54dc524d..3dd1f824c 100644 --- a/src/raster/path.cpp +++ b/src/raster/path.cpp @@ -330,7 +330,7 @@ static void art_image_svp_aa (const ArtSVP *svp, { ArtBitmapSVPData data; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: data.shift = 2; diff --git a/src/undoers/set_sprite_imgtype.h b/src/raster/pixel_format.h similarity index 55% rename from src/undoers/set_sprite_imgtype.h rename to src/raster/pixel_format.h index 530100a8b..8b3df4b7d 100644 --- a/src/undoers/set_sprite_imgtype.h +++ b/src/raster/pixel_format.h @@ -1,45 +1,29 @@ -/* 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 UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED -#define UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED - -#include "undo/object_id.h" -#include "undoers/undoer_base.h" - -class Sprite; - -namespace undoers { - -class SetSpriteImgType : public UndoerBase -{ -public: - SetSpriteImgType(undo::ObjectsContainer* objects, Sprite* sprite); - - void dispose() OVERRIDE; - int getMemSize() const OVERRIDE { return sizeof(*this); } - void revert(undo::ObjectsContainer* objects, undo::UndoersCollector* redoers) OVERRIDE; - -private: - undo::ObjectId m_spriteId; - uint32_t m_imgtype; -}; - -} // namespace undoers - -#endif // UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED +/* 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_PIXEL_FORMAT_H_INCLUDED +#define RASTER_PIXEL_FORMAT_H_INCLUDED + +enum PixelFormat { + IMAGE_RGB, + IMAGE_GRAYSCALE, + IMAGE_INDEXED, + IMAGE_BITMAP +}; + +#endif diff --git a/src/raster/quantization.cpp b/src/raster/quantization.cpp index eb1414020..6e550791f 100644 --- a/src/raster/quantization.cpp +++ b/src/raster/quantization.cpp @@ -55,7 +55,7 @@ Palette* quantization::create_palette_from_rgb(const Sprite* sprite) false); // forWrite=false, read only // Add a flat image with the current sprite's frame rendered - flat_image = Image::create(sprite->getImgType(), sprite->getWidth(), sprite->getHeight()); + flat_image = Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()); image_clear(flat_image, 0); sprite->render(flat_image, 0, 0); @@ -75,11 +75,12 @@ Palette* quantization::create_palette_from_rgb(const Sprite* sprite) return palette; } -Image* quantization::convert_imgtype(const Image* image, int imgtype, - DitheringMethod ditheringMethod, - const RgbMap* rgbmap, - const Palette* palette, - bool has_background_layer) +Image* quantization::convert_pixel_format(const Image* image, + PixelFormat pixelFormat, + DitheringMethod ditheringMethod, + const RgbMap* rgbmap, + const Palette* palette, + bool has_background_layer) { uint32_t* rgb_address; uint16_t* gray_address; @@ -89,27 +90,27 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype, Image *new_image; // no convertion - if (image->imgtype == imgtype) + if (image->getPixelFormat() == pixelFormat) return NULL; // RGB -> Indexed with ordered dithering - else if (image->imgtype == IMAGE_RGB && - imgtype == IMAGE_INDEXED && + else if (image->getPixelFormat() == IMAGE_RGB && + pixelFormat == IMAGE_INDEXED && ditheringMethod == DITHERING_ORDERED) { return ordered_dithering(image, 0, 0, rgbmap, palette); } - new_image = Image::create(imgtype, image->w, image->h); + new_image = Image::create(pixelFormat, image->w, image->h); if (!new_image) return NULL; size = image->w*image->h; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: rgb_address = (uint32_t*)image->dat; - switch (new_image->imgtype) { + switch (new_image->getPixelFormat()) { // RGB -> Grayscale case IMAGE_GRAYSCALE: @@ -149,7 +150,7 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype, case IMAGE_GRAYSCALE: gray_address = (uint16_t*)image->dat; - switch (new_image->imgtype) { + switch (new_image->getPixelFormat()) { // Grayscale -> RGB case IMAGE_RGB: @@ -182,7 +183,7 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype, case IMAGE_INDEXED: idx_address = image->dat; - switch (new_image->imgtype) { + switch (new_image->getPixelFormat()) { // Indexed -> RGB case IMAGE_RGB: diff --git a/src/raster/quantization.h b/src/raster/quantization.h index ee58984ee..fdc1beb57 100644 --- a/src/raster/quantization.h +++ b/src/raster/quantization.h @@ -20,6 +20,7 @@ #define RASTER_QUANTIZATION_H_INCLUDED #include "raster/dithering_method.h" +#include "raster/pixel_format.h" class Image; class Palette; @@ -32,13 +33,14 @@ namespace quantization { // Creates a new palette suitable to quantize the given RGB sprite to Indexed color. Palette* create_palette_from_rgb(const Sprite* sprite); - // Changes the "imgtype" of the image. The dithering method is used - // only when you want to convert from RGB to Indexed. - Image* convert_imgtype(const Image* image, int imgtype, - DitheringMethod ditheringMethod, - const RgbMap* rgbmap, - const Palette* palette, - bool has_background_layer); + // Changes the image pixel format. The dithering method is used only + // when you want to convert from RGB to Indexed. + Image* convert_pixel_format(const Image* image, + PixelFormat pixelFormat, + DitheringMethod ditheringMethod, + const RgbMap* rgbmap, + const Palette* palette, + bool has_background_layer); } diff --git a/src/raster/rotate.cpp b/src/raster/rotate.cpp index b5d014b75..ada17fb12 100644 --- a/src/raster/rotate.cpp +++ b/src/raster/rotate.cpp @@ -57,16 +57,16 @@ void image_scale(Image *dst, Image *src, int x, int y, int w, int h) BLEND_COLOR blender = NULL; int u, v, c; - if (dst->imgtype == IMAGE_RGB) + if (dst->getPixelFormat() == IMAGE_RGB) blender = _rgba_blenders[BLEND_MODE_NORMAL]; - else if (dst->imgtype == IMAGE_GRAYSCALE) + else if (dst->getPixelFormat() == IMAGE_GRAYSCALE) blender = _graya_blenders[BLEND_MODE_NORMAL]; for (v=0; vw*u/w, src->h*v/h); - switch (dst->imgtype) { + switch (dst->getPixelFormat()) { case IMAGE_RGB: case IMAGE_GRAYSCALE: @@ -638,7 +638,7 @@ static void ase_parallelogram_map(Image *bmp, Image *spr, fixed xs[4], fixed ys[ static void ase_parallelogram_map_standard(Image *bmp, Image *sprite, fixed xs[4], fixed ys[4]) { - switch (bmp->imgtype) { + switch (bmp->getPixelFormat()) { case IMAGE_RGB: ase_parallelogram_map(bmp, sprite, xs, ys, false); diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 7c569cdf5..b31a70843 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -33,9 +33,9 @@ static int layer2index(const Layer* layer, const Layer* find_layer, int* index_c ////////////////////////////////////////////////////////////////////// // Constructors/Destructor -Sprite::Sprite(int imgtype, int width, int height, int ncolors) +Sprite::Sprite(PixelFormat format, int width, int height, int ncolors) : GfxObj(GFXOBJ_SPRITE) - , m_imgtype(imgtype) + , m_format(format) , m_width(width) , m_height(height) { @@ -44,14 +44,14 @@ Sprite::Sprite(int imgtype, int width, int height, int ncolors) m_frames = 1; m_frlens.push_back(100); // First frame with 100 msecs of duration m_frame = 0; - m_stock = new Stock(imgtype); + m_stock = new Stock(format); m_folder = new LayerFolder(this); m_layer = NULL; // Generate palette Palette pal(0, ncolors); - switch (imgtype) { + switch (format) { // For colored images case IMAGE_RGB: @@ -103,9 +103,9 @@ Sprite::~Sprite() ////////////////////////////////////////////////////////////////////// // Main properties -void Sprite::setImgType(int imgtype) +void Sprite::setPixelFormat(PixelFormat format) { - m_imgtype = imgtype; + m_format = format; } void Sprite::setSize(int width, int height) @@ -119,7 +119,7 @@ void Sprite::setSize(int width, int height) bool Sprite::needAlpha() const { - switch (m_imgtype) { + switch (m_format) { case IMAGE_RGB: case IMAGE_GRAYSCALE: return (getBackgroundLayer() == NULL); @@ -375,7 +375,7 @@ void Sprite::getCels(CelList& cels) void Sprite::remapImages(int frame_from, int frame_to, const std::vector& mapping) { - ASSERT(m_imgtype == IMAGE_INDEXED); + ASSERT(m_format == IMAGE_INDEXED); ASSERT(mapping.size() == 256); CelList cels; @@ -404,7 +404,7 @@ void Sprite::remapImages(int frame_from, int frame_to, const std::vector= 0) && (y >= 0) && (x < m_width) && (y < m_height)) { - Image* image = Image::create(m_imgtype, 1, 1); - image_clear(image, (m_imgtype == IMAGE_INDEXED ? getTransparentColor(): 0)); + Image* image = Image::create(m_format, 1, 1); + image_clear(image, (m_format == IMAGE_INDEXED ? getTransparentColor(): 0)); render(image, -x, -y); color = image_getpixel(image, 0, 0); image_free(image); diff --git a/src/raster/sprite.h b/src/raster/sprite.h index 5825d2a75..3c38ec9c5 100644 --- a/src/raster/sprite.h +++ b/src/raster/sprite.h @@ -21,6 +21,7 @@ #include "base/disable_copying.h" #include "raster/gfxobj.h" +#include "raster/pixel_format.h" #include @@ -45,14 +46,14 @@ public: //////////////////////////////////////// // Constructors/Destructor - Sprite(int imgtype, int width, int height, int ncolors); + Sprite(PixelFormat format, int width, int height, int ncolors); virtual ~Sprite(); //////////////////////////////////////// // Main properties - int getImgType() const { return m_imgtype; } - void setImgType(int imgtype); + PixelFormat getPixelFormat() const { return m_format; } + void setPixelFormat(PixelFormat format); int getWidth() const { return m_width; } int getHeight() const { return m_height; } @@ -140,7 +141,7 @@ public: private: Sprite* m_self; // pointer to the Sprite - int m_imgtype; // image type + 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 diff --git a/src/raster/stock.cpp b/src/raster/stock.cpp index 125e20c4f..7aca80136 100644 --- a/src/raster/stock.cpp +++ b/src/raster/stock.cpp @@ -23,20 +23,18 @@ #include "raster/image.h" #include "raster/stock.h" -Stock::Stock(int imgtype) +Stock::Stock(PixelFormat format) : GfxObj(GFXOBJ_STOCK) + , m_format(format) { - m_imgtype = imgtype; - // Image with index=0 is always NULL. m_image.push_back(NULL); } Stock::Stock(const Stock& stock) : GfxObj(stock) + , m_format(stock.getPixelFormat()) { - m_imgtype = stock.getImgType(); - try { for (int i=0; i class Image; @@ -29,12 +30,12 @@ typedef std::vector ImagesList; class Stock : public GfxObj { public: - Stock(int imgtype); + Stock(PixelFormat format); Stock(const Stock& stock); virtual ~Stock(); - int getImgType() const; - void setImgType(int imgtype); + PixelFormat getPixelFormat() const; + void setPixelFormat(PixelFormat format); // Returns the number of image in the stock. int size() const { @@ -63,7 +64,7 @@ public: void replaceImage(int index, Image* image); //private: TODO uncomment this line - int m_imgtype; // Type of images (all images in the stock must be of this type). + PixelFormat m_format; // Type of images (all images in the stock must be of this type). ImagesList m_image; // The images-array where the images are. }; diff --git a/src/tools/inks.h b/src/tools/inks.h index 920ebb671..b114f18f1 100644 --- a/src/tools/inks.h +++ b/src/tools/inks.h @@ -65,8 +65,8 @@ public: } m_proc = loop->getOpacity() == 255 ? - ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getImgType(), 2)]: - ink_processing[INK_TRANSPARENT][MID(0, loop->getSprite()->getImgType(), 2)]; + ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getPixelFormat(), 2)]: + ink_processing[INK_TRANSPARENT][MID(0, loop->getSprite()->getPixelFormat(), 2)]; } void inkHline(int x1, int y, int x2, ToolLoop* loop) @@ -158,7 +158,7 @@ public: switch (m_type) { case Eraser: - m_proc = ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getImgType(), 2)]; + m_proc = ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getPixelFormat(), 2)]; // TODO app_get_color_to_clear_layer should receive the context as parameter loop->setPrimaryColor(app_get_color_to_clear_layer(loop->getLayer())); @@ -166,7 +166,7 @@ public: break; case ReplaceFgWithBg: - m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)]; + m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getPixelFormat(), 2)]; loop->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getFgColor(), loop->getLayer())); @@ -175,7 +175,7 @@ public: break; case ReplaceBgWithFg: - m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getImgType(), 2)]; + m_proc = ink_processing[INK_REPLACE][MID(0, loop->getSprite()->getPixelFormat(), 2)]; loop->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getBgColor(), loop->getLayer())); @@ -202,7 +202,7 @@ public: void prepareInk(ToolLoop* loop) { - m_proc = ink_processing[INK_BLUR][MID(0, loop->getSprite()->getImgType(), 2)]; + m_proc = ink_processing[INK_BLUR][MID(0, loop->getSprite()->getPixelFormat(), 2)]; } void inkHline(int x1, int y, int x2, ToolLoop* loop) @@ -222,7 +222,7 @@ public: void prepareInk(ToolLoop* loop) { - m_proc = ink_processing[INK_JUMBLE][MID(0, loop->getSprite()->getImgType(), 2)]; + m_proc = ink_processing[INK_JUMBLE][MID(0, loop->getSprite()->getPixelFormat(), 2)]; } void inkHline(int x1, int y, int x2, ToolLoop* loop) diff --git a/src/ui_context.cpp b/src/ui_context.cpp index 0734a5d83..50ec76da6 100644 --- a/src/ui_context.cpp +++ b/src/ui_context.cpp @@ -83,7 +83,7 @@ void UIContext::onSetActiveDocument(Document* document) app_get_tabsbar()->selectTab(document); // Change the image-type of color bar. - app_get_colorbar()->setImgType(app_get_current_image_type()); + app_get_colorbar()->setPixelFormat(app_get_current_pixel_format()); // Change the main frame title. base::string defaultTitle = PACKAGE " v" VERSION; diff --git a/src/undo_transaction.cpp b/src/undo_transaction.cpp index 38ce0a78b..adedfe4d6 100644 --- a/src/undo_transaction.cpp +++ b/src/undo_transaction.cpp @@ -56,9 +56,9 @@ #include "undoers/set_layer_name.h" #include "undoers/set_mask.h" #include "undoers/set_mask_position.h" -#include "undoers/set_sprite_imgtype.h" +#include "undoers/set_sprite_pixel_format.h" #include "undoers/set_sprite_size.h" -#include "undoers/set_stock_imgtype.h" +#include "undoers/set_stock_pixel_format.h" #include "undoers/set_total_frames.h" UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification) @@ -210,7 +210,7 @@ void UndoTransaction::autocropSprite(int bgcolor) x1 = y1 = INT_MAX; x2 = y2 = INT_MIN; - Image* image = Image::create(m_sprite->getImgType(), + Image* image = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); @@ -239,20 +239,20 @@ void UndoTransaction::autocropSprite(int bgcolor) cropSprite(gfx::Rect(x1, y1, x2-x1+1, y2-y1+1), bgcolor); } -void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_method) +void UndoTransaction::setPixelFormat(PixelFormat newFormat, DitheringMethod dithering_method) { Image *old_image; Image *new_image; int c; - if (m_sprite->getImgType() == new_imgtype) + if (m_sprite->getPixelFormat() == newFormat) return; - // Change imgtype of the stock of images. + // Change pixel format of the stock of images. if (isEnabled()) - m_undoHistory->pushUndoer(new undoers::SetStockImgType(m_undoHistory->getObjects(), m_sprite->getStock())); + m_undoHistory->pushUndoer(new undoers::SetStockPixelFormat(m_undoHistory->getObjects(), m_sprite->getStock())); - m_sprite->getStock()->setImgType(new_imgtype); + m_sprite->getStock()->setPixelFormat(newFormat); // Use the rgbmap for the specified sprite const RgbMap* rgbmap = m_sprite->getRgbMap(); @@ -262,25 +262,25 @@ void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_meth if (!old_image) continue; - new_image = quantization::convert_imgtype(old_image, new_imgtype, dithering_method, rgbmap, - // TODO check this out - m_sprite->getCurrentPalette(), - m_sprite->getBackgroundLayer() != NULL); + new_image = quantization::convert_pixel_format(old_image, newFormat, dithering_method, rgbmap, + // TODO check this out + m_sprite->getCurrentPalette(), + m_sprite->getBackgroundLayer() != NULL); this->replaceStockImage(c, new_image); } - // Change sprite's "imgtype" field. + // Change sprite's pixel format. if (isEnabled()) - m_undoHistory->pushUndoer(new undoers::SetSpriteImgType(m_undoHistory->getObjects(), m_sprite)); + m_undoHistory->pushUndoer(new undoers::SetSpritePixelFormat(m_undoHistory->getObjects(), m_sprite)); - m_sprite->setImgType(new_imgtype); + m_sprite->setPixelFormat(newFormat); // Regenerate extras m_document->destroyExtraCel(); // change "sprite.palette" - if (new_imgtype == IMAGE_GRAYSCALE) { + if (newFormat == IMAGE_GRAYSCALE) { if (isEnabled()) { // Save all palettes PalettesList palettes = m_sprite->getPalettes(); @@ -472,7 +472,7 @@ void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor) // create a temporary image to draw each frame of the new // `Background' layer - UniquePtr bg_image_wrap(Image::create(m_sprite->getImgType(), + UniquePtr bg_image_wrap(Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight())); Image* bg_image = bg_image_wrap.get(); @@ -517,7 +517,7 @@ void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor) for (int frame=0; framegetTotalFrames(); frame++) { Cel* cel = layer->getCel(frame); if (!cel) { - Image* cel_image = Image::create(m_sprite->getImgType(), m_sprite->getWidth(), m_sprite->getHeight()); + Image* cel_image = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); image_clear(cel_image, bgcolor); // Add the new image in the stock @@ -558,7 +558,7 @@ void UndoTransaction::flattenLayers(int bgcolor) int frame; // create a temporary image - UniquePtr image_wrap(Image::create(m_sprite->getImgType(), + UniquePtr image_wrap(Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight())); Image* image = image_wrap.get(); diff --git a/src/undo_transaction.h b/src/undo_transaction.h index 50b3de3e3..8145a8c58 100644 --- a/src/undo_transaction.h +++ b/src/undo_transaction.h @@ -21,6 +21,7 @@ #include "gfx/rect.h" #include "raster/dithering_method.h" +#include "raster/pixel_format.h" #include "undo/modification.h" class Cel; @@ -78,7 +79,7 @@ public: void setSpriteSize(int w, int h); void cropSprite(const gfx::Rect& bounds, int bgcolor); void autocropSprite(int bgcolor); - void setImgType(int new_imgtype, DitheringMethod dithering_method); + void setPixelFormat(PixelFormat newFormat, DitheringMethod dithering_method); // for images in stock int addImageInStock(Image* image); diff --git a/src/undoers/flip_image.cpp b/src/undoers/flip_image.cpp index 3a671f271..44c362e65 100644 --- a/src/undoers/flip_image.cpp +++ b/src/undoers/flip_image.cpp @@ -31,7 +31,7 @@ using namespace undoers; FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, int flipFlags) : m_imageId(objects->addObject(image)) - , m_imgtype(image->imgtype) + , m_format(image->getPixelFormat()) , m_x(x), m_y(y), m_w(w), m_h(h) , m_flipFlags(flipFlags) { @@ -48,7 +48,7 @@ void FlipImage::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Image* image = objects->getObjectT(m_imageId); - if (image->imgtype != m_imgtype) + if (image->getPixelFormat() != m_format) throw UndoException("Image type does not match"); redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipFlags)); diff --git a/src/undoers/flip_image.h b/src/undoers/flip_image.h index 4a6e5d684..1d69799b8 100644 --- a/src/undoers/flip_image.h +++ b/src/undoers/flip_image.h @@ -39,7 +39,7 @@ public: private: undo::ObjectId m_imageId; - uint8_t m_imgtype; + uint8_t m_format; uint16_t m_x, m_y, m_w, m_h; uint8_t m_flipFlags; }; diff --git a/src/undoers/image_area.cpp b/src/undoers/image_area.cpp index 09af51685..aedade1d9 100644 --- a/src/undoers/image_area.cpp +++ b/src/undoers/image_area.cpp @@ -30,7 +30,7 @@ using namespace undoers; ImageArea::ImageArea(ObjectsContainer* objects, Image* image, int x, int y, int w, int h) : m_imageId(objects->addObject(image)) - , m_imgtype(image->imgtype) + , m_format(image->getPixelFormat()) , m_x(x), m_y(y), m_w(w), m_h(h) , m_lineSize(image_line_size(image, w)) , m_data(m_lineSize * h) @@ -51,7 +51,7 @@ void ImageArea::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Image* image = objects->getObjectT(m_imageId); - if (image->imgtype != m_imgtype) + if (image->getPixelFormat() != m_format) throw UndoException("Image type does not match"); // Backup the current image portion diff --git a/src/undoers/image_area.h b/src/undoers/image_area.h index 99d7af445..37b502313 100644 --- a/src/undoers/image_area.h +++ b/src/undoers/image_area.h @@ -39,7 +39,7 @@ public: private: undo::ObjectId m_imageId; - uint8_t m_imgtype; + uint8_t m_format; uint16_t m_x, m_y, m_w, m_h; uint32_t m_lineSize; std::vector m_data; diff --git a/src/undoers/set_sprite_imgtype.cpp b/src/undoers/set_sprite_pixel_format.cpp similarity index 69% rename from src/undoers/set_sprite_imgtype.cpp rename to src/undoers/set_sprite_pixel_format.cpp index 19cdc8b06..df5c6170f 100644 --- a/src/undoers/set_sprite_imgtype.cpp +++ b/src/undoers/set_sprite_pixel_format.cpp @@ -18,7 +18,7 @@ #include "config.h" -#include "undoers/set_sprite_imgtype.h" +#include "undoers/set_sprite_pixel_format.h" #include "raster/sprite.h" #include "undo/objects_container.h" @@ -27,23 +27,23 @@ using namespace undo; using namespace undoers; -SetSpriteImgType::SetSpriteImgType(ObjectsContainer* objects, Sprite* sprite) +SetSpritePixelFormat::SetSpritePixelFormat(ObjectsContainer* objects, Sprite* sprite) : m_spriteId(objects->addObject(sprite)) - , m_imgtype(sprite->getImgType()) + , m_format(sprite->getPixelFormat()) { } -void SetSpriteImgType::dispose() +void SetSpritePixelFormat::dispose() { delete this; } -void SetSpriteImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers) +void SetSpritePixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Sprite* sprite = objects->getObjectT(m_spriteId); - // Push another SetSpriteImgType as redoer - redoers->pushUndoer(new SetSpriteImgType(objects, sprite)); + // Push another SetSpritePixelFormat as redoer + redoers->pushUndoer(new SetSpritePixelFormat(objects, sprite)); - sprite->setImgType(m_imgtype); + sprite->setPixelFormat(static_cast(m_format)); } diff --git a/src/undoers/set_imgtype.h b/src/undoers/set_sprite_pixel_format.h similarity index 79% rename from src/undoers/set_imgtype.h rename to src/undoers/set_sprite_pixel_format.h index 982183410..a5ae589ad 100644 --- a/src/undoers/set_imgtype.h +++ b/src/undoers/set_sprite_pixel_format.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UNDOERS_SET_IMGTYPE_H_INCLUDED -#define UNDOERS_SET_IMGTYPE_H_INCLUDED +#ifndef UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED +#define UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED #include "undo/object_id.h" #include "undoers/undoer_base.h" @@ -26,10 +26,10 @@ class Sprite; namespace undoers { -class SetImgType : public UndoerBase +class SetSpritePixelFormat : public UndoerBase { public: - SetImgType(undo::ObjectsContainer* objects, Sprite* sprite); + SetSpritePixelFormat(undo::ObjectsContainer* objects, Sprite* sprite); void dispose() OVERRIDE; int getMemSize() const OVERRIDE { return sizeof(*this); } @@ -37,9 +37,9 @@ public: private: undo::ObjectId m_spriteId; - uint32_t m_imgtype; + uint32_t m_format; }; } // namespace undoers -#endif // UNDOERS_SET_IMGTYPE_H_INCLUDED +#endif // UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED diff --git a/src/undoers/set_stock_imgtype.cpp b/src/undoers/set_stock_pixel_format.cpp similarity index 69% rename from src/undoers/set_stock_imgtype.cpp rename to src/undoers/set_stock_pixel_format.cpp index 3eae9097b..1428b2807 100644 --- a/src/undoers/set_stock_imgtype.cpp +++ b/src/undoers/set_stock_pixel_format.cpp @@ -18,7 +18,7 @@ #include "config.h" -#include "undoers/set_stock_imgtype.h" +#include "undoers/set_stock_pixel_format.h" #include "raster/stock.h" #include "undo/objects_container.h" @@ -27,23 +27,23 @@ using namespace undo; using namespace undoers; -SetStockImgType::SetStockImgType(ObjectsContainer* objects, Stock* stock) +SetStockPixelFormat::SetStockPixelFormat(ObjectsContainer* objects, Stock* stock) : m_stockId(objects->addObject(stock)) - , m_imgtype(stock->getImgType()) + , m_format(stock->getPixelFormat()) { } -void SetStockImgType::dispose() +void SetStockPixelFormat::dispose() { delete this; } -void SetStockImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers) +void SetStockPixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers) { Stock* stock = objects->getObjectT(m_stockId); - // Push another SetStockImgType as redoer - redoers->pushUndoer(new SetStockImgType(objects, stock)); + // Push another SetStockPixelFormat as redoer + redoers->pushUndoer(new SetStockPixelFormat(objects, stock)); - stock->setImgType(m_imgtype); + stock->setPixelFormat(static_cast(m_format)); } diff --git a/src/undoers/set_stock_imgtype.h b/src/undoers/set_stock_pixel_format.h similarity index 79% rename from src/undoers/set_stock_imgtype.h rename to src/undoers/set_stock_pixel_format.h index c692277c6..5d12efa0f 100644 --- a/src/undoers/set_stock_imgtype.h +++ b/src/undoers/set_stock_pixel_format.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED -#define UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED +#ifndef UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED +#define UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED #include "undo/object_id.h" #include "undoers/undoer_base.h" @@ -26,10 +26,10 @@ class Stock; namespace undoers { -class SetStockImgType : public UndoerBase +class SetStockPixelFormat : public UndoerBase { public: - SetStockImgType(undo::ObjectsContainer* objects, Stock* stock); + SetStockPixelFormat(undo::ObjectsContainer* objects, Stock* stock); void dispose() OVERRIDE; int getMemSize() const OVERRIDE { return sizeof(*this); } @@ -37,9 +37,9 @@ public: private: undo::ObjectId m_stockId; - uint32_t m_imgtype; + uint32_t m_format; }; } // namespace undoers -#endif // UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED +#endif // UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED diff --git a/src/util/clipboard.cpp b/src/util/clipboard.cpp index 1912ae0db..f0c95a8d4 100644 --- a/src/util/clipboard.cpp +++ b/src/util/clipboard.cpp @@ -186,13 +186,14 @@ void clipboard::paste() // Source image (clipboard or a converted copy to the destination 'imgtype') Image* src_image; - if (clipboard_image->imgtype == sprite->getImgType()) + if (clipboard_image->getPixelFormat() == sprite->getPixelFormat()) src_image = clipboard_image; else { RgbMap* rgbmap = sprite->getRgbMap(); - src_image = quantization::convert_imgtype(clipboard_image, sprite->getImgType(), DITHERING_NONE, - rgbmap, sprite->getPalette(sprite->getCurrentFrame()), - false); + src_image = quantization::convert_pixel_format(clipboard_image, + sprite->getPixelFormat(), DITHERING_NONE, + rgbmap, sprite->getPalette(sprite->getCurrentFrame()), + false); } // Change to MovingPixelsState diff --git a/src/util/clipboard_win32.h b/src/util/clipboard_win32.h index d90b57269..fac0e7b96 100644 --- a/src/util/clipboard_win32.h +++ b/src/util/clipboard_win32.h @@ -64,7 +64,7 @@ static void set_win32_clipboard_bitmap(Image* image, Palette* palette) int color_depth = 0; int palette_entries = 0; - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: scanline = sizeof(uint32_t) * image->w; color_depth = 32; @@ -107,7 +107,7 @@ static void set_win32_clipboard_bitmap(Image* image, Palette* palette) bi->bV5ClrUsed = palette_entries == 256 ? 0: palette_entries; // write pixels - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: { uint32_t* dst = (uint32_t*)(((uint8_t*)bi)+bi->bV5Size); uint32_t c; diff --git a/src/util/expand_cel_canvas.cpp b/src/util/expand_cel_canvas.cpp index 1d169bb21..c1c732f87 100644 --- a/src/util/expand_cel_canvas.cpp +++ b/src/util/expand_cel_canvas.cpp @@ -55,7 +55,7 @@ ExpandCelCanvas::ExpandCelCanvas(Document* document, Sprite* sprite, Layer* laye // If there is no Cel if (m_cel == NULL) { // Create the image - m_celImage = Image::create(m_sprite->getImgType(), m_sprite->getWidth(), m_sprite->getHeight()); + m_celImage = Image::create(m_sprite->getPixelFormat(), m_sprite->getWidth(), m_sprite->getHeight()); image_clear(m_celImage, sprite->getTransparentColor()); // create the cel diff --git a/src/util/misc.cpp b/src/util/misc.cpp index 65c42d6bb..2d5b94a88 100644 --- a/src/util/misc.cpp +++ b/src/util/misc.cpp @@ -53,7 +53,7 @@ Image* NewImageFromMask(const Document* srcDocument) ASSERT(srcBitmap); ASSERT(src); - dst = Image::create(srcSprite->getImgType(), srcBounds.w, srcBounds.h); + dst = Image::create(srcSprite->getPixelFormat(), srcBounds.w, srcBounds.h); if (!dst) return NULL; diff --git a/src/util/msk_file.cpp b/src/util/msk_file.cpp index b0bd94ba0..15582ead5 100644 --- a/src/util/msk_file.cpp +++ b/src/util/msk_file.cpp @@ -54,7 +54,7 @@ Mask *load_msk_file(const char *filename) /* just load an Animator Pro PIC file */ image = load_pic_file(filename, &x, &y, NULL); - if ((!image) || (image->imgtype != IMAGE_BITMAP)) { + if ((!image) || (image->getPixelFormat() != IMAGE_BITMAP)) { if (image) image_free(image); } diff --git a/src/util/pic_file.cpp b/src/util/pic_file.cpp index 1cb74cdc5..f9be1eb0d 100644 --- a/src/util/pic_file.cpp +++ b/src/util/pic_file.cpp @@ -179,9 +179,9 @@ int save_pic_file(const char *filename, int x, int y, int c, u, v, bpp, size, byte; PACKFILE* f; - if (image->imgtype == IMAGE_INDEXED) + if (image->getPixelFormat() == IMAGE_INDEXED) bpp = 8; - else if (image->imgtype == IMAGE_BITMAP) + else if (image->getPixelFormat() == IMAGE_BITMAP) bpp = 1; else return -1; diff --git a/src/util/render.cpp b/src/util/render.cpp index 60b07a1ac..ba68b574f 100644 --- a/src/util/render.cpp +++ b/src/util/render.cpp @@ -379,7 +379,7 @@ Image* RenderEngine::renderSprite(const Document* document, uint32_t bg_color = 0; Image *image; - switch (sprite->getImgType()) { + switch (sprite->getPixelFormat()) { case IMAGE_RGB: zoomed_func = merge_zoomed_image; @@ -461,8 +461,8 @@ void RenderEngine::renderCheckedBackground(Image* image, int x, y, u, v; int tile_w = 16; int tile_h = 16; - int c1 = color_utils::color_for_image(checked_bg_color1, image->imgtype); - int c2 = color_utils::color_for_image(checked_bg_color2, image->imgtype); + int c1 = color_utils::color_for_image(checked_bg_color1, image->getPixelFormat()); + int c2 = color_utils::color_for_image(checked_bg_color2, image->getPixelFormat()); switch (checked_bg_type) { @@ -524,9 +524,9 @@ void RenderEngine::renderImage(Image* rgb_image, Image* src_image, const Palette { void (*zoomed_func)(Image*, const Image*, const Palette*, int, int, int, int, int); - ASSERT(rgb_image->imgtype == IMAGE_RGB && "renderImage accepts RGB destination images only"); + ASSERT(rgb_image->getPixelFormat() == IMAGE_RGB && "renderImage accepts RGB destination images only"); - switch (src_image->imgtype) { + switch (src_image->getPixelFormat()) { case IMAGE_RGB: zoomed_func = merge_zoomed_image; diff --git a/src/util/thmbnail.cpp b/src/util/thmbnail.cpp index a0b7af509..e2d7b1a3c 100644 --- a/src/util/thmbnail.cpp +++ b/src/util/thmbnail.cpp @@ -131,7 +131,7 @@ static void thumbnail_render(BITMAP* bmp, const Image* image, bool has_alpha, co rectgrid(bmp, 0, 0, bmp->w-1, bmp->h-1, bmp->w/4, bmp->h/4); - switch (image->imgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: for (y=0; yimgtype) { + switch (image->getPixelFormat()) { case IMAGE_RGB: for (y=0; ymouse.y; editor->screenToEditor(x, y, &x, &y); imgcolor = sprite->getPixel(x, y); - color = Color::fromImage(sprite->getImgType(), imgcolor); + color = Color::fromImage(sprite->getPixelFormat(), imgcolor); } } } @@ -208,12 +208,12 @@ void ColorButton::onPaint(PaintEvent& ev) // TODO use "ev.getGraphics()" this->getBounds(), true, true, true, true, true, true, true, true, - this->m_imgtype, + m_pixelFormat, color, this->hasMouseOver(), false); // Draw text - std::string str = m_color.toFormalString(this->m_imgtype, false); + std::string str = m_color.toFormalString(m_pixelFormat, false); setTextQuiet(str.c_str()); jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); diff --git a/src/widgets/color_button.h b/src/widgets/color_button.h index 5e5dbff31..df41c8faf 100644 --- a/src/widgets/color_button.h +++ b/src/widgets/color_button.h @@ -23,17 +23,18 @@ #include "base/compiler_specific.h" #include "base/signal.h" #include "gui/button.h" +#include "raster/pixel_format.h" class ColorSelector; class ColorButton : public ButtonBase { public: - ColorButton(const Color& color, int imgtype); + ColorButton(const Color& color, PixelFormat pixelFormat); ~ColorButton(); - int getImgType() const; - void setImgType(int imgtype); + PixelFormat getPixelFormat() const; + void setPixelFormat(PixelFormat pixelFormat); Color getColor() const; void setColor(const Color& color); @@ -53,7 +54,7 @@ private: void onFrameColorChange(const Color& color); Color m_color; - int m_imgtype; + PixelFormat m_pixelFormat; ColorSelector* m_frame; }; diff --git a/src/widgets/editor/cursor.cpp b/src/widgets/editor/cursor.cpp index 0dfe56cf9..0c1b3cb58 100644 --- a/src/widgets/editor/cursor.cpp +++ b/src/widgets/editor/cursor.cpp @@ -296,7 +296,7 @@ void Editor::editor_draw_cursor(int x, int y, bool refresh) // In 'indexed' images, if the current color is 0, we have to use // a different mask color (different from 0) to draw the extra layer - if (m_sprite->getImgType() == IMAGE_INDEXED && pen_color == 0) { + if (m_sprite->getPixelFormat() == IMAGE_INDEXED && pen_color == 0) { new_mask_color = 1; } else { @@ -684,5 +684,5 @@ static int get_pen_color(Sprite *sprite) if (sprite->getCurrentLayer() != NULL) return color_utils::color_for_layer(c, sprite->getCurrentLayer()); else - return color_utils::color_for_image(c, sprite->getImgType()); + return color_utils::color_for_image(c, sprite->getPixelFormat()); } diff --git a/src/widgets/editor/moving_pixels_state.cpp b/src/widgets/editor/moving_pixels_state.cpp index 4cfc6914d..f576db5a4 100644 --- a/src/widgets/editor/moving_pixels_state.cpp +++ b/src/widgets/editor/moving_pixels_state.cpp @@ -397,8 +397,8 @@ void MovingPixelsState::setTransparentColor(const Color& color) Sprite* sprite = current_editor->getSprite(); ASSERT(sprite != NULL); - int imgtype = sprite->getImgType(); - m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, imgtype)); + PixelFormat format = sprite->getPixelFormat(); + m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, format)); } void MovingPixelsState::dropPixels(Editor* editor) diff --git a/src/widgets/editor/pixels_movement.cpp b/src/widgets/editor/pixels_movement.cpp index 14e3f8738..1807a3fa9 100644 --- a/src/widgets/editor/pixels_movement.cpp +++ b/src/widgets/editor/pixels_movement.cpp @@ -366,7 +366,7 @@ Image* PixelsMovement::getDraggedImageCopy(gfx::Point& origin) int width = rightBottom.x - leftTop.x; int height = rightBottom.y - leftTop.y; - UniquePtr image(Image::create(m_sprite->getImgType(), width, height)); + UniquePtr image(Image::create(m_sprite->getPixelFormat(), width, height)); image_clear(image, image->mask_color); image_parallelogram(image, m_originalImage, corners.leftTop().x-leftTop.x, corners.leftTop().y-leftTop.y, diff --git a/src/widgets/editor/standby_state.cpp b/src/widgets/editor/standby_state.cpp index 8bd4b99a9..f5d93b085 100644 --- a/src/widgets/editor/standby_state.cpp +++ b/src/widgets/editor/standby_state.cpp @@ -450,12 +450,12 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) } // For eye-dropper else if (current_tool->getInk(0)->isEyedropper()) { - int imgtype = sprite->getImgType(); + PixelFormat format = sprite->getPixelFormat(); uint32_t pixel = sprite->getPixel(x, y); - Color color = Color::fromImage(imgtype, pixel); + Color color = Color::fromImage(format, pixel); int alpha = 255; - switch (imgtype) { + switch (format) { case IMAGE_RGB: alpha = _rgba_geta(pixel); break; case IMAGE_GRAYSCALE: alpha = _graya_geta(pixel); break; } diff --git a/src/widgets/fileview.cpp b/src/widgets/fileview.cpp index 8a98b0ca2..b37d1ee34 100644 --- a/src/widgets/fileview.cpp +++ b/src/widgets/fileview.cpp @@ -794,7 +794,7 @@ static void monitor_thumbnail_generation(void *_data) data->palette = new Palette(*sprite->getPalette(0)); // Render the 'sprite' in one plain 'image' - image = Image::create(sprite->getImgType(), sprite->getWidth(), sprite->getHeight()); + image = Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()); sprite->render(image, 0, 0); // Calculate the thumbnail size @@ -808,7 +808,7 @@ static void monitor_thumbnail_generation(void *_data) thumb_h = MID(1, thumb_h, MAX_THUMBNAIL_SIZE); // Stretch the 'image' - data->thumbnail = Image::create(image->imgtype, thumb_w, thumb_h); + data->thumbnail = Image::create(image->getPixelFormat(), thumb_w, thumb_h); image_clear(data->thumbnail, 0); image_scale(data->thumbnail, image, 0, 0, thumb_w, thumb_h); image_free(image); diff --git a/src/widgets/statebar.cpp b/src/widgets/statebar.cpp index dde4421be..f01c62674 100644 --- a/src/widgets/statebar.cpp +++ b/src/widgets/statebar.cpp @@ -516,13 +516,13 @@ bool StatusBar::onProcessMessage(Message* msg) draw_color_button(doublebuffer, Rect(x, rc->y1, 32*jguiscale(), rc->y2-rc->y1), true, true, true, true, true, true, true, true, - app_get_current_image_type(), m_color, + app_get_current_pixel_format(), m_color, false, false); x += (32+4)*jguiscale(); // Draw color description - std::string str = m_color.toFormalString(app_get_current_image_type(), true); + std::string str = m_color.toFormalString(app_get_current_pixel_format(), true); if (m_alpha < 255) { char buf[512]; usprintf(buf, ", Alpha %d", m_alpha); diff --git a/src/xml_widgets.cpp b/src/xml_widgets.cpp index 6c1f212ec..708a3ba92 100644 --- a/src/xml_widgets.cpp +++ b/src/xml_widgets.cpp @@ -330,7 +330,7 @@ static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root) } /* colorpicker */ else if (ustrcmp(elem_name, "colorpicker") == 0) { - widget = new ColorButton(Color::fromMask(), app_get_current_image_type()); + widget = new ColorButton(Color::fromMask(), app_get_current_pixel_format()); } // Was the widget created?