Skip to content
Permalink
Browse files
Encapsulate Image implementation (private members, accessors, iterato…
…rs, etc.)

- Rename _rgba/_graya to raster::rgba()/graya()
- Add raster::color_t type (alias for uint32_t)
- Rename raster::GfxObj to Object. And GfxObj::getType() to Object::type()
- Move conversion from raster::Image/Palette to Allegro BITMAP/RGB
  to raster/conversion_alleg.h file
- Add raster/color_scales.h
- Rename image_* functions to raster/primitives.h
- Reimplement ink processing with templates instead of macros
  • Loading branch information
dacap committed Nov 9, 2013
1 parent 7657461 commit e5ba8e0922e066e7b521b149007a74aa00a9a25b
Show file tree
Hide file tree
Showing 128 changed files with 4,922 additions and 3,763 deletions.
@@ -1,5 +1,7 @@
# Very high priority (next release?)

* Remove Image::getPixelAddress() shouldn't be public, and almost
everywhere we should use iterators for images.
* Warning icon when selecting RGB/HSB color in indexed image.
* Warning message when we open a file that is already opened file
(show an option to create a second view, or maybe this should
@@ -145,9 +145,8 @@ else()
endif()

######################################################################
# ASEPRITE libraries
# Aseprite Libraries (in preferred order to be built)

add_subdirectory(app)
add_subdirectory(base)
add_subdirectory(filters)
add_subdirectory(gfx)
@@ -157,6 +156,8 @@ add_subdirectory(she)
add_subdirectory(ui)
add_subdirectory(undo)

add_subdirectory(app)

if(V8_FOUND)
list(APPEND libs3rdparty ${V8_LIBRARIES})
endif()
@@ -242,6 +243,7 @@ endfunction()

find_unittests(base base-lib ${sys_libs})
find_unittests(gfx gfx-lib base-lib ${sys_libs})
find_unittests(raster raster-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_unittests(ui ui-lib she gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_unittests(file ${all_libs})
find_unittests(app ${all_libs})
@@ -28,6 +28,7 @@
#include "gfx/rgb.h"
#include "raster/image.h"
#include "raster/palette.h"
#include "raster/primitives.h"

#include <cstdlib>
#include <iomanip>
@@ -83,23 +84,23 @@ Color Color::fromIndex(int index)
}

// static
Color Color::fromImage(PixelFormat pixelFormat, int c)
Color Color::fromImage(PixelFormat pixelFormat, color_t c)
{
Color color = Color::fromMask();

switch (pixelFormat) {

case IMAGE_RGB:
if (_rgba_geta(c) > 0) {
color = Color::fromRgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c));
if (rgba_geta(c) > 0) {
color = Color::fromRgb(rgba_getr(c),
rgba_getg(c),
rgba_getb(c));
}
break;

case IMAGE_GRAYSCALE:
if (_graya_geta(c) > 0) {
color = Color::fromGray(_graya_getv(c));
if (graya_geta(c) > 0) {
color = Color::fromGray(graya_getv(c));
}
break;

@@ -114,8 +115,8 @@ Color Color::fromImage(PixelFormat pixelFormat, int c)
// static
Color Color::fromImageGetPixel(Image *image, int x, int y)
{
if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h))
return Color::fromImage(image->getPixelFormat(), image_getpixel(image, x, y));
if ((x >= 0) && (y >= 0) && (x < image->getWidth()) && (y < image->getHeight()))
return Color::fromImage(image->getPixelFormat(), raster::get_pixel(image, x, y));
else
return Color::fromMask();
}
@@ -245,9 +246,9 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
uint32_t _c = get_current_palette()->getEntry(i);
result << "Index " << i
<< " (RGB "
<< (int)_rgba_getr(_c) << " "
<< (int)_rgba_getg(_c) << " "
<< (int)_rgba_getb(_c) << ")";
<< (int)rgba_getr(_c) << " "
<< (int)rgba_getg(_c) << " "
<< (int)rgba_getb(_c) << ")";
}
else {
result << "Index "
@@ -381,7 +382,7 @@ int Color::getRed() const
int i = m_value.index;
ASSERT(i >= 0 && i < get_current_palette()->size());

return _rgba_getr(get_current_palette()->getEntry(i));
return rgba_getr(get_current_palette()->getEntry(i));
}

}
@@ -412,7 +413,7 @@ int Color::getGreen() const
int i = m_value.index;
ASSERT(i >= 0 && i < get_current_palette()->size());

return _rgba_getg(get_current_palette()->getEntry(i));
return rgba_getg(get_current_palette()->getEntry(i));
}

}
@@ -443,7 +444,7 @@ int Color::getBlue() const
int i = m_value.index;
ASSERT(i >= 0 && i < get_current_palette()->size());

return _rgba_getb(get_current_palette()->getEntry(i));
return rgba_getb(get_current_palette()->getEntry(i));
}

}
@@ -476,9 +477,9 @@ int Color::getHue() const

uint32_t c = get_current_palette()->getEntry(i);

return Hsv(Rgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c))).hueInt();
return Hsv(Rgb(rgba_getr(c),
rgba_getg(c),
rgba_getb(c))).hueInt();
}

}
@@ -511,9 +512,9 @@ int Color::getSaturation() const

uint32_t c = get_current_palette()->getEntry(i);

return Hsv(Rgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c))).saturationInt();
return Hsv(Rgb(rgba_getr(c),
rgba_getg(c),
rgba_getb(c))).saturationInt();
}

}
@@ -546,9 +547,9 @@ int Color::getValue() const

uint32_t c = get_current_palette()->getEntry(i);

return Hsv(Rgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c))).valueInt();
return Hsv(Rgb(rgba_getr(c),
rgba_getg(c),
rgba_getb(c))).valueInt();
}

}
@@ -581,9 +582,9 @@ int Color::getGray() const

uint32_t c = get_current_palette()->getEntry(i);

return 255 * Hsv(Rgb(_rgba_getr(c),
_rgba_getg(c),
_rgba_getb(c))).valueInt() / 100;
return 255 * Hsv(Rgb(rgba_getr(c),
rgba_getg(c),
rgba_getb(c))).valueInt() / 100;
}

}
@@ -19,6 +19,7 @@
#ifndef APP_COLOR_H_INCLUDED
#define APP_COLOR_H_INCLUDED

#include "raster/color.h"
#include "raster/pixel_format.h"

#include <string>
@@ -56,7 +57,7 @@ namespace app {
static Color fromGray(int g);
static Color fromIndex(int index);

static Color fromImage(PixelFormat pixelFormat, int pixel);
static Color fromImage(PixelFormat pixelFormat, color_t c);
static Color fromImageGetPixel(Image* image, int x, int y);
static Color fromString(const std::string& str);

@@ -100,9 +100,9 @@ ui::Color color_utils::color_for_ui(const app::Color& color)
ASSERT(i >= 0 && i < (int)get_current_palette()->size());

uint32_t _c = get_current_palette()->getEntry(i);
c = ui::rgba(_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
c = ui::rgba(rgba_getr(_c),
rgba_getg(_c),
rgba_getb(_c), 255);
break;
}

@@ -142,9 +142,9 @@ int color_utils::color_for_allegro(const app::Color& color, int depth)

uint32_t _c = get_current_palette()->getEntry(c);
c = makeacol_depth(depth,
_rgba_getr(_c),
_rgba_getg(_c),
_rgba_getb(_c), 255);
rgba_getr(_c),
rgba_getg(_c),
rgba_getb(_c), 255);
}
break;

@@ -153,19 +153,19 @@ int color_utils::color_for_allegro(const app::Color& color, int depth)
return c;
}

int color_utils::color_for_image(const app::Color& color, PixelFormat format)
raster::color_t color_utils::color_for_image(const app::Color& color, PixelFormat format)
{
if (color.getType() == app::Color::MaskType)
return 0;

int c = -1;
raster::color_t c = -1;

switch (format) {
case IMAGE_RGB:
c = _rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
c = rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
break;
case IMAGE_GRAYSCALE:
c = _graya(color.getGray(), 255);
c = graya(color.getGray(), 255);
break;
case IMAGE_INDEXED:
if (color.getType() == app::Color::IndexType)
@@ -178,9 +178,9 @@ int color_utils::color_for_image(const app::Color& color, PixelFormat format)
return c;
}

int color_utils::color_for_layer(const app::Color& color, Layer* layer)
raster::color_t color_utils::color_for_layer(const app::Color& color, Layer* layer)
{
int pixel_color;
raster::color_t pixel_color;

if (color.getType() == app::Color::MaskType) {
pixel_color = layer->getSprite()->getTransparentColor();
@@ -193,27 +193,27 @@ int color_utils::color_for_layer(const app::Color& color, Layer* layer)
return fixup_color_for_layer(layer, pixel_color);
}

int color_utils::fixup_color_for_layer(Layer *layer, int color)
raster::color_t color_utils::fixup_color_for_layer(Layer *layer, raster::color_t color)
{
if (layer->isBackground())
return fixup_color_for_background(layer->getSprite()->getPixelFormat(), color);
else
return color;
}

int color_utils::fixup_color_for_background(PixelFormat format, int color)
raster::color_t color_utils::fixup_color_for_background(PixelFormat format, raster::color_t color)
{
switch (format) {
case IMAGE_RGB:
if (_rgba_geta(color) < 255) {
return _rgba(_rgba_getr(color),
_rgba_getg(color),
_rgba_getb(color), 255);
if (rgba_geta(color) < 255) {
return rgba(rgba_getr(color),
rgba_getg(color),
rgba_getb(color), 255);
}
break;
case IMAGE_GRAYSCALE:
if (_graya_geta(color) < 255) {
return _graya(_graya_getv(color), 255);
if (graya_geta(color) < 255) {
return graya(graya_getv(color), 255);
}
break;
}
@@ -20,6 +20,7 @@
#define APP_COLOR_UTILS_H_INCLUDED

#include "app/color.h"
#include "raster/color.h"
#include "raster/pixel_format.h"
#include "ui/color.h"

@@ -35,11 +36,11 @@ namespace app {

ui::Color color_for_ui(const app::Color& color);
int color_for_allegro(const app::Color& color, int depth);
int color_for_image(const app::Color& color, raster::PixelFormat format);
int color_for_layer(const app::Color& color, raster::Layer* layer);
raster::color_t color_for_image(const app::Color& color, raster::PixelFormat format);
raster::color_t color_for_layer(const app::Color& color, raster::Layer* layer);

int fixup_color_for_layer(raster::Layer* layer, int color);
int fixup_color_for_background(raster::PixelFormat format, int color);
raster::color_t fixup_color_for_layer(raster::Layer* layer, raster::color_t color);
raster::color_t fixup_color_for_background(raster::PixelFormat format, raster::color_t color);

} // namespace color_utils
} // namespace app
@@ -99,14 +99,12 @@ void CelPropertiesCommand::onExecute(Context* context)
label_pos->setTextf("%d, %d", cel->getX(), cel->getY());

// Dimension (and memory size)
int memsize =
image_line_size(sprite->getStock()->getImage(cel->getImage()),
sprite->getStock()->getImage(cel->getImage())->w)*
sprite->getStock()->getImage(cel->getImage())->h;
Image* image = sprite->getStock()->getImage(cel->getImage());
int memsize = image->getRowStrideSize() * image->getHeight();

label_size->setTextf("%dx%d (%s)",
sprite->getStock()->getImage(cel->getImage())->w,
sprite->getStock()->getImage(cel->getImage())->h,
sprite->getStock()->getImage(cel->getImage())->getWidth(),
sprite->getStock()->getImage(cel->getImage())->getHeight(),
base::get_pretty_memory_size(memsize).c_str());

// Opacity
@@ -38,6 +38,7 @@
#include "raster/image.h"
#include "raster/layer.h"
#include "raster/palette.h"
#include "raster/primitives.h"
#include "raster/sprite.h"
#include "raster/stock.h"
#include "ui/ui.h"
@@ -146,7 +147,7 @@ class ExportSpriteSheetWindow : public Window {
int sheet_h = sprite->getHeight()*((nframes/columns)+((nframes%columns)>0?1:0));
base::UniquePtr<Image> resultImage(Image::create(sprite->getPixelFormat(), sheet_w, sheet_h));
base::UniquePtr<Image> tempImage(Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()));
image_clear(resultImage, 0);
raster::clear_image(resultImage, 0);

int column = 0, row = 0;
for (FrameNumber frame(0); frame<nframes; ++frame) {
@@ -89,8 +89,7 @@ void FlipCommand::onExecute(Context* context)
bool alreadyFlipped = false;

// This variable will be the area to be flipped inside the image.
gfx::Rect bounds(gfx::Point(0, 0),
gfx::Size(image->w, image->h));
gfx::Rect bounds(image->getBounds());

// If there is some portion of sprite selected, we flip the
// selected region only. If the mask isn't visible, we flip the
@@ -122,8 +121,7 @@ void FlipCommand::onExecute(Context* context)
base::UniquePtr<Mask> newMask(new Mask(*mask));
newMask->freeze();
raster::algorithm::flip_image(newMask->getBitmap(),
gfx::Rect(gfx::Point(0, 0),
gfx::Size(maskBitmap->w, maskBitmap->h)),
maskBitmap->getBounds(),
m_flipType);
newMask->unfreeze();

@@ -153,13 +151,13 @@ void FlipCommand::onExecute(Context* context)
api.setCelPosition
(sprite, cel,
(m_flipType == raster::algorithm::FlipHorizontal ?
sprite->getWidth() - image->w - cel->getX():
sprite->getWidth() - image->getWidth() - cel->getX():
cel->getX()),
(m_flipType == raster::algorithm::FlipVertical ?
sprite->getHeight() - image->h - cel->getY():
sprite->getHeight() - image->getHeight() - cel->getY():
cel->getY()));

api.flipImage(image, gfx::Rect(0, 0, image->w, image->h), m_flipType);
api.flipImage(image, image->getBounds(), m_flipType);
}
}

0 comments on commit e5ba8e0

Please sign in to comment.