Change "imgtype" int type to PixelFormat enumeration.

This commit is contained in:
David Capello 2012-02-12 23:21:06 -03:00
parent bc32ded8a5
commit 041140f528
94 changed files with 491 additions and 486 deletions

View File

@ -238,17 +238,17 @@
<menu text="&amp;Sprite"> <menu text="&amp;Sprite">
<item command="SpriteProperties" text="&amp;Properties..." /> <item command="SpriteProperties" text="&amp;Properties..." />
<menu text="Color &amp;Mode"> <menu text="Color &amp;Mode">
<item command="ChangeImageType" text="&amp;RGB Color"> <item command="ChangePixelFormat" text="&amp;RGB Color">
<param name="imgtype" value="rgb" /> <param name="format" value="rgb" />
</item> </item>
<item command="ChangeImageType" text="&amp;Grayscale"> <item command="ChangePixelFormat" text="&amp;Grayscale">
<param name="imgtype" value="grayscale" /> <param name="format" value="grayscale" />
</item> </item>
<item command="ChangeImageType" text="&amp;Indexed (No Dithering)"> <item command="ChangePixelFormat" text="&amp;Indexed (No Dithering)">
<param name="imgtype" value="indexed" /> <param name="format" value="indexed" />
</item> </item>
<item command="ChangeImageType" text="Indexed (Ordered &amp;Dither)"> <item command="ChangePixelFormat" text="Indexed (Ordered &amp;Dither)">
<param name="imgtype" value="indexed" /> <param name="format" value="indexed" />
<param name="dithering" value="ordered" /> <param name="dithering" value="ordered" />
</item> </item>
</menu> </menu>

View File

@ -286,9 +286,9 @@ add_library(aseprite-library
undoers/set_mask.cpp undoers/set_mask.cpp
undoers/set_mask_position.cpp undoers/set_mask_position.cpp
undoers/set_palette_colors.cpp undoers/set_palette_colors.cpp
undoers/set_sprite_imgtype.cpp undoers/set_sprite_pixel_format.cpp
undoers/set_sprite_size.cpp undoers/set_sprite_size.cpp
undoers/set_stock_imgtype.cpp undoers/set_stock_pixel_format.cpp
undoers/set_total_frames.cpp undoers/set_total_frames.cpp
util/autocrop.cpp util/autocrop.cpp
util/boundary.cpp util/boundary.cpp

View File

@ -464,14 +464,14 @@ bool app_rebuild_recent_list()
return true; return true;
} }
int app_get_current_image_type() PixelFormat app_get_current_pixel_format()
{ {
Context* context = UIContext::instance(); Context* context = UIContext::instance();
ASSERT(context != NULL); ASSERT(context != NULL);
Document* document = context->getActiveDocument(); Document* document = context->getActiveDocument();
if (document != NULL) if (document != NULL)
return document->getSprite()->getImgType(); return document->getSprite()->getPixelFormat();
else if (screen != NULL && bitmap_color_depth(screen) == 8) else if (screen != NULL && bitmap_color_depth(screen) == 8)
return IMAGE_INDEXED; return IMAGE_INDEXED;
else else

View File

@ -22,6 +22,7 @@
#include "base/signal.h" #include "base/signal.h"
#include "base/string.h" #include "base/string.h"
#include "gui/base.h" #include "gui/base.h"
#include "raster/pixel_format.h"
#include <vector> #include <vector>
@ -96,7 +97,7 @@ void app_update_document_tab(const Document* document);
// Updates the list of recent files. // Updates the list of recent files.
bool app_rebuild_recent_list(); bool app_rebuild_recent_list();
int app_get_current_image_type(); PixelFormat app_get_current_pixel_format();
Frame* app_get_top_window(); Frame* app_get_top_window();
MenuBar* app_get_menubar(); MenuBar* app_get_menubar();

View File

@ -76,11 +76,11 @@ Color Color::fromIndex(int index)
} }
// static // static
Color Color::fromImage(int imgtype, int c) Color Color::fromImage(PixelFormat pixelFormat, int c)
{ {
Color color = Color::fromMask(); Color color = Color::fromMask();
switch (imgtype) { switch (pixelFormat) {
case IMAGE_RGB: case IMAGE_RGB:
if (_rgba_geta(c) > 0) { 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) Color Color::fromImageGetPixel(Image *image, int x, int y)
{ {
if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h)) 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 else
return Color::fromMask(); return Color::fromMask();
} }
@ -186,7 +186,7 @@ std::string Color::toString() const
return result.str(); 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; std::stringstream result;
@ -199,7 +199,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const
break; break;
case Color::RgbType: case Color::RgbType:
if (imgtype == IMAGE_GRAYSCALE) { if (pixelFormat == IMAGE_GRAYSCALE) {
result << "Gray " << getGray(); result << "Gray " << getGray();
} }
else { else {
@ -208,14 +208,14 @@ std::string Color::toFormalString(int imgtype, bool long_format) const
<< m_value.rgb.g << " " << m_value.rgb.g << " "
<< m_value.rgb.b; << m_value.rgb.b;
if (imgtype == IMAGE_INDEXED) if (pixelFormat == IMAGE_INDEXED)
result << " Index " result << " Index "
<< color_utils::color_for_image(*this, imgtype); << color_utils::color_for_image(*this, pixelFormat);
} }
break; break;
case Color::HsvType: case Color::HsvType:
if (imgtype == IMAGE_GRAYSCALE) { if (pixelFormat == IMAGE_GRAYSCALE) {
result << "Gray " << getGray(); result << "Gray " << getGray();
} }
else { else {
@ -224,8 +224,8 @@ std::string Color::toFormalString(int imgtype, bool long_format) const
<< m_value.hsv.s << " " << m_value.hsv.s << " "
<< m_value.hsv.v; << m_value.hsv.v;
if (imgtype == IMAGE_INDEXED) if (pixelFormat == IMAGE_INDEXED)
result << " Index " << color_utils::color_for_image(*this, imgtype); result << " Index " << color_utils::color_for_image(*this, pixelFormat);
} }
break; break;
@ -265,7 +265,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const
break; break;
case Color::RgbType: case Color::RgbType:
if (imgtype == IMAGE_GRAYSCALE) { if (pixelFormat == IMAGE_GRAYSCALE) {
result << "Gry-" << getGray(); result << "Gry-" << getGray();
} }
else { else {
@ -277,7 +277,7 @@ std::string Color::toFormalString(int imgtype, bool long_format) const
break; break;
case Color::HsvType: case Color::HsvType:
if (imgtype == IMAGE_GRAYSCALE) { if (pixelFormat == IMAGE_GRAYSCALE) {
result << "Gry-" << getGray(); result << "Gry-" << getGray();
} }
else { else {

View File

@ -19,6 +19,8 @@
#ifndef APP_COLOR_H_INCLUDED #ifndef APP_COLOR_H_INCLUDED
#define APP_COLOR_H_INCLUDED #define APP_COLOR_H_INCLUDED
#include "raster/pixel_format.h"
#include <string> #include <string>
class Image; class Image;
@ -43,12 +45,12 @@ public:
static Color fromGray(int g); static Color fromGray(int g);
static Color fromIndex(int index); 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 fromImageGetPixel(Image* image, int x, int y);
static Color fromString(const std::string& str); static Color fromString(const std::string& str);
std::string toString() const; 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;
bool operator!=(const Color& other) const { bool operator!=(const Color& other) const {

View File

@ -108,14 +108,14 @@ int color_utils::color_for_allegro(const Color& color, int depth)
return c; 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) if (color.getType() == Color::MaskType)
return 0; return 0;
int c = -1; int c = -1;
switch (imgtype) { switch (format) {
case IMAGE_RGB: case IMAGE_RGB:
c = _rgba(color.getRed(), color.getGreen(), color.getBlue(), 255); c = _rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
break; break;
@ -141,8 +141,8 @@ int color_utils::color_for_layer(const Color& color, Layer* layer)
pixel_color = layer->getSprite()->getTransparentColor(); pixel_color = layer->getSprite()->getTransparentColor();
} }
else { else {
int imgtype = layer->getSprite()->getImgType(); PixelFormat format = layer->getSprite()->getPixelFormat();
pixel_color = color_for_image(color, imgtype); pixel_color = color_for_image(color, format);
} }
return fixup_color_for_layer(layer, pixel_color); 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) int color_utils::fixup_color_for_layer(Layer *layer, int color)
{ {
if (layer->is_background()) if (layer->is_background())
return fixup_color_for_background(layer->getSprite()->getImgType(), color); return fixup_color_for_background(layer->getSprite()->getPixelFormat(), color);
else else
return color; 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: case IMAGE_RGB:
if (_rgba_geta(color) < 255) { if (_rgba_geta(color) < 255) {
return _rgba(_rgba_getr(color), return _rgba(_rgba_getr(color),

View File

@ -20,6 +20,7 @@
#define APP_COLOR_UTILS_H_INCLUDED #define APP_COLOR_UTILS_H_INCLUDED
#include "app/color.h" #include "app/color.h"
#include "raster/pixel_format.h"
class Layer; class Layer;
@ -29,11 +30,11 @@ int blackandwhite(int r, int g, int b);
int blackandwhite_neg(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_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 color_for_layer(const Color& color, Layer* layer);
int fixup_color_for_layer(Layer* layer, int color); 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);
} }

View File

@ -63,8 +63,8 @@ void BackgroundFromLayerCommand::onExecute(Context* context)
// each frame of the layer to be converted as `Background' must be // each frame of the layer to be converted as `Background' must be
// cleared using the selected background color in the color-bar // cleared using the selected background color in the color-bar
int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType()); int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getPixelFormat());
bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor); bgcolor = color_utils::fixup_color_for_background(sprite->getPixelFormat(), bgcolor);
{ {
UndoTransaction undo_transaction(document, "Background from Layer"); UndoTransaction undo_transaction(document, "Background from Layer");

View File

@ -204,8 +204,8 @@ void CanvasSizeCommand::onExecute(Context* context)
{ {
DocumentWriter documentWriter(document); DocumentWriter documentWriter(document);
UndoTransaction undoTransaction(documentWriter, "Canvas Size"); UndoTransaction undoTransaction(documentWriter, "Canvas Size");
int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getImgType()); int bgcolor = color_utils::color_for_image(context->getSettings()->getBgColor(), sprite->getPixelFormat());
bgcolor = color_utils::fixup_color_for_background(sprite->getImgType(), bgcolor); bgcolor = color_utils::fixup_color_for_background(sprite->getPixelFormat(), bgcolor);
undoTransaction.cropSprite(gfx::Rect(x1, y1, x2-x1, y2-y1), bgcolor); undoTransaction.cropSprite(gfx::Rect(x1, y1, x2-x1, y2-y1), bgcolor);
undoTransaction.commit(); undoTransaction.commit();

View File

@ -30,13 +30,13 @@
#include <allegro/unicode.h> #include <allegro/unicode.h>
class ChangeImageTypeCommand : public Command class ChangePixelFormatCommand : public Command
{ {
int m_imgtype; PixelFormat m_format;
DitheringMethod m_dithering; DitheringMethod m_dithering;
public: public:
ChangeImageTypeCommand(); ChangePixelFormatCommand();
Command* clone() const { return new ChangeImageTypeCommand(*this); } Command* clone() const { return new ChangePixelFormatCommand(*this); }
protected: protected:
void onLoadParams(Params* params); void onLoadParams(Params* params);
@ -45,21 +45,21 @@ protected:
void onExecute(Context* context); void onExecute(Context* context);
}; };
ChangeImageTypeCommand::ChangeImageTypeCommand() ChangePixelFormatCommand::ChangePixelFormatCommand()
: Command("ChangeImageType", : Command("ChangePixelFormat",
"Change Image Type", "Change Pixel Format",
CmdUIOnlyFlag) CmdUIOnlyFlag)
{ {
m_imgtype = IMAGE_RGB; m_format = IMAGE_RGB;
m_dithering = DITHERING_NONE; m_dithering = DITHERING_NONE;
} }
void ChangeImageTypeCommand::onLoadParams(Params* params) void ChangePixelFormatCommand::onLoadParams(Params* params)
{ {
std::string imgtype = params->get("imgtype"); std::string format = params->get("format");
if (imgtype == "rgb") m_imgtype = IMAGE_RGB; if (format == "rgb") m_format = IMAGE_RGB;
else if (imgtype == "grayscale") m_imgtype = IMAGE_GRAYSCALE; else if (format == "grayscale") m_format = IMAGE_GRAYSCALE;
else if (imgtype == "indexed") m_imgtype = IMAGE_INDEXED; else if (format == "indexed") m_format = IMAGE_INDEXED;
std::string dithering = params->get("dithering"); std::string dithering = params->get("dithering");
if (dithering == "ordered") if (dithering == "ordered")
@ -68,42 +68,42 @@ void ChangeImageTypeCommand::onLoadParams(Params* params)
m_dithering = DITHERING_NONE; m_dithering = DITHERING_NONE;
} }
bool ChangeImageTypeCommand::onEnabled(Context* context) bool ChangePixelFormatCommand::onEnabled(Context* context)
{ {
ActiveDocumentWriter document(context); ActiveDocumentWriter document(context);
Sprite* sprite(document ? document->getSprite(): 0); Sprite* sprite(document ? document->getSprite(): 0);
if (sprite != NULL && if (sprite != NULL &&
sprite->getImgType() == IMAGE_INDEXED && sprite->getPixelFormat() == IMAGE_INDEXED &&
m_imgtype == IMAGE_INDEXED && m_format == IMAGE_INDEXED &&
m_dithering == DITHERING_ORDERED) m_dithering == DITHERING_ORDERED)
return false; return false;
return sprite != NULL; return sprite != NULL;
} }
bool ChangeImageTypeCommand::onChecked(Context* context) bool ChangePixelFormatCommand::onChecked(Context* context)
{ {
const ActiveDocumentReader document(context); const ActiveDocumentReader document(context);
const Sprite* sprite(document ? document->getSprite(): 0); const Sprite* sprite(document ? document->getSprite(): 0);
if (sprite != NULL && if (sprite != NULL &&
sprite->getImgType() == IMAGE_INDEXED && sprite->getPixelFormat() == IMAGE_INDEXED &&
m_imgtype == IMAGE_INDEXED && m_format == IMAGE_INDEXED &&
m_dithering == DITHERING_ORDERED) m_dithering == DITHERING_ORDERED)
return false; return false;
return return
sprite != NULL && sprite != NULL &&
sprite->getImgType() == m_imgtype; sprite->getPixelFormat() == m_format;
} }
void ChangeImageTypeCommand::onExecute(Context* context) void ChangePixelFormatCommand::onExecute(Context* context)
{ {
ActiveDocumentWriter document(context); ActiveDocumentWriter document(context);
{ {
UndoTransaction undoTransaction(document, "Color Mode Change"); UndoTransaction undoTransaction(document, "Color Mode Change");
undoTransaction.setImgType(m_imgtype, m_dithering); undoTransaction.setPixelFormat(m_format, m_dithering);
undoTransaction.commit(); undoTransaction.commit();
} }
app_refresh_screen(document); app_refresh_screen(document);
@ -112,7 +112,7 @@ void ChangeImageTypeCommand::onExecute(Context* context)
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// CommandFactory // CommandFactory
Command* CommandFactory::createChangeImageTypeCommand() Command* CommandFactory::createChangePixelFormatCommand()
{ {
return new ChangeImageTypeCommand; return new ChangePixelFormatCommand;
} }

View File

@ -66,7 +66,7 @@ void CropSpriteCommand::onExecute(Context* context)
const Mask* mask(document->getMask()); const Mask* mask(document->getMask());
{ {
UndoTransaction undoTransaction(document, "Sprite Crop"); 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.cropSprite(mask->getBounds(), bgcolor);
undoTransaction.commit(); undoTransaction.commit();
@ -107,7 +107,7 @@ void AutocropSpriteCommand::onExecute(Context* context)
ActiveDocumentWriter document(context); ActiveDocumentWriter document(context);
Sprite* sprite(document->getSprite()); 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 undoTransaction(document, "Sprite Autocrop");
undoTransaction.autocropSprite(bgcolor); undoTransaction.autocropSprite(bgcolor);

View File

@ -139,7 +139,7 @@ protected:
int sheet_w = sprite->getWidth()*columns; int sheet_w = sprite->getWidth()*columns;
int sheet_h = sprite->getHeight()*((nframes/columns)+((nframes%columns)>0?1:0)); int sheet_h = sprite->getHeight()*((nframes/columns)+((nframes%columns)>0?1:0));
UniquePtr<Image> resultImage(Image::create(sprite->getImgType(), sheet_w, sheet_h)); UniquePtr<Image> resultImage(Image::create(sprite->getPixelFormat(), sheet_w, sheet_h));
image_clear(resultImage, 0); image_clear(resultImage, 0);
int oldFrame = sprite->getCurrentFrame(); int oldFrame = sprite->getCurrentFrame();

View File

@ -81,7 +81,7 @@ void EyedropperCommand::onExecute(Context* context)
editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y); editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y);
// get the color from the image // get the color from the image
Color color = Color::fromImage(sprite->getImgType(), Color color = Color::fromImage(sprite->getPixelFormat(),
sprite->getPixel(x, y)); sprite->getPixel(x, y));
// TODO replace the color in the "context", not directly from the color-bar // TODO replace the color in the "context", not directly from the color-bar

View File

@ -57,7 +57,7 @@ void FlattenLayersCommand::onExecute(Context* context)
{ {
ActiveDocumentWriter document(context); ActiveDocumentWriter document(context);
Sprite* sprite = document->getSprite(); 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 undoTransaction(document, "Flatten Layers");
undoTransaction.flattenLayers(bgcolor); undoTransaction.flattenLayers(bgcolor);

View File

@ -159,7 +159,7 @@ protected:
// As first step, we cut each tile and add them into "animation" list. // As first step, we cut each tile and add them into "animation" list.
for (int y=m_rect.y; y<sprite->getHeight(); y += m_rect.h) { for (int y=m_rect.y; y<sprite->getHeight(); y += m_rect.h) {
for (int x=m_rect.x; x<sprite->getWidth(); x += m_rect.w) { for (int x=m_rect.x; x<sprite->getWidth(); x += m_rect.w) {
UniquePtr<Image> resultImage(Image::create(sprite->getImgType(), m_rect.w, m_rect.h)); UniquePtr<Image> resultImage(Image::create(sprite->getPixelFormat(), m_rect.w, m_rect.h));
// Clear the image with mask color. // Clear the image with mask color.
image_clear(resultImage, 0); image_clear(resultImage, 0);

View File

@ -69,7 +69,8 @@ NewFileCommand::NewFileCommand()
void NewFileCommand::onExecute(Context* context) void NewFileCommand::onExecute(Context* context)
{ {
JWidget width, height, radio1, radio2, radio3, colors, ok, bg_box; 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]; char buf[1024];
Color bg_table[] = { Color bg_table[] = {
Color::fromMask(), Color::fromMask(),
@ -92,8 +93,11 @@ void NewFileCommand::onExecute(Context* context)
"bg_box", &bg_box, NULL); "bg_box", &bg_box, NULL);
// Default values: Indexed, 320x240, Background color // Default values: Indexed, 320x240, Background color
imgtype = get_config_int("NewSprite", "Type", IMAGE_INDEXED); format = static_cast<PixelFormat>(get_config_int("NewSprite", "Type", IMAGE_INDEXED));
imgtype = MID(IMAGE_RGB, imgtype, 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); w = get_config_int("NewSprite", "Width", 320);
h = get_config_int("NewSprite", "Height", 240); h = get_config_int("NewSprite", "Height", 240);
bg = get_config_int("NewSprite", "Background", 4); // Default = Background color 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)); colors->setTextf("%d", MID(2, ncolors, 256));
// Select image-type // Select image-type
switch (imgtype) { switch (format) {
case IMAGE_RGB: radio1->setSelected(true); break; case IMAGE_RGB: radio1->setSelected(true); break;
case IMAGE_GRAYSCALE: radio2->setSelected(true); break; case IMAGE_GRAYSCALE: radio2->setSelected(true); break;
case IMAGE_INDEXED: radio3->setSelected(true); break; case IMAGE_INDEXED: radio3->setSelected(true); break;
@ -128,9 +132,9 @@ void NewFileCommand::onExecute(Context* context)
bool ok = false; bool ok = false;
// Get the options // Get the options
if (radio1->isSelected()) imgtype = IMAGE_RGB; if (radio1->isSelected()) format = IMAGE_RGB;
else if (radio2->isSelected()) imgtype = IMAGE_GRAYSCALE; else if (radio2->isSelected()) format = IMAGE_GRAYSCALE;
else if (radio3->isSelected()) imgtype = IMAGE_INDEXED; else if (radio3->isSelected()) format = IMAGE_INDEXED;
w = width->getTextInt(); w = width->getTextInt();
h = height->getTextInt(); h = height->getTextInt();
@ -151,19 +155,19 @@ void NewFileCommand::onExecute(Context* context)
if (ok) { if (ok) {
// Save the configuration // 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", "Width", w);
set_config_int("NewSprite", "Height", h); set_config_int("NewSprite", "Height", h);
set_config_int("NewSprite", "Background", bg); set_config_int("NewSprite", "Background", bg);
// Create the new sprite // 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(w >= 1 && w <= 9999);
ASSERT(h >= 1 && h <= 9999); ASSERT(h >= 1 && h <= 9999);
UniquePtr<Document> document( UniquePtr<Document> document(
Document::createBasicDocument(imgtype, w, h, Document::createBasicDocument(format, w, h,
(imgtype == IMAGE_INDEXED ? ncolors: 256))); (format == IMAGE_INDEXED ? ncolors: 256)));
Sprite* sprite(document->getSprite()); Sprite* sprite(document->getSprite());
get_default_palette()->copyColorsTo(sprite->getCurrentPalette()); get_default_palette()->copyColorsTo(sprite->getCurrentPalette());
@ -179,7 +183,7 @@ void NewFileCommand::onExecute(Context* context)
ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image()); ASSERT(sprite->getCurrentLayer() && sprite->getCurrentLayer()->is_image());
static_cast<LayerImage*>(sprite->getCurrentLayer())->configureAsBackground(); static_cast<LayerImage*>(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 // Show the sprite to the user

View File

@ -578,7 +578,7 @@ void PaletteEntryEditor::onQuantizeCommand(Event& ev)
return; return;
} }
if (sprite->getImgType() != IMAGE_RGB) { if (sprite->getPixelFormat() != IMAGE_RGB) {
Alert::show("Error<<You can use this command only for RGB sprites||&OK"); Alert::show("Error<<You can use this command only for RGB sprites||&OK");
return; return;
} }

View File

@ -18,13 +18,6 @@
#include "config.h" #include "config.h"
#include <stdio.h>
#include <allegro.h>
#if defined ALLEGRO_WINDOWS && defined DEBUGMODE
#include <winalleg.h>
#include <psapi.h>
#endif
#include "app.h" #include "app.h"
#include "commands/command.h" #include "commands/command.h"
#include "gui/system.h" #include "gui/system.h"
@ -33,6 +26,12 @@
#include "document_wrappers.h" #include "document_wrappers.h"
#include "widgets/statebar.h" #include "widgets/statebar.h"
#include <allegro.h>
#if defined ALLEGRO_WINDOWS && defined DEBUGMODE
#include <winalleg.h>
#include <psapi.h>
#endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// refresh // refresh

View File

@ -109,7 +109,7 @@ protected:
continue; continue;
// rotate the image // 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->w: image->h,
m_angle == 180 ? image->h: image->w); m_angle == 180 ? image->h: image->w);
image_rotate(image, new_image, m_angle); image_rotate(image, new_image, m_angle);

View File

@ -83,7 +83,7 @@ void SpritePropertiesCommand::onExecute(Context* context)
const Sprite* sprite(document ? document->getSprite(): NULL); const Sprite* sprite(document ? document->getSprite(): NULL);
// Update widgets values // Update widgets values
switch (sprite->getImgType()) { switch (sprite->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
imgtype_text = "RGB"; imgtype_text = "RGB";
break; break;
@ -117,7 +117,7 @@ void SpritePropertiesCommand::onExecute(Context* context)
// How many frames // How many frames
frames->setTextf("%d", sprite->getTotalFrames()); frames->setTextf("%d", sprite->getTotalFrames());
if (sprite->getImgType() == IMAGE_INDEXED) { if (sprite->getPixelFormat() == IMAGE_INDEXED) {
color_button = new ColorButton(Color::fromIndex(sprite->getTransparentColor()), color_button = new ColorButton(Color::fromIndex(sprite->getTransparentColor()),
IMAGE_INDEXED); IMAGE_INDEXED);

View File

@ -91,7 +91,7 @@ protected:
// Resize the image // Resize the image
int w = scale_x(image->w); int w = scale_x(image->w);
int h = scale_y(image->h); 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_fixup_transparent_colors(image);
image_resize(image, new_image, image_resize(image, new_image,

View File

@ -24,8 +24,8 @@ FOR_EACH_COMMAND(Cancel)
FOR_EACH_COMMAND(CanvasSize) FOR_EACH_COMMAND(CanvasSize)
FOR_EACH_COMMAND(CelProperties) FOR_EACH_COMMAND(CelProperties)
FOR_EACH_COMMAND(ChangeColor) FOR_EACH_COMMAND(ChangeColor)
FOR_EACH_COMMAND(ChangeImageType)
FOR_EACH_COMMAND(ChangePen) FOR_EACH_COMMAND(ChangePen)
FOR_EACH_COMMAND(ChangePixelFormat)
FOR_EACH_COMMAND(Clear) FOR_EACH_COMMAND(Clear)
FOR_EACH_COMMAND(CloseAllFiles) FOR_EACH_COMMAND(CloseAllFiles)
FOR_EACH_COMMAND(CloseEditor) FOR_EACH_COMMAND(CloseEditor)

View File

@ -86,9 +86,9 @@ void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
m_progressDelegate = 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) void FilterManagerImpl::setTarget(int target)
@ -175,7 +175,7 @@ bool FilterManagerImpl::applyStep()
else else
m_mask_address = NULL; m_mask_address = NULL;
switch (m_sprite->getImgType()) { switch (m_sprite->getPixelFormat()) {
case IMAGE_RGB: m_filter->applyToRgba(this); break; case IMAGE_RGB: m_filter->applyToRgba(this); break;
case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break; case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break;
case IMAGE_INDEXED: m_filter->applyToIndexed(this); break; case IMAGE_INDEXED: m_filter->applyToIndexed(this); break;
@ -295,7 +295,7 @@ void FilterManagerImpl::flush()
const void* FilterManagerImpl::getSourceAddress() 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_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_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; 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() 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_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_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; case IMAGE_INDEXED: return ((uint8_t**)m_dst->line)[m_row+m_y]+m_x;

View File

@ -19,13 +19,15 @@
#ifndef COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED #ifndef COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED
#define COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED #define COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED
#include <cstring>
#include <stdlib.h>
#include "base/exception.h" #include "base/exception.h"
#include "base/exception.h"
#include "document_wrappers.h"
#include "filters/filter_indexed_data.h" #include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h" #include "filters/filter_manager.h"
#include "document_wrappers.h" #include "raster/pixel_format.h"
#include <cstdlib>
#include <cstring>
class Filter; class Filter;
class Image; class Image;
@ -70,7 +72,7 @@ public:
void setProgressDelegate(IProgressDelegate* progressDelegate); void setProgressDelegate(IProgressDelegate* progressDelegate);
int getImgType() const; PixelFormat getPixelFormat() const;
void setTarget(Target target); void setTarget(Target target);

View File

@ -40,7 +40,7 @@ FilterWindow::FilterWindow(const char* title, const char* cfgSection,
, m_okButton("&OK") , m_okButton("&OK")
, m_cancelButton("&Cancel") , m_cancelButton("&Cancel")
, m_preview(filterMgr) , m_preview(filterMgr)
, m_targetButton(filterMgr->getImgType(), (withChannels == WithChannelsSelector)) , m_targetButton(filterMgr->getPixelFormat(), (withChannels == WithChannelsSelector))
, m_showPreview("&Preview") , m_showPreview("&Preview")
, m_tiledCheck(withTiled == WithTiledCheckBox ? new CheckBox("&Tiled") : NULL) , m_tiledCheck(withTiled == WithTiledCheckBox ? new CheckBox("&Tiled") : NULL)
{ {

View File

@ -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)); clear_to_color(bmp, makecol32 (255, 0, 255));
textout_ex(bmp, f, text, 0, 0, makecol32 (255, 255, 255), -1); 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) { if (!image) {
destroy_bitmap(bmp); destroy_bitmap(bmp);
return NULL; return NULL;
@ -207,7 +207,7 @@ static Image* render_text(Sprite* sprite, FONT *f, const char *text, int color)
image_clear(image, 0); image_clear(image, 0);
acquire_bitmap(bmp); acquire_bitmap(bmp);
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
DO(uint32_t, _rgba(_rgba_getr(color), DO(uint32_t, _rgba(_rgba_getr(color),

View File

@ -83,7 +83,7 @@ void dialogs_mask_color(Document* document)
button_color = new ColorButton button_color = new ColorButton
(get_config_color("MaskColor", "Color", (get_config_color("MaskColor", "Color",
app_get_colorbar()->getFgColor()), app_get_colorbar()->getFgColor()),
sprite->getImgType()); sprite->getPixelFormat());
button_1 = new Button("1"); button_1 = new Button("1");
button_2 = new Button("2"); button_2 = new Button("2");
label_tolerance = new Label("Tolerance:"); label_tolerance = new Label("Tolerance:");
@ -183,7 +183,7 @@ static Mask* gen_mask(const Sprite* sprite)
const Image* image = sprite->getCurrentImage(&xpos, &ypos, NULL); 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(); tolerance = slider_tolerance->getValue();
UniquePtr<Mask> mask(new Mask()); UniquePtr<Mask> mask(new Mask());

View File

@ -77,16 +77,16 @@ Document::~Document()
destroyExtraCel(); 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. // Create the sprite.
UniquePtr<Sprite> sprite(new Sprite(imgtype, width, height, ncolors)); UniquePtr<Sprite> sprite(new Sprite(format, width, height, ncolors));
sprite->setTotalFrames(1); sprite->setTotalFrames(1);
// Create the main image. // Create the main image.
int indexInStock; int indexInStock;
{ {
UniquePtr<Image> image(Image::create(imgtype, width, height)); UniquePtr<Image> image(Image::create(format, width, height));
// Clear the image with mask color. // Clear the image with mask color.
image_clear(image, 0); 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); m_extraCel->setOpacity(opacity);
if (!m_extraImage || if (!m_extraImage ||
m_extraImage->imgtype != getSprite()->getImgType() || m_extraImage->getPixelFormat() != getSprite()->getPixelFormat() ||
m_extraImage->w != w || m_extraImage->w != w ||
m_extraImage->h != h) { m_extraImage->h != h) {
delete m_extraImage; // image delete m_extraImage; // image
m_extraImage = Image::create(getSprite()->getImgType(), w, h); m_extraImage = Image::create(getSprite()->getPixelFormat(), w, h);
image_clear(m_extraImage, image_clear(m_extraImage,
m_extraImage->mask_color = 0); m_extraImage->mask_color = 0);
} }
@ -399,7 +399,7 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
Document* Document::duplicate(DuplicateType type) const Document* Document::duplicate(DuplicateType type) const
{ {
const Sprite* sourceSprite = getSprite(); const Sprite* sourceSprite = getSprite();
UniquePtr<Sprite> spriteCopyPtr(new Sprite(sourceSprite->getImgType(), UniquePtr<Sprite> spriteCopyPtr(new Sprite(sourceSprite->getPixelFormat(),
sourceSprite->getWidth(), sourceSprite->getWidth(),
sourceSprite->getHeight(), sourceSprite->getPalette(0)->size())); sourceSprite->getHeight(), sourceSprite->getPalette(0)->size()));
UniquePtr<Document> documentCopy(new Document(spriteCopyPtr)); UniquePtr<Document> documentCopy(new Document(spriteCopyPtr));

View File

@ -24,6 +24,7 @@
#include "base/unique_ptr.h" #include "base/unique_ptr.h"
#include "document_id.h" #include "document_id.h"
#include "gfx/transformation.h" #include "gfx/transformation.h"
#include "raster/pixel_format.h"
#include <string> #include <string>
@ -68,7 +69,7 @@ public:
// Creates a document with one sprite, with one transparent layer, // Creates a document with one sprite, with one transparent layer,
// and one frame. // 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(Sprite* sprite);
~Document(); ~Document();

View File

@ -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 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 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 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 void ase_file_write_cel_chunk(FILE *f, Cel *cel, LayerImage *layer, Sprite *sprite);
static Mask *ase_file_read_mask_chunk(FILE *f); static Mask *ase_file_read_mask_chunk(FILE *f);
static void ase_file_write_mask_chunk(FILE *f, Mask *mask); 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: case ASE_FILE_CHUNK_FLI_COLOR2:
/* fop_error(fop, "Color chunk\n"); */ /* fop_error(fop, "Color chunk\n"); */
if (sprite->getImgType() == IMAGE_INDEXED) { if (sprite->getPixelFormat() == IMAGE_INDEXED) {
Palette *prev_pal = sprite->getPalette(frame); Palette *prev_pal = sprite->getPalette(frame);
Palette *pal = Palette *pal =
chunk_type == ASE_FILE_CHUNK_FLI_COLOR ? chunk_type == ASE_FILE_CHUNK_FLI_COLOR ?
@ -237,7 +237,7 @@ bool AseFormat::onLoad(FileOp *fop)
/* fop_error(fop, "Cel chunk\n"); */ /* fop_error(fop, "Cel chunk\n"); */
ase_file_read_cel_chunk(f, sprite, frame, ase_file_read_cel_chunk(f, sprite, frame,
sprite->getImgType(), fop, &header, sprite->getPixelFormat(), fop, &header,
chunk_pos+chunk_size); chunk_pos+chunk_size);
break; break;
} }
@ -318,7 +318,7 @@ bool AseFormat::onSave(FileOp *fop)
frame_header.duration = sprite->getFrameDuration(frame); frame_header.duration = sprite->getFrameDuration(frame);
/* the sprite is indexed and the palette changes? (or is the first 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 || (frame == 0 ||
sprite->getPalette(frame-1)->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) { sprite->getPalette(frame-1)->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) {
/* write the color chunk */ /* 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->frames = sprite->getTotalFrames();
header->width = sprite->getWidth(); header->width = sprite->getWidth();
header->height = sprite->getHeight(); header->height = sprite->getHeight();
header->depth = (sprite->getImgType() == IMAGE_RGB ? 32: header->depth = (sprite->getPixelFormat() == IMAGE_RGB ? 32:
sprite->getImgType() == IMAGE_GRAYSCALE ? 16: sprite->getPixelFormat() == IMAGE_GRAYSCALE ? 16:
sprite->getImgType() == IMAGE_INDEXED ? 8: 0); sprite->getPixelFormat() == IMAGE_INDEXED ? 8: 0);
header->flags = 0; header->flags = 0;
header->speed = sprite->getFrameDuration(0); header->speed = sprite->getFrameDuration(0);
header->next = 0; header->next = 0;
@ -997,7 +997,9 @@ static void write_compressed_image(FILE* f, Image* image)
// Cel Chunk // 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; Cel *cel;
/* read chunk data */ /* 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); int h = fgetw(f);
if (w > 0 && h > 0) { if (w > 0 && h > 0) {
Image* image = Image::create(imgtype, w, h); Image* image = Image::create(pixelFormat, w, h);
if (!image) { if (!image) {
delete cel; delete cel;
// Not enough memory for frame's image // 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 // Read pixel data
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
read_raw_image<RgbTraits>(f, image, fop, header); read_raw_image<RgbTraits>(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); int h = fgetw(f);
if (w > 0 && h > 0) { if (w > 0 && h > 0) {
Image* image = Image::create(imgtype, w, h); Image* image = Image::create(pixelFormat, w, h);
if (!image) { if (!image) {
delete cel; delete cel;
// Not enough memory for frame's image // 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 // Read pixel data
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
read_compressed_image<RgbTraits>(f, image, chunk_end, fop, header); read_compressed_image<RgbTraits>(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); fputw(image->h, f);
// Pixel data // Pixel data
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
write_raw_image<RgbTraits>(f, image); write_raw_image<RgbTraits>(f, image);
@ -1184,7 +1186,7 @@ static void ase_file_write_cel_chunk(FILE *f, Cel *cel, LayerImage *layer, Sprit
fputw(image->h, f); fputw(image->h, f);
// Pixel data // Pixel data
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
write_compressed_image<RgbTraits>(f, image); write_compressed_image<RgbTraits>(f, image);

View File

@ -603,7 +603,8 @@ bool BmpFormat::onLoad(FileOp *fop)
Image *image; Image *image;
FILE *f; FILE *f;
unsigned long biSize; unsigned long biSize;
int type, format; PixelFormat pixelFormat;
int format;
f = fopen(fop->filename.c_str(), "rb"); f = fopen(fop->filename.c_str(), "rb");
if (!f) if (!f)
@ -645,9 +646,9 @@ bool BmpFormat::onLoad(FileOp *fop)
if ((infoheader.biBitCount == 32) || if ((infoheader.biBitCount == 32) ||
(infoheader.biBitCount == 24) || (infoheader.biBitCount == 24) ||
(infoheader.biBitCount == 16)) (infoheader.biBitCount == 16))
type = IMAGE_RGB; pixelFormat = IMAGE_RGB;
else else
type = IMAGE_INDEXED; pixelFormat = IMAGE_INDEXED;
/* bitfields have the 'mask' for each component */ /* bitfields have the 'mask' for each component */
if (infoheader.biCompression == BI_BITFIELDS) { if (infoheader.biCompression == BI_BITFIELDS) {
@ -658,7 +659,7 @@ bool BmpFormat::onLoad(FileOp *fop)
else else
rmask = gmask = bmask = 0; rmask = gmask = bmask = 0;
image = fop_sequence_image(fop, type, image = fop_sequence_image(fop, pixelFormat,
infoheader.biWidth, infoheader.biWidth,
ABS((int)infoheader.biHeight)); ABS((int)infoheader.biHeight));
if (!image) { if (!image) {
@ -666,7 +667,7 @@ bool BmpFormat::onLoad(FileOp *fop)
return false; return false;
} }
if (type == IMAGE_RGB) if (pixelFormat == IMAGE_RGB)
image_clear(image, _rgba(0, 0, 0, 255)); image_clear(image, _rgba(0, 0, 0, 255));
else else
image_clear(image, 0); image_clear(image, 0);
@ -730,7 +731,7 @@ bool BmpFormat::onSave(FileOp *fop)
FILE *f; FILE *f;
int bfSize; int bfSize;
int biSizeImage; 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 filler = 3 - ((image->w*(bpp/8)-1) & 3);
int c, i, j, r, g, b; 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 (i=image->h-1; i>=0; i--) {
for (j=0; j<image->w; j++) { for (j=0; j<image->w; j++) {
if (bpp == 8) { if (bpp == 8) {
if (image->imgtype == IMAGE_INDEXED) if (image->getPixelFormat() == IMAGE_INDEXED)
fputc(image_getpixel_fast<IndexedTraits>(image, j, i), f); fputc(image_getpixel_fast<IndexedTraits>(image, j, i), f);
else if (image->imgtype == IMAGE_GRAYSCALE) else if (image->getPixelFormat() == IMAGE_GRAYSCALE)
fputc(_graya_getv(image_getpixel_fast<GrayscaleTraits>(image, j, i)), f); fputc(_graya_getv(image_getpixel_fast<GrayscaleTraits>(image, j, i)), f);
} }
else { else {

View File

@ -254,7 +254,7 @@ FileOp* fop_to_save_document(Document* document)
fatal = false; fatal = false;
/* check image type support */ /* check image type support */
switch (fop->document->getSprite()->getImgType()) { switch (fop->document->getSprite()->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
if (!(fop->format->support(FILE_SUPPORT_RGB))) { if (!(fop->format->support(FILE_SUPPORT_RGB))) {
@ -542,7 +542,7 @@ void fop_operate(FileOp *fop)
Sprite* sprite = fop->document->getSprite(); Sprite* sprite = fop->document->getSprite();
// Create a temporary bitmap // Create a temporary bitmap
fop->seq.image = Image::create(sprite->getImgType(), fop->seq.image = Image::create(sprite->getPixelFormat(),
sprite->getWidth(), sprite->getWidth(),
sprite->getHeight()); sprite->getHeight());
if (fop->seq.image != NULL) { if (fop->seq.image != NULL) {
@ -654,7 +654,7 @@ void fop_post_load(FileOp* fop)
} }
// Creates a suitable palette for RGB images // 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()->getPalettes().size() <= 1 &&
fop->document->getSprite()->getPalette(0)->isBlack()) { fop->document->getSprite()->getPalette(0)->isBlack()) {
SharedPtr<Palette> palette(quantization::create_palette_from_rgb(fop->document->getSprite())); SharedPtr<Palette> 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); *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; Sprite* sprite;
// Create the image // Create the image
if (!fop->document) { if (!fop->document) {
sprite = new Sprite(imgtype, w, h, 256); sprite = new Sprite(pixelFormat, w, h, 256);
try { try {
LayerImage* layer = new LayerImage(sprite); LayerImage* layer = new LayerImage(sprite);
@ -712,7 +712,7 @@ Image* fop_sequence_image(FileOp* fop, int imgtype, int w, int h)
else { else {
sprite = fop->document->getSprite(); sprite = fop->document->getSprite();
if (sprite->getImgType() != imgtype) if (sprite->getPixelFormat() != pixelFormat)
return NULL; return NULL;
} }
@ -722,7 +722,7 @@ Image* fop_sequence_image(FileOp* fop, int imgtype, int w, int h)
} }
// Create a bitmap // Create a bitmap
Image* image = Image::create(imgtype, w, h); Image* image = Image::create(pixelFormat, w, h);
fop->seq.image = image; fop->seq.image = image;
fop->seq.last_cel = new Cel(fop->seq.frame++, 0); fop->seq.last_cel = new Cel(fop->seq.frame++, 0);

View File

@ -20,6 +20,7 @@
#define FILE_FILE_H_INCLUDED #define FILE_FILE_H_INCLUDED
#include "base/shared_ptr.h" #include "base/shared_ptr.h"
#include "raster/pixeL_format.h"
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
@ -115,7 +116,7 @@ void fop_post_load(FileOp* fop);
void fop_sequence_set_format_options(FileOp* fop, const SharedPtr<FormatOptions>& format_options); void fop_sequence_set_format_options(FileOp* fop, const SharedPtr<FormatOptions>& format_options);
void fop_sequence_set_color(FileOp* fop, int index, int r, int g, int b); 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); 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_error(FileOp* fop, const char *error, ...);
void fop_progress(FileOp* fop, float progress); void fop_progress(FileOp* fop, float progress);

View File

@ -274,7 +274,7 @@ bool GifFormat::onPostLoad(FileOp* fop)
if (!data) if (!data)
return true; return true;
int imgtype = IMAGE_INDEXED; PixelFormat pixelFormat = IMAGE_INDEXED;
bool askForConversion = false; bool askForConversion = false;
if (!fop->oneframe) { if (!fop->oneframe) {
@ -326,19 +326,19 @@ bool GifFormat::onPostLoad(FileOp* fop)
fop->document->getFilename()); fop->document->getFilename());
if (result == 1) if (result == 1)
imgtype = IMAGE_RGB; pixelFormat = IMAGE_RGB;
else if (result != 2) else if (result != 2)
return false; return false;
} }
// Create the sprite with the GIF dimension // Create the sprite with the GIF dimension
UniquePtr<Sprite> sprite(new Sprite(imgtype, data->sprite_w, data->sprite_h, 256)); UniquePtr<Sprite> sprite(new Sprite(pixelFormat, data->sprite_w, data->sprite_h, 256));
// Create the main layer // Create the main layer
LayerImage* layer = new LayerImage(sprite); LayerImage* layer = new LayerImage(sprite);
sprite->getFolder()->add_layer(layer); sprite->getFolder()->add_layer(layer);
if (imgtype == IMAGE_INDEXED) { if (pixelFormat == IMAGE_INDEXED) {
if (data->bgcolor_index >= 0) if (data->bgcolor_index >= 0)
sprite->setTransparentColor(data->bgcolor_index); sprite->setTransparentColor(data->bgcolor_index);
else else
@ -348,11 +348,11 @@ bool GifFormat::onPostLoad(FileOp* fop)
// The previous image is used to support the special disposal method // The previous image is used to support the special disposal method
// of GIF frames DISPOSAL_METHOD_RESTORE_PREVIOUS (number 3 in // of GIF frames DISPOSAL_METHOD_RESTORE_PREVIOUS (number 3 in
// Graphics Extension) // Graphics Extension)
UniquePtr<Image> current_image(Image::create(imgtype, data->sprite_w, data->sprite_h)); UniquePtr<Image> current_image(Image::create(pixelFormat, data->sprite_w, data->sprite_h));
UniquePtr<Image> previous_image(Image::create(imgtype, data->sprite_w, data->sprite_h)); UniquePtr<Image> previous_image(Image::create(pixelFormat, data->sprite_w, data->sprite_h));
// Clear both images with the transparent color (alpha = 0). // 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)); (data->bgcolor_index >= 0 ? data->bgcolor_index: 0));
image_clear(current_image, bgcolor); image_clear(current_image, bgcolor);
image_clear(previous_image, bgcolor); image_clear(previous_image, bgcolor);
@ -375,7 +375,7 @@ bool GifFormat::onPostLoad(FileOp* fop)
current_palette = frame_it->palette; current_palette = frame_it->palette;
} }
switch (imgtype) { switch (pixelFormat) {
case IMAGE_INDEXED: case IMAGE_INDEXED:
for (int y = 0; y < frame_it->image->h; ++y) for (int y = 0; y < frame_it->image->h; ++y)
@ -490,10 +490,10 @@ bool GifFormat::onSave(FileOp* fop)
Sprite* sprite = fop->document->getSprite(); Sprite* sprite = fop->document->getSprite();
int sprite_w = sprite->getWidth(); int sprite_w = sprite->getWidth();
int sprite_h = sprite->getHeight(); int sprite_h = sprite->getHeight();
int sprite_imgtype = sprite->getImgType(); PixelFormat sprite_format = sprite->getPixelFormat();
bool interlace = false; bool interlace = false;
int loop = 0; 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()); int transparent_index = (sprite->getBackgroundLayer() ? -1: sprite->getTransparentColor());
Palette* current_palette = sprite->getPalette(0); 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 // If the sprite is not Indexed type, we will need a temporary
// buffer to render the full RGB or Grayscale sprite. // buffer to render the full RGB or Grayscale sprite.
if (sprite_imgtype != IMAGE_INDEXED) if (sprite_format != IMAGE_INDEXED)
buffer_image.reset(Image::create(sprite_imgtype, sprite_w, sprite_h)); buffer_image.reset(Image::create(sprite_format, sprite_w, sprite_h));
image_clear(current_image, background_color); image_clear(current_image, background_color);
image_clear(previous_image, background_color); image_clear(previous_image, background_color);
@ -529,11 +529,11 @@ bool GifFormat::onSave(FileOp* fop)
current_palette = sprite->getPalette(frame_num); current_palette = sprite->getPalette(frame_num);
// If the sprite is RGB or Grayscale, we must to convert it to Indexed on the fly. // 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); image_clear(buffer_image, 0);
layer_render(sprite->getFolder(), buffer_image, 0, 0, frame_num); layer_render(sprite->getFolder(), buffer_image, 0, 0, frame_num);
switch (sprite_imgtype) { switch (sprite_format) {
// Convert the RGB image to Indexed // Convert the RGB image to Indexed
case IMAGE_RGB: case IMAGE_RGB:

View File

@ -129,17 +129,17 @@ bool IcoFormat::onLoad(FileOp* fop)
int width = (entry.width == 0 ? 256: entry.width); int width = (entry.width == 0 ? 256: entry.width);
int height = (entry.height == 0 ? 256: entry.height); int height = (entry.height == 0 ? 256: entry.height);
int numcolors = (entry.color_count == 0 ? 256: entry.color_count); int numcolors = (entry.color_count == 0 ? 256: entry.color_count);
int imgtype = IMAGE_INDEXED; PixelFormat pixelFormat = IMAGE_INDEXED;
if (entry.bpp > 8) if (entry.bpp > 8)
imgtype = IMAGE_RGB; pixelFormat = IMAGE_RGB;
// Create the sprite with one background layer // 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); LayerImage* layer = new LayerImage(sprite);
sprite->getFolder()->add_layer(layer); sprite->getFolder()->add_layer(layer);
// Create the first image/cel // 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); int image_index = sprite->getStock()->addImage(image);
Cel* cel = new Cel(0, image_index); Cel* cel = new Cel(0, image_index);
layer->addCel(cel); layer->addCel(cel);
@ -258,7 +258,7 @@ bool IcoFormat::onSave(FileOp* fop)
// Entries // Entries
for (n=0; n<num; ++n) { for (n=0; n<num; ++n) {
bpp = (sprite->getImgType() == IMAGE_INDEXED) ? 8 : 24; bpp = (sprite->getPixelFormat() == IMAGE_INDEXED) ? 8 : 24;
bw = (((sprite->getWidth() * bpp / 8) + 3) / 4) * 4; bw = (((sprite->getWidth() * bpp / 8) + 3) / 4) * 4;
bitsw = ((((sprite->getWidth() + 7) / 8) + 3) / 4) * 4; bitsw = ((((sprite->getWidth() + 7) / 8) + 3) / 4) * 4;
size = sprite->getHeight() * (bw + bitsw) + 40; size = sprite->getHeight() * (bw + bitsw) + 40;
@ -279,7 +279,7 @@ bool IcoFormat::onSave(FileOp* fop)
offset += size; offset += size;
} }
Image* image = Image::create(sprite->getImgType(), Image* image = Image::create(sprite->getPixelFormat(),
sprite->getWidth(), sprite->getWidth(),
sprite->getHeight()); sprite->getHeight());
@ -287,7 +287,7 @@ bool IcoFormat::onSave(FileOp* fop)
image_clear(image, 0); image_clear(image, 0);
layer_render(sprite->getFolder(), image, 0, 0, n); 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; bw = (((image->w * bpp / 8) + 3) / 4) * 4;
bitsw = ((((image->w + 7) / 8) + 3) / 4) * 4; bitsw = ((((image->w + 7) / 8) + 3) / 4) * 4;
size = image->h * (bw + bitsw) + 40; size = image->h * (bw + bitsw) + 40;
@ -325,7 +325,7 @@ bool IcoFormat::onSave(FileOp* fop)
// XOR MASK // XOR MASK
for (y=image->h-1; y>=0; --y) { for (y=image->h-1; y>=0; --y) {
for (x=0; x<image->w; ++x) { for (x=0; x<image->w; ++x) {
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
c = image_getpixel(image, x, y); c = image_getpixel(image, x, y);
@ -364,7 +364,7 @@ bool IcoFormat::onSave(FileOp* fop)
for (b=0; b<8; b++) { for (b=0; b<8; b++) {
c = image_getpixel(image, x*8+b, y); c = image_getpixel(image, x*8+b, y);
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
if (_rgba_geta(c) == 0) if (_rgba_geta(c) == 0)

View File

@ -177,7 +177,7 @@ bool JpegFormat::onLoad(FileOp* fop)
} }
// Generate a grayscale palette if is necessary. // Generate a grayscale palette if is necessary.
if (image->imgtype == IMAGE_GRAYSCALE) if (image->getPixelFormat() == IMAGE_GRAYSCALE)
for (c=0; c<256; c++) for (c=0; c<256; c++)
fop_sequence_set_color(fop, c, c, c, 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); num_scanlines = jpeg_read_scanlines(&cinfo, buffer, buffer_height);
/* RGB */ /* RGB */
if (image->imgtype == IMAGE_RGB) { if (image->getPixelFormat() == IMAGE_RGB) {
uint8_t* src_address; uint8_t* src_address;
uint32_t* dst_address; uint32_t* dst_address;
int x, y, r, g, b; int x, y, r, g, b;
@ -269,7 +269,7 @@ bool JpegFormat::onSave(FileOp* fop)
cinfo.image_width = image->w; cinfo.image_width = image->w;
cinfo.image_height = image->h; cinfo.image_height = image->h;
if (image->imgtype == IMAGE_GRAYSCALE) { if (image->getPixelFormat() == IMAGE_GRAYSCALE) {
cinfo.input_components = 1; cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE; cinfo.in_color_space = JCS_GRAYSCALE;
} }
@ -313,7 +313,7 @@ bool JpegFormat::onSave(FileOp* fop)
// Write each scan line. // Write each scan line.
while (cinfo.next_scanline < cinfo.image_height) { while (cinfo.next_scanline < cinfo.image_height) {
// RGB // RGB
if (image->imgtype == IMAGE_RGB) { if (image->getPixelFormat() == IMAGE_RGB) {
uint32_t* src_address; uint32_t* src_address;
uint8_t* dst_address; uint8_t* dst_address;
int x, y; int x, y;

View File

@ -202,7 +202,7 @@ bool PcxFormat::onSave(FileOp* fop)
return false; return false;
} }
if (image->imgtype == IMAGE_RGB) { if (image->getPixelFormat() == IMAGE_RGB) {
depth = 24; depth = 24;
planes = 3; planes = 3;
} }
@ -243,9 +243,9 @@ bool PcxFormat::onSave(FileOp* fop)
runchar = 0; runchar = 0;
for (x=0; x<image->w*planes; x++) { /* for each pixel... */ for (x=0; x<image->w*planes; x++) { /* for each pixel... */
if (depth == 8) { if (depth == 8) {
if (image->imgtype == IMAGE_INDEXED) if (image->getPixelFormat() == IMAGE_INDEXED)
ch = image_getpixel_fast<IndexedTraits>(image, x, y); ch = image_getpixel_fast<IndexedTraits>(image, x, y);
else if (image->imgtype == IMAGE_GRAYSCALE) { else if (image->getPixelFormat() == IMAGE_GRAYSCALE) {
c = image_getpixel_fast<GrayscaleTraits>(image, x, y); c = image_getpixel_fast<GrayscaleTraits>(image, x, y);
ch = _graya_getv(c); ch = _graya_getv(c);
} }

View File

@ -75,8 +75,8 @@ bool PngFormat::onLoad(FileOp* fop)
png_colorp palette; png_colorp palette;
png_bytep row_pointer; png_bytep row_pointer;
Image *image; Image *image;
int imgtype;
FILE *fp; FILE *fp;
PixelFormat pixelFormat;
fp = fopen(fop->filename.c_str(), "rb"); fp = fopen(fop->filename.c_str(), "rb");
if (!fp) if (!fp)
@ -167,17 +167,17 @@ bool PngFormat::onLoad(FileOp* fop)
case PNG_COLOR_TYPE_RGB_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA:
fop->seq.has_alpha = true; fop->seq.has_alpha = true;
case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB:
imgtype = IMAGE_RGB; pixelFormat = IMAGE_RGB;
break; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_GRAY_ALPHA:
fop->seq.has_alpha = true; fop->seq.has_alpha = true;
case PNG_COLOR_TYPE_GRAY: case PNG_COLOR_TYPE_GRAY:
imgtype = IMAGE_GRAYSCALE; pixelFormat = IMAGE_GRAYSCALE;
break; break;
case PNG_COLOR_TYPE_PALETTE: case PNG_COLOR_TYPE_PALETTE:
imgtype = IMAGE_INDEXED; pixelFormat = IMAGE_INDEXED;
break; break;
default: default:
@ -187,7 +187,7 @@ bool PngFormat::onLoad(FileOp* fop)
return false; 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) { if (!image) {
fop_error(fop, "file_sequence_image %dx%d\n", info_ptr->width, info_ptr->height); fop_error(fop, "file_sequence_image %dx%d\n", info_ptr->width, info_ptr->height);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
@ -395,7 +395,7 @@ bool PngFormat::onSave(FileOp* fop)
width = image->w; width = image->w;
height = image->h; height = image->h;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
color_type = fop->document->getSprite()->needAlpha() ? color_type = fop->document->getSprite()->needAlpha() ?
PNG_COLOR_TYPE_RGB_ALPHA: 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_set_IHDR(png_ptr, info_ptr, width, height, 8, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 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; int c, r, g, b;
#if PNG_MAX_PALETTE_LENGTH != 256 #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 libpng mallocs info_ptr->palette, libpng will free it). If you
allocated it with malloc() instead of png_malloc(), use free() instead allocated it with malloc() instead of png_malloc(), use free() instead
of png_free(). */ of png_free(). */
if (image->imgtype == IMAGE_INDEXED) { if (image->getPixelFormat() == IMAGE_INDEXED) {
png_free(png_ptr, palette); png_free(png_ptr, palette);
palette = NULL; palette = NULL;
} }

View File

@ -204,7 +204,6 @@ bool TgaFormat::onLoad(FileOp* fop)
Image *image; Image *image;
int compressed; int compressed;
FILE *f; FILE *f;
int type;
f = fopen(fop->filename.c_str(), "rb"); f = fopen(fop->filename.c_str(), "rb");
if (!f) if (!f)
@ -264,6 +263,8 @@ bool TgaFormat::onLoad(FileOp* fop)
compressed = (image_type & 8); compressed = (image_type & 8);
image_type &= 7; image_type &= 7;
PixelFormat pixelFormat;
switch (image_type) { switch (image_type) {
/* paletted image */ /* paletted image */
@ -280,7 +281,7 @@ bool TgaFormat::onLoad(FileOp* fop)
image_palette[i][0]); image_palette[i][0]);
} }
type = IMAGE_INDEXED; pixelFormat = IMAGE_INDEXED;
break; break;
/* truecolor image */ /* truecolor image */
@ -292,7 +293,7 @@ bool TgaFormat::onLoad(FileOp* fop)
return false; return false;
} }
type = IMAGE_RGB; pixelFormat = IMAGE_RGB;
break; break;
/* grayscale image */ /* grayscale image */
@ -305,7 +306,7 @@ bool TgaFormat::onLoad(FileOp* fop)
for (i=0; i<256; i++) for (i=0; i<256; i++)
fop_sequence_set_color(fop, i, i, i, i); fop_sequence_set_color(fop, i, i, i, i);
type = IMAGE_GRAYSCALE; pixelFormat = IMAGE_GRAYSCALE;
break; break;
default: default:
@ -315,7 +316,7 @@ bool TgaFormat::onLoad(FileOp* fop)
return false; return false;
} }
image = fop_sequence_image(fop, type, image_width, image_height); image = fop_sequence_image(fop, pixelFormat, image_width, image_height);
if (!image) { if (!image) {
fclose(f); fclose(f);
return false; return false;
@ -408,8 +409,8 @@ bool TgaFormat::onSave(FileOp* fop)
Image *image = fop->seq.image; Image *image = fop->seq.image;
unsigned char image_palette[256][3]; unsigned char image_palette[256][3];
int x, y, c, r, g, b; int x, y, c, r, g, b;
int depth = (image->imgtype == IMAGE_RGB) ? 32 : 8; int depth = (image->getPixelFormat() == IMAGE_RGB) ? 32 : 8;
bool need_pal = (image->imgtype == IMAGE_INDEXED)? true: false; bool need_pal = (image->getPixelFormat() == IMAGE_INDEXED)? true: false;
FILE *f; FILE *f;
f = fopen(fop->filename.c_str(), "wb"); 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(0, f); /* id length (no id saved) */
fputc((need_pal) ? 1 : 0, f); /* palette type */ fputc((need_pal) ? 1 : 0, f); /* palette type */
/* image type */ /* image type */
fputc((image->imgtype == IMAGE_RGB ) ? 2 : fputc((image->getPixelFormat() == IMAGE_RGB ) ? 2 :
(image->imgtype == IMAGE_GRAYSCALE) ? 3 : (image->getPixelFormat() == IMAGE_GRAYSCALE) ? 3 :
(image->imgtype == IMAGE_INDEXED ) ? 1 : 0, f); (image->getPixelFormat() == IMAGE_INDEXED ) ? 1 : 0, f);
fputw(0, f); /* first colour */ fputw(0, f); /* first colour */
fputw((need_pal) ? 256 : 0, f); /* number of colours */ fputw((need_pal) ? 256 : 0, f); /* number of colours */
fputc((need_pal) ? 24 : 0, f); /* palette entry size */ fputc((need_pal) ? 24 : 0, f); /* palette entry size */
@ -434,7 +435,7 @@ bool TgaFormat::onSave(FileOp* fop)
fputc(depth, f); /* bits per pixel */ fputc(depth, f); /* bits per pixel */
/* descriptor (bottom to top, 8-bit alpha) */ /* 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) { if (need_pal) {
for (y=0; y<256; y++) { for (y=0; y<256; y++) {
@ -446,7 +447,7 @@ bool TgaFormat::onSave(FileOp* fop)
fwrite(image_palette, 1, 768, f); fwrite(image_palette, 1, 768, f);
} }
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
for (y=image->h-1; y>=0; y--) { for (y=image->h-1; y>=0; y--) {

View File

@ -355,7 +355,7 @@ void draw_emptyset_symbol(BITMAP* bmp, const Rect& rc, int color)
center.x+size/2, center.y-size/2, 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(); Color::Type type = color.getType();
BITMAP* graph; BITMAP* graph;
@ -378,11 +378,11 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color)
return; return;
} }
switch (imgtype) { switch (pixelFormat) {
case IMAGE_INDEXED: case IMAGE_INDEXED:
rectfill(bmp, rc.x, rc.y, rc.x+rc.w-1, rc.y+rc.h-1, 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))); bitmap_color_depth(bmp)));
break; break;
@ -392,7 +392,7 @@ void draw_color(BITMAP* bmp, const Rect& rc, int imgtype, const Color& color)
return; 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), Color color2 = Color::fromRgb(_rgba_getr(rgb_bitmap_color),
_rgba_getg(rgb_bitmap_color), _rgba_getg(rgb_bitmap_color),
_rgba_getb(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; 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)); Color color2 = Color::fromGray(_graya_getv(gray_bitmap_color));
rectfill(graph, 0, 0, rc.w-1, rc.h-1, rectfill(graph, 0, 0, rc.w-1, rc.h-1,
color_utils::color_for_allegro(color2, 32)); color_utils::color_for_allegro(color2, 32));
@ -428,7 +428,7 @@ void draw_color_button(BITMAP* bmp,
const Rect& rc, const Rect& rc,
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
bool outer_se, bool outer_s, bool outer_sw, bool outer_w, 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(); SkinTheme* theme = (SkinTheme*)CurrentTheme::get();
int scale = jguiscale(); int scale = jguiscale();
@ -438,7 +438,7 @@ void draw_color_button(BITMAP* bmp,
Rect(rc.x+1*jguiscale(), Rect(rc.x+1*jguiscale(),
rc.y+1*jguiscale(), rc.y+1*jguiscale(),
rc.w-((outer_e) ? 2*jguiscale(): 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 // Draw opaque border
{ {

View File

@ -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 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_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, void draw_color_button(BITMAP* bmp,
const gfx::Rect& rc, const gfx::Rect& rc,
bool outer_nw, bool outer_n, bool outer_ne, bool outer_e, bool outer_nw, bool outer_n, bool outer_ne, bool outer_e,
bool outer_se, bool outer_s, bool outer_sw, bool outer_w, 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); bool hot, bool drag);
void draw_progress_bar(BITMAP* bmp, void draw_progress_bar(BITMAP* bmp,
int x1, int y1, int x2, int y2, int x1, int y1, int x2, int y2,

View File

@ -18,16 +18,6 @@
#include "config.h" #include "config.h"
#include <algorithm>
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include <list>
#include <vector>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#endif
#include "app.h" #include "app.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/shared_ptr.h" #include "base/shared_ptr.h"
@ -59,6 +49,16 @@
#include "widgets/toolbar.h" #include "widgets/toolbar.h"
#include "xml_widgets.h" #include "xml_widgets.h"
#include <algorithm>
#include <allegro.h>
#include <allegro/internal/aintern.h>
#include <list>
#include <vector>
#ifdef ALLEGRO_WINDOWS
#include <winalleg.h>
#endif
#define REFRESH_FULL_SCREEN 1 #define REFRESH_FULL_SCREEN 1
#define SYSTEM_WINDOW_RESIZE 2 #define SYSTEM_WINDOW_RESIZE 2

View File

@ -19,14 +19,14 @@
#include "config.h" #include "config.h"
#include "raster/algo.h"
#include "raster/image.h"
#include <allegro.h> #include <allegro.h>
#include <allegro/internal/aintern.h> #include <allegro/internal/aintern.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include "raster/algo.h"
#include "raster/image.h"
typedef struct FLOODED_LINE /* store segments which have been flooded */ 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 left = 0, right = 0;
int c; int c;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
{ {

View File

@ -18,20 +18,20 @@
#include "config.h" #include "config.h"
#include <algorithm>
#include "raster/dirty.h" #include "raster/dirty.h"
#include "raster/image.h" #include "raster/image.h"
Dirty::Dirty(int imgtype, int x1, int y1, int x2, int y2) #include <algorithm>
: m_imgtype(imgtype)
Dirty::Dirty(PixelFormat format, int x1, int y1, int x2, int y2)
: m_format(format)
, m_x1(x1), m_y1(y1) , m_x1(x1), m_y1(y1)
, m_x2(x2), m_y2(y2) , m_x2(x2), m_y2(y2)
{ {
} }
Dirty::Dirty(const Dirty& src) 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_x1(src.m_x1), m_y1(src.m_y1)
, m_x2(src.m_x2), m_y2(src.m_y2) , 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) Dirty::Dirty(Image* image, Image* image_diff)
: m_imgtype(image->imgtype) : m_format(image->getPixelFormat())
, m_x1(0), m_y1(0) , m_x1(0), m_y1(0)
, m_x2(image->w-1), m_y2(image->h-1) , m_x2(image->w-1), m_y2(image->h-1)
{ {

View File

@ -52,14 +52,14 @@ public:
Row(int y) : y(y) { } 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(const Dirty& src);
Dirty(Image* image1, Image* image2); Dirty(Image* image1, Image* image2);
~Dirty(); ~Dirty();
int getMemSize() const; int getMemSize() const;
int getImgType() const { return m_imgtype; } PixelFormat getPixelFormat() const { return m_format; }
int x1() const { return m_x1; } int x1() const { return m_x1; }
int y1() const { return m_y1; } int y1() const { return m_y1; }
int x2() const { return m_x2; } int x2() const { return m_x2; }
@ -69,7 +69,7 @@ public:
const Row& getRow(int i) const { return *m_rows[i]; } const Row& getRow(int i) const { return *m_rows[i]; }
inline int getLineSize(int width) const { inline int getLineSize(int width) const {
return imgtype_line_size(m_imgtype, width); return pixelformat_line_size(m_format, width);
} }
void saveImagePixels(Image* image); void saveImagePixels(Image* image);
@ -86,7 +86,7 @@ public: // a Dirty instance from a deserialization process,
// remember to "privatize" these members when the // remember to "privatize" these members when the
// new Undo implementation is finished. // new Undo implementation is finished.
int m_imgtype; PixelFormat m_format;
int m_x1, m_y1; int m_x1, m_y1;
int m_x2, m_y2; int m_x2, m_y2;
RowsList m_rows; RowsList m_rows;

View File

@ -47,7 +47,7 @@ using namespace base::serialization::little_endian;
void write_dirty(std::ostream& os, Dirty* dirty) void write_dirty(std::ostream& os, Dirty* dirty)
{ {
write8(os, dirty->getImgType()); write8(os, dirty->getPixelFormat());
write16(os, dirty->x1()); write16(os, dirty->x1());
write16(os, dirty->y1()); write16(os, dirty->y1());
write16(os, dirty->x2()); write16(os, dirty->x2());
@ -73,12 +73,12 @@ void write_dirty(std::ostream& os, Dirty* dirty)
Dirty* read_dirty(std::istream& is) Dirty* read_dirty(std::istream& is)
{ {
int u, v, x, y, w; int u, v, x, y, w;
int imgtype = read8(is); int pixelFormat = read8(is);
int x1 = read16(is); int x1 = read16(is);
int y1 = read16(is); int y1 = read16(is);
int x2 = read16(is); int x2 = read16(is);
int y2 = read16(is); int y2 = read16(is);
UniquePtr<Dirty> dirty(new Dirty(imgtype, x1, y1, x2, y2)); UniquePtr<Dirty> dirty(new Dirty(static_cast<PixelFormat>(pixelFormat), x1, y1, x2, y2));
int noRows = read16(is); int noRows = read16(is);
if (noRows > 0) { if (noRows > 0) {

View File

@ -32,10 +32,10 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
Image::Image(int imgtype, int w, int h) Image::Image(PixelFormat format, int w, int h)
: GfxObj(GFXOBJ_IMAGE) : GfxObj(GFXOBJ_IMAGE)
, m_format(format)
{ {
this->imgtype = imgtype;
this->w = w; this->w = w;
this->h = h; this->h = h;
this->dat = NULL; this->dat = NULL;
@ -53,7 +53,7 @@ int Image::getMemSize() const
{ {
int scanline_size = 0; int scanline_size = 0;
if (imgtype == IMAGE_BITMAP) if (m_format == IMAGE_BITMAP)
scanline_size = BitmapTraits::scanline_size(this->w); scanline_size = BitmapTraits::scanline_size(this->w);
else else
scanline_size = image_line_size(this, this->w); scanline_size = image_line_size(this, this->w);
@ -61,11 +61,10 @@ int Image::getMemSize() const
return sizeof(Image) + scanline_size*this->h; return sizeof(Image) + scanline_size*this->h;
} }
////////////////////////////////////////////////////////////////////// // static
Image* Image::create(PixelFormat format, int w, int h)
Image* Image::create(int imgtype, int w, int h)
{ {
switch (imgtype) { switch (format) {
case IMAGE_RGB: return new ImageImpl<RgbTraits>(w, h); case IMAGE_RGB: return new ImageImpl<RgbTraits>(w, h);
case IMAGE_GRAYSCALE: return new ImageImpl<GrayscaleTraits>(w, h); case IMAGE_GRAYSCALE: return new ImageImpl<GrayscaleTraits>(w, h);
case IMAGE_INDEXED: return new ImageImpl<IndexedTraits>(w, h); case IMAGE_INDEXED: return new ImageImpl<IndexedTraits>(w, h);
@ -74,6 +73,7 @@ Image* Image::create(int imgtype, int w, int h)
return NULL; return NULL;
} }
// static
Image* Image::createCopy(const Image* image) Image* Image::createCopy(const Image* image)
{ {
ASSERT(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 (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"); 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; trim->mask_color = image->mask_color;
image_clear(trim, bgcolor); image_clear(trim, bgcolor);
@ -360,7 +360,7 @@ void image_fixup_transparent_colors(Image* image)
{ {
int x, y, u, v; int x, y, u, v;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: { case IMAGE_RGB: {
uint32_t c; uint32_t c;
@ -518,7 +518,7 @@ void image_resize(const Image* src, Image* dst, ResizeMethod method, const Palet
double u2 = 1 - u1; double u2 = 1 - u1;
double v2 = 1 - v1; double v2 = 1 - v1;
switch (dst->imgtype) { switch (dst->getPixelFormat()) {
case IMAGE_RGB: { case IMAGE_RGB: {
int r = ((_rgba_getr(color[0])*u2 + _rgba_getr(color[1])*u1)*v2 + int r = ((_rgba_getr(color[0])*u2 + _rgba_getr(color[1])*u1)*v2 +
(_rgba_getr(color[2])*u2 + _rgba_getr(color[3])*u1)*v1); (_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; 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; return -1;
size = i1->w * i1->h; size = i1->w * i1->h;
switch (i1->imgtype) { switch (i1->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
{ {

View File

@ -19,23 +19,17 @@
#ifndef RASTER_IMAGE_H_INCLUDED #ifndef RASTER_IMAGE_H_INCLUDED
#define RASTER_IMAGE_H_INCLUDED #define RASTER_IMAGE_H_INCLUDED
#include <allegro/color.h>
#include "raster/gfxobj.h"
#include "raster/blend.h" #include "raster/blend.h"
#include "raster/gfxobj.h"
#include "raster/pixel_format.h"
#include <allegro/color.h>
class Palette; class Palette;
class Pen; class Pen;
class RgbMap; class RgbMap;
// Image Types
enum {
IMAGE_RGB,
IMAGE_GRAYSCALE,
IMAGE_INDEXED,
IMAGE_BITMAP
};
enum ResizeMethod { enum ResizeMethod {
RESIZE_METHOD_NEAREST_NEIGHBOR, RESIZE_METHOD_NEAREST_NEIGHBOR,
RESIZE_METHOD_BILINEAR, RESIZE_METHOD_BILINEAR,
@ -46,18 +40,19 @@ struct BITMAP;
class Image : public GfxObj class Image : public GfxObj
{ {
public: public:
int imgtype;
int w, h; int w, h;
uint8_t* dat; // Pixmap data. uint8_t* dat; // Pixmap data.
uint8_t** line; // Start of each scanline. uint8_t** line; // Start of each scanline.
uint32_t mask_color; // Skipped color in merge process. 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); static Image* createCopy(const Image* image);
Image(int imgtype, int w, int h); Image(PixelFormat format, int w, int h);
virtual ~Image(); virtual ~Image();
PixelFormat getPixelFormat() const { return m_format; }
int getMemSize() const; int getMemSize() const;
virtual int getpixel(int x, int y) const = 0; 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 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 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; virtual void to_allegro(BITMAP* bmp, int x, int y, const Palette* palette) const = 0;
private:
PixelFormat m_format;
}; };
void image_free(Image* image); 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); 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); 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: return ((pixelFormat == IMAGE_RGB)? 2:
(imgtype == IMAGE_GRAYSCALE)? 1: 0); (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) inline int image_shift(const Image* image)
{ {
return imgtype_shift(image->imgtype); return pixelformat_shift(image->getPixelFormat());
}
inline int imgtype_line_size(int imgtype, int width)
{
return (width << imgtype_shift(imgtype));
} }
inline int image_line_size(const Image* image, int width) inline int image_line_size(const Image* image, int width)

View File

@ -52,7 +52,7 @@ public: // raw access to pixel-data
public: public:
ImageImpl(int w, int h) ImageImpl(int w, int h)
: Image(Traits::imgtype, w, h) : Image(static_cast<PixelFormat>(Traits::pixel_format), w, h)
{ {
int bytes_per_line = Traits::scanline_size(w); int bytes_per_line = Traits::scanline_size(w);

View File

@ -45,7 +45,7 @@ using namespace base::serialization::little_endian;
void write_image(std::ostream& os, Image* image) 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->w); // Width
write16(os, image->h); // Height write16(os, image->h); // Height
write32(os, image->mask_color); // Mask color 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) Image* read_image(std::istream& is)
{ {
int imgtype = read8(is); // Imgtype int pixelFormat = read8(is); // Pixel format
int width = read16(is); // Width int width = read16(is); // Width
int height = read16(is); // Height int height = read16(is); // Height
uint32_t maskColor = read32(is); // Mask color uint32_t maskColor = read32(is); // Mask color
UniquePtr<Image> image(Image::create(imgtype, width, height)); UniquePtr<Image> image(Image::create(static_cast<PixelFormat>(pixelFormat), width, height));
int size = image_line_size(image, image->w); int size = image_line_size(image, image->w);
for (int c=0; c<image->h; c++) for (int c=0; c<image->h; c++)

View File

@ -58,7 +58,7 @@ inline uint32_t _rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
struct RgbTraits struct RgbTraits
{ {
enum { enum {
imgtype = IMAGE_RGB, pixel_format = IMAGE_RGB,
bits_per_pixel = 32, bits_per_pixel = 32,
bytes_per_pixel = 4, bytes_per_pixel = 4,
channels = 4, channels = 4,
@ -107,7 +107,7 @@ inline uint16_t _graya(uint8_t v, uint8_t a)
struct GrayscaleTraits struct GrayscaleTraits
{ {
enum { enum {
imgtype = IMAGE_GRAYSCALE, pixel_format = IMAGE_GRAYSCALE,
bits_per_pixel = 16, bits_per_pixel = 16,
bytes_per_pixel = 2, bytes_per_pixel = 2,
channels = 2, channels = 2,
@ -137,7 +137,7 @@ struct GrayscaleTraits
struct IndexedTraits struct IndexedTraits
{ {
enum { enum {
imgtype = IMAGE_INDEXED, pixel_format = IMAGE_INDEXED,
bits_per_pixel = 8, bits_per_pixel = 8,
bytes_per_pixel = 1, bytes_per_pixel = 1,
channels = 1, channels = 1,
@ -161,7 +161,7 @@ struct IndexedTraits
struct BitmapTraits struct BitmapTraits
{ {
enum { enum {
imgtype = IMAGE_BITMAP, pixel_format = IMAGE_BITMAP,
bits_per_pixel = 1, bits_per_pixel = 1,
bytes_per_pixel = 1, bytes_per_pixel = 1,
channels = 1, channels = 1,

View File

@ -324,7 +324,7 @@ LayerImage* layer_new_flatten_copy(Sprite* dst_sprite, const Layer* src_layer,
// Does this frame have cels to render? // Does this frame have cels to render?
if (has_cels(src_layer, frame)) { if (has_cels(src_layer, frame)) {
// Create a new image // Create a new image
Image* image = Image::create(flatLayer->getSprite()->getImgType(), w, h); Image* image = Image::create(flatLayer->getSprite()->getPixelFormat(), w, h);
try { try {
// Create the new cel for the output layer (add the image to stock too). // Create the new cel for the output layer (add the image to stock too).

View File

@ -206,7 +206,7 @@ void Mask::byColor(const Image *src, int color, int fuzziness)
Image* dst = m_bitmap; Image* dst = m_bitmap;
switch (src->imgtype) { switch (src->getPixelFormat()) {
case IMAGE_RGB: { case IMAGE_RGB: {
uint32_t* src_address; uint32_t* src_address;

View File

@ -330,7 +330,7 @@ static void art_image_svp_aa (const ArtSVP *svp,
{ {
ArtBitmapSVPData data; ArtBitmapSVPData data;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
data.shift = 2; data.shift = 2;

View File

@ -16,30 +16,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED #ifndef RASTER_PIXEL_FORMAT_H_INCLUDED
#define UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED #define RASTER_PIXEL_FORMAT_H_INCLUDED
#include "undo/object_id.h" enum PixelFormat {
#include "undoers/undoer_base.h" IMAGE_RGB,
IMAGE_GRAYSCALE,
class Sprite; IMAGE_INDEXED,
IMAGE_BITMAP
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
#endif // UNDOERS_SET_SPRITE_IMGTYPE_H_INCLUDED

View File

@ -55,7 +55,7 @@ Palette* quantization::create_palette_from_rgb(const Sprite* sprite)
false); // forWrite=false, read only false); // forWrite=false, read only
// Add a flat image with the current sprite's frame rendered // 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); image_clear(flat_image, 0);
sprite->render(flat_image, 0, 0); sprite->render(flat_image, 0, 0);
@ -75,11 +75,12 @@ Palette* quantization::create_palette_from_rgb(const Sprite* sprite)
return palette; return palette;
} }
Image* quantization::convert_imgtype(const Image* image, int imgtype, Image* quantization::convert_pixel_format(const Image* image,
DitheringMethod ditheringMethod, PixelFormat pixelFormat,
const RgbMap* rgbmap, DitheringMethod ditheringMethod,
const Palette* palette, const RgbMap* rgbmap,
bool has_background_layer) const Palette* palette,
bool has_background_layer)
{ {
uint32_t* rgb_address; uint32_t* rgb_address;
uint16_t* gray_address; uint16_t* gray_address;
@ -89,27 +90,27 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype,
Image *new_image; Image *new_image;
// no convertion // no convertion
if (image->imgtype == imgtype) if (image->getPixelFormat() == pixelFormat)
return NULL; return NULL;
// RGB -> Indexed with ordered dithering // RGB -> Indexed with ordered dithering
else if (image->imgtype == IMAGE_RGB && else if (image->getPixelFormat() == IMAGE_RGB &&
imgtype == IMAGE_INDEXED && pixelFormat == IMAGE_INDEXED &&
ditheringMethod == DITHERING_ORDERED) { ditheringMethod == DITHERING_ORDERED) {
return ordered_dithering(image, 0, 0, rgbmap, palette); 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) if (!new_image)
return NULL; return NULL;
size = image->w*image->h; size = image->w*image->h;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
rgb_address = (uint32_t*)image->dat; rgb_address = (uint32_t*)image->dat;
switch (new_image->imgtype) { switch (new_image->getPixelFormat()) {
// RGB -> Grayscale // RGB -> Grayscale
case IMAGE_GRAYSCALE: case IMAGE_GRAYSCALE:
@ -149,7 +150,7 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype,
case IMAGE_GRAYSCALE: case IMAGE_GRAYSCALE:
gray_address = (uint16_t*)image->dat; gray_address = (uint16_t*)image->dat;
switch (new_image->imgtype) { switch (new_image->getPixelFormat()) {
// Grayscale -> RGB // Grayscale -> RGB
case IMAGE_RGB: case IMAGE_RGB:
@ -182,7 +183,7 @@ Image* quantization::convert_imgtype(const Image* image, int imgtype,
case IMAGE_INDEXED: case IMAGE_INDEXED:
idx_address = image->dat; idx_address = image->dat;
switch (new_image->imgtype) { switch (new_image->getPixelFormat()) {
// Indexed -> RGB // Indexed -> RGB
case IMAGE_RGB: case IMAGE_RGB:

View File

@ -20,6 +20,7 @@
#define RASTER_QUANTIZATION_H_INCLUDED #define RASTER_QUANTIZATION_H_INCLUDED
#include "raster/dithering_method.h" #include "raster/dithering_method.h"
#include "raster/pixel_format.h"
class Image; class Image;
class Palette; class Palette;
@ -32,13 +33,14 @@ namespace quantization {
// Creates a new palette suitable to quantize the given RGB sprite to Indexed color. // Creates a new palette suitable to quantize the given RGB sprite to Indexed color.
Palette* create_palette_from_rgb(const Sprite* sprite); Palette* create_palette_from_rgb(const Sprite* sprite);
// Changes the "imgtype" of the image. The dithering method is used // Changes the image pixel format. The dithering method is used only
// only when you want to convert from RGB to Indexed. // when you want to convert from RGB to Indexed.
Image* convert_imgtype(const Image* image, int imgtype, Image* convert_pixel_format(const Image* image,
DitheringMethod ditheringMethod, PixelFormat pixelFormat,
const RgbMap* rgbmap, DitheringMethod ditheringMethod,
const Palette* palette, const RgbMap* rgbmap,
bool has_background_layer); const Palette* palette,
bool has_background_layer);
} }

View File

@ -57,16 +57,16 @@ void image_scale(Image *dst, Image *src, int x, int y, int w, int h)
BLEND_COLOR blender = NULL; BLEND_COLOR blender = NULL;
int u, v, c; int u, v, c;
if (dst->imgtype == IMAGE_RGB) if (dst->getPixelFormat() == IMAGE_RGB)
blender = _rgba_blenders[BLEND_MODE_NORMAL]; blender = _rgba_blenders[BLEND_MODE_NORMAL];
else if (dst->imgtype == IMAGE_GRAYSCALE) else if (dst->getPixelFormat() == IMAGE_GRAYSCALE)
blender = _graya_blenders[BLEND_MODE_NORMAL]; blender = _graya_blenders[BLEND_MODE_NORMAL];
for (v=0; v<h; v++) { for (v=0; v<h; v++) {
for (u=0; u<w; u++) { for (u=0; u<w; u++) {
c = image_getpixel (src, src->w*u/w, src->h*v/h); c = image_getpixel (src, src->w*u/w, src->h*v/h);
switch (dst->imgtype) { switch (dst->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
case IMAGE_GRAYSCALE: 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, static void ase_parallelogram_map_standard(Image *bmp, Image *sprite,
fixed xs[4], fixed ys[4]) fixed xs[4], fixed ys[4])
{ {
switch (bmp->imgtype) { switch (bmp->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
ase_parallelogram_map<RgbTraits, RgbDelegate>(bmp, sprite, xs, ys, false); ase_parallelogram_map<RgbTraits, RgbDelegate>(bmp, sprite, xs, ys, false);

View File

@ -33,9 +33,9 @@ static int layer2index(const Layer* layer, const Layer* find_layer, int* index_c
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Constructors/Destructor // 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) : GfxObj(GFXOBJ_SPRITE)
, m_imgtype(imgtype) , m_format(format)
, m_width(width) , m_width(width)
, m_height(height) , m_height(height)
{ {
@ -44,14 +44,14 @@ Sprite::Sprite(int imgtype, int width, int height, int ncolors)
m_frames = 1; m_frames = 1;
m_frlens.push_back(100); // First frame with 100 msecs of duration m_frlens.push_back(100); // First frame with 100 msecs of duration
m_frame = 0; m_frame = 0;
m_stock = new Stock(imgtype); m_stock = new Stock(format);
m_folder = new LayerFolder(this); m_folder = new LayerFolder(this);
m_layer = NULL; m_layer = NULL;
// Generate palette // Generate palette
Palette pal(0, ncolors); Palette pal(0, ncolors);
switch (imgtype) { switch (format) {
// For colored images // For colored images
case IMAGE_RGB: case IMAGE_RGB:
@ -103,9 +103,9 @@ Sprite::~Sprite()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Main properties // 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) void Sprite::setSize(int width, int height)
@ -119,7 +119,7 @@ void Sprite::setSize(int width, int height)
bool Sprite::needAlpha() const bool Sprite::needAlpha() const
{ {
switch (m_imgtype) { switch (m_format) {
case IMAGE_RGB: case IMAGE_RGB:
case IMAGE_GRAYSCALE: case IMAGE_GRAYSCALE:
return (getBackgroundLayer() == NULL); return (getBackgroundLayer() == NULL);
@ -375,7 +375,7 @@ void Sprite::getCels(CelList& cels)
void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping) void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t>& mapping)
{ {
ASSERT(m_imgtype == IMAGE_INDEXED); ASSERT(m_format == IMAGE_INDEXED);
ASSERT(mapping.size() == 256); ASSERT(mapping.size() == 256);
CelList cels; CelList cels;
@ -404,7 +404,7 @@ void Sprite::remapImages(int frame_from, int frame_to, const std::vector<uint8_t
void Sprite::render(Image* image, int x, int y) const void Sprite::render(Image* image, int x, int y) const
{ {
image_rectfill(image, x, y, x+m_width-1, y+m_height-1, image_rectfill(image, x, y, x+m_width-1, y+m_height-1,
(m_imgtype == IMAGE_INDEXED ? getTransparentColor(): 0)); (m_format == IMAGE_INDEXED ? getTransparentColor(): 0));
layer_render(getFolder(), image, x, y, getCurrentFrame()); layer_render(getFolder(), image, x, y, getCurrentFrame());
} }
@ -414,8 +414,8 @@ int Sprite::getPixel(int x, int y) const
int color = 0; int color = 0;
if ((x >= 0) && (y >= 0) && (x < m_width) && (y < m_height)) { if ((x >= 0) && (y >= 0) && (x < m_width) && (y < m_height)) {
Image* image = Image::create(m_imgtype, 1, 1); Image* image = Image::create(m_format, 1, 1);
image_clear(image, (m_imgtype == IMAGE_INDEXED ? getTransparentColor(): 0)); image_clear(image, (m_format == IMAGE_INDEXED ? getTransparentColor(): 0));
render(image, -x, -y); render(image, -x, -y);
color = image_getpixel(image, 0, 0); color = image_getpixel(image, 0, 0);
image_free(image); image_free(image);

View File

@ -21,6 +21,7 @@
#include "base/disable_copying.h" #include "base/disable_copying.h"
#include "raster/gfxobj.h" #include "raster/gfxobj.h"
#include "raster/pixel_format.h"
#include <vector> #include <vector>
@ -45,14 +46,14 @@ public:
//////////////////////////////////////// ////////////////////////////////////////
// Constructors/Destructor // Constructors/Destructor
Sprite(int imgtype, int width, int height, int ncolors); Sprite(PixelFormat format, int width, int height, int ncolors);
virtual ~Sprite(); virtual ~Sprite();
//////////////////////////////////////// ////////////////////////////////////////
// Main properties // Main properties
int getImgType() const { return m_imgtype; } PixelFormat getPixelFormat() const { return m_format; }
void setImgType(int imgtype); void setPixelFormat(PixelFormat format);
int getWidth() const { return m_width; } int getWidth() const { return m_width; }
int getHeight() const { return m_height; } int getHeight() const { return m_height; }
@ -140,7 +141,7 @@ public:
private: private:
Sprite* m_self; // pointer to the Sprite 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_width; // image width (in pixels)
int m_height; // image height (in pixels) int m_height; // image height (in pixels)
int m_frames; // how many frames has this sprite int m_frames; // how many frames has this sprite

View File

@ -23,20 +23,18 @@
#include "raster/image.h" #include "raster/image.h"
#include "raster/stock.h" #include "raster/stock.h"
Stock::Stock(int imgtype) Stock::Stock(PixelFormat format)
: GfxObj(GFXOBJ_STOCK) : GfxObj(GFXOBJ_STOCK)
, m_format(format)
{ {
m_imgtype = imgtype;
// Image with index=0 is always NULL. // Image with index=0 is always NULL.
m_image.push_back(NULL); m_image.push_back(NULL);
} }
Stock::Stock(const Stock& stock) Stock::Stock(const Stock& stock)
: GfxObj(stock) : GfxObj(stock)
, m_format(stock.getPixelFormat())
{ {
m_imgtype = stock.getImgType();
try { try {
for (int i=0; i<stock.size(); ++i) { for (int i=0; i<stock.size(); ++i) {
if (!stock.getImage(i)) if (!stock.getImage(i))
@ -66,14 +64,14 @@ Stock::~Stock()
} }
} }
int Stock::getImgType() const PixelFormat Stock::getPixelFormat() const
{ {
return m_imgtype; return m_format;
} }
void Stock::setImgType(int imgtype) void Stock::setPixelFormat(PixelFormat pixelFormat)
{ {
m_imgtype = imgtype; m_format = pixelFormat;
} }
Image* Stock::getImage(int index) const Image* Stock::getImage(int index) const

View File

@ -20,6 +20,7 @@
#define RASTER_STOCK_H_INCLUDED #define RASTER_STOCK_H_INCLUDED
#include "raster/gfxobj.h" #include "raster/gfxobj.h"
#include "raster/pixel_format.h"
#include <vector> #include <vector>
class Image; class Image;
@ -29,12 +30,12 @@ typedef std::vector<Image*> ImagesList;
class Stock : public GfxObj class Stock : public GfxObj
{ {
public: public:
Stock(int imgtype); Stock(PixelFormat format);
Stock(const Stock& stock); Stock(const Stock& stock);
virtual ~Stock(); virtual ~Stock();
int getImgType() const; PixelFormat getPixelFormat() const;
void setImgType(int imgtype); void setPixelFormat(PixelFormat format);
// Returns the number of image in the stock. // Returns the number of image in the stock.
int size() const { int size() const {
@ -63,7 +64,7 @@ public:
void replaceImage(int index, Image* image); void replaceImage(int index, Image* image);
//private: TODO uncomment this line //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. ImagesList m_image; // The images-array where the images are.
}; };

View File

@ -65,8 +65,8 @@ public:
} }
m_proc = loop->getOpacity() == 255 ? m_proc = loop->getOpacity() == 255 ?
ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getImgType(), 2)]: ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getPixelFormat(), 2)]:
ink_processing[INK_TRANSPARENT][MID(0, loop->getSprite()->getImgType(), 2)]; ink_processing[INK_TRANSPARENT][MID(0, loop->getSprite()->getPixelFormat(), 2)];
} }
void inkHline(int x1, int y, int x2, ToolLoop* loop) void inkHline(int x1, int y, int x2, ToolLoop* loop)
@ -158,7 +158,7 @@ public:
switch (m_type) { switch (m_type) {
case Eraser: 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 // TODO app_get_color_to_clear_layer should receive the context as parameter
loop->setPrimaryColor(app_get_color_to_clear_layer(loop->getLayer())); loop->setPrimaryColor(app_get_color_to_clear_layer(loop->getLayer()));
@ -166,7 +166,7 @@ public:
break; break;
case ReplaceFgWithBg: 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->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getFgColor(),
loop->getLayer())); loop->getLayer()));
@ -175,7 +175,7 @@ public:
break; break;
case ReplaceBgWithFg: 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->setPrimaryColor(color_utils::color_for_layer(loop->getContext()->getSettings()->getBgColor(),
loop->getLayer())); loop->getLayer()));
@ -202,7 +202,7 @@ public:
void prepareInk(ToolLoop* loop) 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) void inkHline(int x1, int y, int x2, ToolLoop* loop)
@ -222,7 +222,7 @@ public:
void prepareInk(ToolLoop* loop) 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) void inkHline(int x1, int y, int x2, ToolLoop* loop)

View File

@ -83,7 +83,7 @@ void UIContext::onSetActiveDocument(Document* document)
app_get_tabsbar()->selectTab(document); app_get_tabsbar()->selectTab(document);
// Change the image-type of color bar. // 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. // Change the main frame title.
base::string defaultTitle = PACKAGE " v" VERSION; base::string defaultTitle = PACKAGE " v" VERSION;

View File

@ -56,9 +56,9 @@
#include "undoers/set_layer_name.h" #include "undoers/set_layer_name.h"
#include "undoers/set_mask.h" #include "undoers/set_mask.h"
#include "undoers/set_mask_position.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_sprite_size.h"
#include "undoers/set_stock_imgtype.h" #include "undoers/set_stock_pixel_format.h"
#include "undoers/set_total_frames.h" #include "undoers/set_total_frames.h"
UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification) UndoTransaction::UndoTransaction(Document* document, const char* label, undo::Modification modification)
@ -210,7 +210,7 @@ void UndoTransaction::autocropSprite(int bgcolor)
x1 = y1 = INT_MAX; x1 = y1 = INT_MAX;
x2 = y2 = INT_MIN; x2 = y2 = INT_MIN;
Image* image = Image::create(m_sprite->getImgType(), Image* image = Image::create(m_sprite->getPixelFormat(),
m_sprite->getWidth(), m_sprite->getWidth(),
m_sprite->getHeight()); m_sprite->getHeight());
@ -239,20 +239,20 @@ void UndoTransaction::autocropSprite(int bgcolor)
cropSprite(gfx::Rect(x1, y1, x2-x1+1, y2-y1+1), 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 *old_image;
Image *new_image; Image *new_image;
int c; int c;
if (m_sprite->getImgType() == new_imgtype) if (m_sprite->getPixelFormat() == newFormat)
return; return;
// Change imgtype of the stock of images. // Change pixel format of the stock of images.
if (isEnabled()) 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 // Use the rgbmap for the specified sprite
const RgbMap* rgbmap = m_sprite->getRgbMap(); const RgbMap* rgbmap = m_sprite->getRgbMap();
@ -262,25 +262,25 @@ void UndoTransaction::setImgType(int new_imgtype, DitheringMethod dithering_meth
if (!old_image) if (!old_image)
continue; continue;
new_image = quantization::convert_imgtype(old_image, new_imgtype, dithering_method, rgbmap, new_image = quantization::convert_pixel_format(old_image, newFormat, dithering_method, rgbmap,
// TODO check this out // TODO check this out
m_sprite->getCurrentPalette(), m_sprite->getCurrentPalette(),
m_sprite->getBackgroundLayer() != NULL); m_sprite->getBackgroundLayer() != NULL);
this->replaceStockImage(c, new_image); this->replaceStockImage(c, new_image);
} }
// Change sprite's "imgtype" field. // Change sprite's pixel format.
if (isEnabled()) 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 // Regenerate extras
m_document->destroyExtraCel(); m_document->destroyExtraCel();
// change "sprite.palette" // change "sprite.palette"
if (new_imgtype == IMAGE_GRAYSCALE) { if (newFormat == IMAGE_GRAYSCALE) {
if (isEnabled()) { if (isEnabled()) {
// Save all palettes // Save all palettes
PalettesList palettes = m_sprite->getPalettes(); 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 // create a temporary image to draw each frame of the new
// `Background' layer // `Background' layer
UniquePtr<Image> bg_image_wrap(Image::create(m_sprite->getImgType(), UniquePtr<Image> bg_image_wrap(Image::create(m_sprite->getPixelFormat(),
m_sprite->getWidth(), m_sprite->getWidth(),
m_sprite->getHeight())); m_sprite->getHeight()));
Image* bg_image = bg_image_wrap.get(); Image* bg_image = bg_image_wrap.get();
@ -517,7 +517,7 @@ void UndoTransaction::backgroundFromLayer(LayerImage* layer, int bgcolor)
for (int frame=0; frame<m_sprite->getTotalFrames(); frame++) { for (int frame=0; frame<m_sprite->getTotalFrames(); frame++) {
Cel* cel = layer->getCel(frame); Cel* cel = layer->getCel(frame);
if (!cel) { 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); image_clear(cel_image, bgcolor);
// Add the new image in the stock // Add the new image in the stock
@ -558,7 +558,7 @@ void UndoTransaction::flattenLayers(int bgcolor)
int frame; int frame;
// create a temporary image // create a temporary image
UniquePtr<Image> image_wrap(Image::create(m_sprite->getImgType(), UniquePtr<Image> image_wrap(Image::create(m_sprite->getPixelFormat(),
m_sprite->getWidth(), m_sprite->getWidth(),
m_sprite->getHeight())); m_sprite->getHeight()));
Image* image = image_wrap.get(); Image* image = image_wrap.get();

View File

@ -21,6 +21,7 @@
#include "gfx/rect.h" #include "gfx/rect.h"
#include "raster/dithering_method.h" #include "raster/dithering_method.h"
#include "raster/pixel_format.h"
#include "undo/modification.h" #include "undo/modification.h"
class Cel; class Cel;
@ -78,7 +79,7 @@ public:
void setSpriteSize(int w, int h); void setSpriteSize(int w, int h);
void cropSprite(const gfx::Rect& bounds, int bgcolor); void cropSprite(const gfx::Rect& bounds, int bgcolor);
void autocropSprite(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 // for images in stock
int addImageInStock(Image* image); int addImageInStock(Image* image);

View File

@ -31,7 +31,7 @@ using namespace undoers;
FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, int flipFlags) FlipImage::FlipImage(ObjectsContainer* objects, Image* image, int x, int y, int w, int h, int flipFlags)
: m_imageId(objects->addObject(image)) : 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_x(x), m_y(y), m_w(w), m_h(h)
, m_flipFlags(flipFlags) , m_flipFlags(flipFlags)
{ {
@ -48,7 +48,7 @@ void FlipImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{ {
Image* image = objects->getObjectT<Image>(m_imageId); Image* image = objects->getObjectT<Image>(m_imageId);
if (image->imgtype != m_imgtype) if (image->getPixelFormat() != m_format)
throw UndoException("Image type does not match"); throw UndoException("Image type does not match");
redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipFlags)); redoers->pushUndoer(new FlipImage(objects, image, m_x, m_y, m_w, m_h, m_flipFlags));

View File

@ -39,7 +39,7 @@ public:
private: private:
undo::ObjectId m_imageId; undo::ObjectId m_imageId;
uint8_t m_imgtype; uint8_t m_format;
uint16_t m_x, m_y, m_w, m_h; uint16_t m_x, m_y, m_w, m_h;
uint8_t m_flipFlags; uint8_t m_flipFlags;
}; };

View File

@ -30,7 +30,7 @@ using namespace undoers;
ImageArea::ImageArea(ObjectsContainer* objects, Image* image, int x, int y, int w, int h) ImageArea::ImageArea(ObjectsContainer* objects, Image* image, int x, int y, int w, int h)
: m_imageId(objects->addObject(image)) : 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_x(x), m_y(y), m_w(w), m_h(h)
, m_lineSize(image_line_size(image, w)) , m_lineSize(image_line_size(image, w))
, m_data(m_lineSize * h) , m_data(m_lineSize * h)
@ -51,7 +51,7 @@ void ImageArea::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{ {
Image* image = objects->getObjectT<Image>(m_imageId); Image* image = objects->getObjectT<Image>(m_imageId);
if (image->imgtype != m_imgtype) if (image->getPixelFormat() != m_format)
throw UndoException("Image type does not match"); throw UndoException("Image type does not match");
// Backup the current image portion // Backup the current image portion

View File

@ -39,7 +39,7 @@ public:
private: private:
undo::ObjectId m_imageId; undo::ObjectId m_imageId;
uint8_t m_imgtype; uint8_t m_format;
uint16_t m_x, m_y, m_w, m_h; uint16_t m_x, m_y, m_w, m_h;
uint32_t m_lineSize; uint32_t m_lineSize;
std::vector<uint8_t> m_data; std::vector<uint8_t> m_data;

View File

@ -18,7 +18,7 @@
#include "config.h" #include "config.h"
#include "undoers/set_sprite_imgtype.h" #include "undoers/set_sprite_pixel_format.h"
#include "raster/sprite.h" #include "raster/sprite.h"
#include "undo/objects_container.h" #include "undo/objects_container.h"
@ -27,23 +27,23 @@
using namespace undo; using namespace undo;
using namespace undoers; using namespace undoers;
SetSpriteImgType::SetSpriteImgType(ObjectsContainer* objects, Sprite* sprite) SetSpritePixelFormat::SetSpritePixelFormat(ObjectsContainer* objects, Sprite* sprite)
: m_spriteId(objects->addObject(sprite)) : m_spriteId(objects->addObject(sprite))
, m_imgtype(sprite->getImgType()) , m_format(sprite->getPixelFormat())
{ {
} }
void SetSpriteImgType::dispose() void SetSpritePixelFormat::dispose()
{ {
delete this; delete this;
} }
void SetSpriteImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers) void SetSpritePixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{ {
Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId); Sprite* sprite = objects->getObjectT<Sprite>(m_spriteId);
// Push another SetSpriteImgType as redoer // Push another SetSpritePixelFormat as redoer
redoers->pushUndoer(new SetSpriteImgType(objects, sprite)); redoers->pushUndoer(new SetSpritePixelFormat(objects, sprite));
sprite->setImgType(m_imgtype); sprite->setPixelFormat(static_cast<PixelFormat>(m_format));
} }

View File

@ -16,8 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UNDOERS_SET_IMGTYPE_H_INCLUDED #ifndef UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED
#define UNDOERS_SET_IMGTYPE_H_INCLUDED #define UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED
#include "undo/object_id.h" #include "undo/object_id.h"
#include "undoers/undoer_base.h" #include "undoers/undoer_base.h"
@ -26,10 +26,10 @@ class Sprite;
namespace undoers { namespace undoers {
class SetImgType : public UndoerBase class SetSpritePixelFormat : public UndoerBase
{ {
public: public:
SetImgType(undo::ObjectsContainer* objects, Sprite* sprite); SetSpritePixelFormat(undo::ObjectsContainer* objects, Sprite* sprite);
void dispose() OVERRIDE; void dispose() OVERRIDE;
int getMemSize() const OVERRIDE { return sizeof(*this); } int getMemSize() const OVERRIDE { return sizeof(*this); }
@ -37,9 +37,9 @@ public:
private: private:
undo::ObjectId m_spriteId; undo::ObjectId m_spriteId;
uint32_t m_imgtype; uint32_t m_format;
}; };
} // namespace undoers } // namespace undoers
#endif // UNDOERS_SET_IMGTYPE_H_INCLUDED #endif // UNDOERS_SET_SPRITE_PIXEL_FORMAT_H_INCLUDED

View File

@ -18,7 +18,7 @@
#include "config.h" #include "config.h"
#include "undoers/set_stock_imgtype.h" #include "undoers/set_stock_pixel_format.h"
#include "raster/stock.h" #include "raster/stock.h"
#include "undo/objects_container.h" #include "undo/objects_container.h"
@ -27,23 +27,23 @@
using namespace undo; using namespace undo;
using namespace undoers; using namespace undoers;
SetStockImgType::SetStockImgType(ObjectsContainer* objects, Stock* stock) SetStockPixelFormat::SetStockPixelFormat(ObjectsContainer* objects, Stock* stock)
: m_stockId(objects->addObject(stock)) : m_stockId(objects->addObject(stock))
, m_imgtype(stock->getImgType()) , m_format(stock->getPixelFormat())
{ {
} }
void SetStockImgType::dispose() void SetStockPixelFormat::dispose()
{ {
delete this; delete this;
} }
void SetStockImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers) void SetStockPixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{ {
Stock* stock = objects->getObjectT<Stock>(m_stockId); Stock* stock = objects->getObjectT<Stock>(m_stockId);
// Push another SetStockImgType as redoer // Push another SetStockPixelFormat as redoer
redoers->pushUndoer(new SetStockImgType(objects, stock)); redoers->pushUndoer(new SetStockPixelFormat(objects, stock));
stock->setImgType(m_imgtype); stock->setPixelFormat(static_cast<PixelFormat>(m_format));
} }

View File

@ -16,8 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED #ifndef UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED
#define UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED #define UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED
#include "undo/object_id.h" #include "undo/object_id.h"
#include "undoers/undoer_base.h" #include "undoers/undoer_base.h"
@ -26,10 +26,10 @@ class Stock;
namespace undoers { namespace undoers {
class SetStockImgType : public UndoerBase class SetStockPixelFormat : public UndoerBase
{ {
public: public:
SetStockImgType(undo::ObjectsContainer* objects, Stock* stock); SetStockPixelFormat(undo::ObjectsContainer* objects, Stock* stock);
void dispose() OVERRIDE; void dispose() OVERRIDE;
int getMemSize() const OVERRIDE { return sizeof(*this); } int getMemSize() const OVERRIDE { return sizeof(*this); }
@ -37,9 +37,9 @@ public:
private: private:
undo::ObjectId m_stockId; undo::ObjectId m_stockId;
uint32_t m_imgtype; uint32_t m_format;
}; };
} // namespace undoers } // namespace undoers
#endif // UNDOERS_SET_STOCK_IMGTYPE_H_INCLUDED #endif // UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED

View File

@ -186,13 +186,14 @@ void clipboard::paste()
// Source image (clipboard or a converted copy to the destination 'imgtype') // Source image (clipboard or a converted copy to the destination 'imgtype')
Image* src_image; Image* src_image;
if (clipboard_image->imgtype == sprite->getImgType()) if (clipboard_image->getPixelFormat() == sprite->getPixelFormat())
src_image = clipboard_image; src_image = clipboard_image;
else { else {
RgbMap* rgbmap = sprite->getRgbMap(); RgbMap* rgbmap = sprite->getRgbMap();
src_image = quantization::convert_imgtype(clipboard_image, sprite->getImgType(), DITHERING_NONE, src_image = quantization::convert_pixel_format(clipboard_image,
rgbmap, sprite->getPalette(sprite->getCurrentFrame()), sprite->getPixelFormat(), DITHERING_NONE,
false); rgbmap, sprite->getPalette(sprite->getCurrentFrame()),
false);
} }
// Change to MovingPixelsState // Change to MovingPixelsState

View File

@ -64,7 +64,7 @@ static void set_win32_clipboard_bitmap(Image* image, Palette* palette)
int color_depth = 0; int color_depth = 0;
int palette_entries = 0; int palette_entries = 0;
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
scanline = sizeof(uint32_t) * image->w; scanline = sizeof(uint32_t) * image->w;
color_depth = 32; 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; bi->bV5ClrUsed = palette_entries == 256 ? 0: palette_entries;
// write pixels // write pixels
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: { case IMAGE_RGB: {
uint32_t* dst = (uint32_t*)(((uint8_t*)bi)+bi->bV5Size); uint32_t* dst = (uint32_t*)(((uint8_t*)bi)+bi->bV5Size);
uint32_t c; uint32_t c;

View File

@ -55,7 +55,7 @@ ExpandCelCanvas::ExpandCelCanvas(Document* document, Sprite* sprite, Layer* laye
// If there is no Cel // If there is no Cel
if (m_cel == NULL) { if (m_cel == NULL) {
// Create the image // 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()); image_clear(m_celImage, sprite->getTransparentColor());
// create the cel // create the cel

View File

@ -53,7 +53,7 @@ Image* NewImageFromMask(const Document* srcDocument)
ASSERT(srcBitmap); ASSERT(srcBitmap);
ASSERT(src); ASSERT(src);
dst = Image::create(srcSprite->getImgType(), srcBounds.w, srcBounds.h); dst = Image::create(srcSprite->getPixelFormat(), srcBounds.w, srcBounds.h);
if (!dst) if (!dst)
return NULL; return NULL;

View File

@ -54,7 +54,7 @@ Mask *load_msk_file(const char *filename)
/* just load an Animator Pro PIC file */ /* just load an Animator Pro PIC file */
image = load_pic_file(filename, &x, &y, NULL); image = load_pic_file(filename, &x, &y, NULL);
if ((!image) || (image->imgtype != IMAGE_BITMAP)) { if ((!image) || (image->getPixelFormat() != IMAGE_BITMAP)) {
if (image) if (image)
image_free(image); image_free(image);
} }

View File

@ -179,9 +179,9 @@ int save_pic_file(const char *filename, int x, int y,
int c, u, v, bpp, size, byte; int c, u, v, bpp, size, byte;
PACKFILE* f; PACKFILE* f;
if (image->imgtype == IMAGE_INDEXED) if (image->getPixelFormat() == IMAGE_INDEXED)
bpp = 8; bpp = 8;
else if (image->imgtype == IMAGE_BITMAP) else if (image->getPixelFormat() == IMAGE_BITMAP)
bpp = 1; bpp = 1;
else else
return -1; return -1;

View File

@ -379,7 +379,7 @@ Image* RenderEngine::renderSprite(const Document* document,
uint32_t bg_color = 0; uint32_t bg_color = 0;
Image *image; Image *image;
switch (sprite->getImgType()) { switch (sprite->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
zoomed_func = merge_zoomed_image<RgbTraits, RgbTraits>; zoomed_func = merge_zoomed_image<RgbTraits, RgbTraits>;
@ -461,8 +461,8 @@ void RenderEngine::renderCheckedBackground(Image* image,
int x, y, u, v; int x, y, u, v;
int tile_w = 16; int tile_w = 16;
int tile_h = 16; int tile_h = 16;
int c1 = color_utils::color_for_image(checked_bg_color1, 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->imgtype); int c2 = color_utils::color_for_image(checked_bg_color2, image->getPixelFormat());
switch (checked_bg_type) { 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); 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: case IMAGE_RGB:
zoomed_func = merge_zoomed_image<RgbTraits, RgbTraits>; zoomed_func = merge_zoomed_image<RgbTraits, RgbTraits>;

View File

@ -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, rectgrid(bmp, 0, 0, bmp->w-1, bmp->h-1,
bmp->w/4, bmp->h/4); bmp->w/4, bmp->h/4);
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
for (y=0; y<h; y++) for (y=0; y<h; y++)
for (x=0; x<w; x++) { for (x=0; x<w; x++) {
@ -177,7 +177,7 @@ static void thumbnail_render(BITMAP* bmp, const Image* image, bool has_alpha, co
else { else {
clear_to_color(bmp, makecol(128, 128, 128)); clear_to_color(bmp, makecol(128, 128, 128));
switch (image->imgtype) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB:
for (y=0; y<h; y++) for (y=0; y<h; y++)
for (x=0; x<w; x++) { for (x=0; x<w; x++) {

View File

@ -144,10 +144,10 @@ ColorBar::~ColorBar()
set_config_color("ColorBar", "BG", getBgColor()); set_config_color("ColorBar", "BG", getBgColor());
} }
void ColorBar::setImgType(int imgtype) void ColorBar::setPixelFormat(PixelFormat pixelFormat)
{ {
m_fgColor.setImgType(imgtype); m_fgColor.setPixelFormat(pixelFormat);
m_bgColor.setImgType(imgtype); m_bgColor.setPixelFormat(pixelFormat);
} }
Color ColorBar::getFgColor() Color ColorBar::getFgColor()

View File

@ -25,6 +25,7 @@
#include "gui/box.h" #include "gui/box.h"
#include "gui/button.h" #include "gui/button.h"
#include "gui/view.h" #include "gui/view.h"
#include "raster/pixel_format.h"
#include "widgets/color_button.h" #include "widgets/color_button.h"
#include "widgets/palette_view.h" #include "widgets/palette_view.h"
@ -37,7 +38,7 @@ public:
ColorBar(int align); ColorBar(int align);
~ColorBar(); ~ColorBar();
void setImgType(int imgtype); void setPixelFormat(PixelFormat pixelFormat);
Color getFgColor(); Color getFgColor();
Color getBgColor(); Color getBgColor();

View File

@ -43,10 +43,10 @@ static int colorbutton_type()
return type; return type;
} }
ColorButton::ColorButton(const Color& color, int imgtype) ColorButton::ColorButton(const Color& color, PixelFormat pixelFormat)
: ButtonBase("", colorbutton_type(), JI_BUTTON, JI_BUTTON) : ButtonBase("", colorbutton_type(), JI_BUTTON, JI_BUTTON)
, m_color(color) , m_color(color)
, m_imgtype(imgtype) , m_pixelFormat(pixelFormat)
, m_frame(NULL) , m_frame(NULL)
{ {
jwidget_focusrest(this, true); jwidget_focusrest(this, true);
@ -59,14 +59,14 @@ ColorButton::~ColorButton()
delete m_frame; // widget, frame delete m_frame; // widget, frame
} }
int ColorButton::getImgType() const PixelFormat ColorButton::getPixelFormat() const
{ {
return m_imgtype; return m_pixelFormat;
} }
void ColorButton::setImgType(int imgtype) void ColorButton::setPixelFormat(PixelFormat pixelFormat)
{ {
m_imgtype = imgtype; m_pixelFormat = pixelFormat;
invalidate(); invalidate();
} }
@ -146,7 +146,7 @@ bool ColorButton::onProcessMessage(Message* msg)
y = msg->mouse.y; y = msg->mouse.y;
editor->screenToEditor(x, y, &x, &y); editor->screenToEditor(x, y, &x, &y);
imgcolor = sprite->getPixel(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(), this->getBounds(),
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
this->m_imgtype, m_pixelFormat,
color, color,
this->hasMouseOver(), false); this->hasMouseOver(), false);
// Draw text // 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()); setTextQuiet(str.c_str());
jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(this, &box, &text, &icon, 0, 0, 0);

View File

@ -23,17 +23,18 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/signal.h" #include "base/signal.h"
#include "gui/button.h" #include "gui/button.h"
#include "raster/pixel_format.h"
class ColorSelector; class ColorSelector;
class ColorButton : public ButtonBase class ColorButton : public ButtonBase
{ {
public: public:
ColorButton(const Color& color, int imgtype); ColorButton(const Color& color, PixelFormat pixelFormat);
~ColorButton(); ~ColorButton();
int getImgType() const; PixelFormat getPixelFormat() const;
void setImgType(int imgtype); void setPixelFormat(PixelFormat pixelFormat);
Color getColor() const; Color getColor() const;
void setColor(const Color& color); void setColor(const Color& color);
@ -53,7 +54,7 @@ private:
void onFrameColorChange(const Color& color); void onFrameColorChange(const Color& color);
Color m_color; Color m_color;
int m_imgtype; PixelFormat m_pixelFormat;
ColorSelector* m_frame; ColorSelector* m_frame;
}; };

View File

@ -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 // 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 // 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; new_mask_color = 1;
} }
else { else {
@ -684,5 +684,5 @@ static int get_pen_color(Sprite *sprite)
if (sprite->getCurrentLayer() != NULL) if (sprite->getCurrentLayer() != NULL)
return color_utils::color_for_layer(c, sprite->getCurrentLayer()); return color_utils::color_for_layer(c, sprite->getCurrentLayer());
else else
return color_utils::color_for_image(c, sprite->getImgType()); return color_utils::color_for_image(c, sprite->getPixelFormat());
} }

View File

@ -397,8 +397,8 @@ void MovingPixelsState::setTransparentColor(const Color& color)
Sprite* sprite = current_editor->getSprite(); Sprite* sprite = current_editor->getSprite();
ASSERT(sprite != NULL); ASSERT(sprite != NULL);
int imgtype = sprite->getImgType(); PixelFormat format = sprite->getPixelFormat();
m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, imgtype)); m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, format));
} }
void MovingPixelsState::dropPixels(Editor* editor) void MovingPixelsState::dropPixels(Editor* editor)

View File

@ -366,7 +366,7 @@ Image* PixelsMovement::getDraggedImageCopy(gfx::Point& origin)
int width = rightBottom.x - leftTop.x; int width = rightBottom.x - leftTop.x;
int height = rightBottom.y - leftTop.y; int height = rightBottom.y - leftTop.y;
UniquePtr<Image> image(Image::create(m_sprite->getImgType(), width, height)); UniquePtr<Image> image(Image::create(m_sprite->getPixelFormat(), width, height));
image_clear(image, image->mask_color); image_clear(image, image->mask_color);
image_parallelogram(image, m_originalImage, image_parallelogram(image, m_originalImage,
corners.leftTop().x-leftTop.x, corners.leftTop().y-leftTop.y, corners.leftTop().x-leftTop.x, corners.leftTop().y-leftTop.y,

View File

@ -450,12 +450,12 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
} }
// For eye-dropper // For eye-dropper
else if (current_tool->getInk(0)->isEyedropper()) { else if (current_tool->getInk(0)->isEyedropper()) {
int imgtype = sprite->getImgType(); PixelFormat format = sprite->getPixelFormat();
uint32_t pixel = sprite->getPixel(x, y); uint32_t pixel = sprite->getPixel(x, y);
Color color = Color::fromImage(imgtype, pixel); Color color = Color::fromImage(format, pixel);
int alpha = 255; int alpha = 255;
switch (imgtype) { switch (format) {
case IMAGE_RGB: alpha = _rgba_geta(pixel); break; case IMAGE_RGB: alpha = _rgba_geta(pixel); break;
case IMAGE_GRAYSCALE: alpha = _graya_geta(pixel); break; case IMAGE_GRAYSCALE: alpha = _graya_geta(pixel); break;
} }

View File

@ -794,7 +794,7 @@ static void monitor_thumbnail_generation(void *_data)
data->palette = new Palette(*sprite->getPalette(0)); data->palette = new Palette(*sprite->getPalette(0));
// Render the 'sprite' in one plain 'image' // 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); sprite->render(image, 0, 0);
// Calculate the thumbnail size // Calculate the thumbnail size
@ -808,7 +808,7 @@ static void monitor_thumbnail_generation(void *_data)
thumb_h = MID(1, thumb_h, MAX_THUMBNAIL_SIZE); thumb_h = MID(1, thumb_h, MAX_THUMBNAIL_SIZE);
// Stretch the 'image' // 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_clear(data->thumbnail, 0);
image_scale(data->thumbnail, image, 0, 0, thumb_w, thumb_h); image_scale(data->thumbnail, image, 0, 0, thumb_w, thumb_h);
image_free(image); image_free(image);

View File

@ -516,13 +516,13 @@ bool StatusBar::onProcessMessage(Message* msg)
draw_color_button(doublebuffer, Rect(x, rc->y1, 32*jguiscale(), rc->y2-rc->y1), draw_color_button(doublebuffer, Rect(x, rc->y1, 32*jguiscale(), rc->y2-rc->y1),
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
app_get_current_image_type(), m_color, app_get_current_pixel_format(), m_color,
false, false); false, false);
x += (32+4)*jguiscale(); x += (32+4)*jguiscale();
// Draw color description // 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) { if (m_alpha < 255) {
char buf[512]; char buf[512];
usprintf(buf, ", Alpha %d", m_alpha); usprintf(buf, ", Alpha %d", m_alpha);

View File

@ -330,7 +330,7 @@ static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root)
} }
/* colorpicker */ /* colorpicker */
else if (ustrcmp(elem_name, "colorpicker") == 0) { 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? // Was the widget created?