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
Showing with 4,922 additions and 3,763 deletions.
  1. +2 −0 TODO.md
  2. +4 −2 src/CMakeLists.txt
  3. +28 −27 src/app/color.cpp
  4. +2 −1 src/app/color.h
  5. +20 −20 src/app/color_utils.cpp
  6. +5 −4 src/app/color_utils.h
  7. +4 −6 src/app/commands/cmd_cel_properties.cpp
  8. +2 −1 src/app/commands/cmd_export_sprite_sheet.cpp
  9. +5 −7 src/app/commands/cmd_flip.cpp
  10. +2 −1 src/app/commands/cmd_import_sprite_sheet.cpp
  11. +9 −8 src/app/commands/cmd_invert_mask.cpp
  12. +12 −11 src/app/commands/cmd_merge_down_layer.cpp
  13. +2 −1 src/app/commands/cmd_new_file.cpp
  14. +7 −7 src/app/commands/cmd_palette_editor.cpp
  15. +3 −2 src/app/commands/cmd_play_animation.cpp
  16. +4 −2 src/app/commands/cmd_preview.cpp
  17. +12 −8 src/app/commands/cmd_rotate_canvas.cpp
  18. +22 −19 src/app/commands/cmd_sprite_size.cpp
  19. +28 −31 src/app/commands/filters/filter_manager_impl.cpp
  20. +5 −3 src/app/commands/filters/filter_manager_impl.h
  21. +6 −0 src/app/commands/filters/filter_preview.cpp
  22. +5 −5 src/app/document.cpp
  23. +48 −44 src/app/document_api.cpp
  24. +6 −6 src/app/drop_files.cpp
  25. +54 −54 src/app/file/ase_format.cpp
  26. +38 −36 src/app/file/bmp_format.cpp
  27. +5 −5 src/app/file/file.cpp
  28. +2 −2 src/app/file/file_unittest.cpp
  29. +18 −18 src/app/file/fli_format.cpp
  30. +63 −59 src/app/file/gif_format.cpp
  31. +35 −35 src/app/file/ico_format.cpp
  32. +19 −18 src/app/file/jpeg_format.cpp
  33. +30 −27 src/app/file/pcx_format.cpp
  34. +26 −26 src/app/file/png_format.cpp
  35. +39 −43 src/app/file/tga_format.cpp
  36. +3 −3 src/app/flatten.cpp
  37. +4 −4 src/app/modules/gfx.cpp
  38. +8 −7 src/app/modules/palettes.cpp
  39. +10 −10 src/app/thumbnail_generator.cpp
  40. +483 −402 src/app/tools/ink_processing.h
  41. +1 −1 src/app/tools/inks.h
  42. +5 −5 src/app/tools/point_shape.cpp
  43. +5 −4 src/app/tools/tool_loop_manager.cpp
  44. +12 −5 src/app/ui/context_bar.cpp
  45. +10 −7 src/app/ui/editor/cursor.cpp
  46. +28 −27 src/app/ui/editor/editor.cpp
  47. +14 −14 src/app/ui/editor/pixels_movement.cpp
  48. +4 −4 src/app/ui/editor/select_box_state.cpp
  49. +3 −3 src/app/ui/editor/standby_state.cpp
  50. +3 −3 src/app/ui/palette_view.cpp
  51. +1 −1 src/app/undoers/flip_image.cpp
  52. +4 −4 src/app/undoers/image_area.cpp
  53. +22 −22 src/app/util/autocrop.cpp
  54. +19 −17 src/app/util/boundary.cpp
  55. +7 −6 src/app/util/celmove.cpp
  56. +3 −11 src/app/util/clipboard.cpp
  57. +50 −50 src/app/util/clipboard_win32.h
  58. +9 −8 src/app/util/expand_cel_canvas.cpp
  59. +13 −15 src/app/util/misc.cpp
  60. +2 −3 src/app/util/msk_file.cpp
  61. +24 −23 src/app/util/pic_file.cpp
  62. +100 −105 src/app/util/render.cpp
  63. +31 −30 src/app/util/thmbnail.cpp
  64. +21 −0 src/base/clamp.h
  65. +11 −11 src/filters/color_curve_filter.cpp
  66. +26 −25 src/filters/convolution_matrix_filter.cpp
  67. +11 −11 src/filters/invert_color_filter.cpp
  68. +24 −23 src/filters/median_filter.cpp
  69. +13 −12 src/filters/neighboring_pixels.h
  70. +12 −12 src/filters/replace_color_filter.cpp
  71. +6 −1 src/raster/CMakeLists.txt
  72. +2 −2 src/raster/algo.cpp
  73. +51 −51 src/raster/algofill.cpp
  74. +14 −13 src/raster/algorithm/flip_image.cpp
  75. +0 −1 src/raster/algorithm/flip_image.h
  76. +244 −0 src/raster/algorithm/resize_image.cpp
  77. +53 −0 src/raster/algorithm/resize_image.h
  78. +114 −0 src/raster/algorithm/shrink_bounds.cpp
  79. +36 −0 src/raster/algorithm/shrink_bounds.h
  80. +52 −52 src/raster/blend.cpp
  81. +12 −12 src/raster/blend.h
  82. +2 −2 src/raster/cel.cpp
  83. +2 −2 src/raster/cel.h
  84. +80 −0 src/raster/color.h
  85. +5 −3 src/raster/color_histogram.h
  86. +60 −0 src/raster/color_scales.cpp
  87. +34 −0 src/raster/color_scales.h
  88. +315 −0 src/raster/conversion_alleg.cpp
  89. +36 −0 src/raster/conversion_alleg.h
  90. +10 −8 src/raster/dirty.cpp
  91. +1 −1 src/raster/dirty.h
  92. +32 −31 src/raster/file/col_file.cpp
  93. +4 −4 src/raster/file/gpl_file.cpp
  94. +23 −658 src/raster/image.cpp
  95. +57 −69 src/raster/image.h
  96. +167 −0 src/raster/image_bits.h
  97. +185 −750 src/raster/image_impl.h
  98. +10 −10 src/raster/image_io.cpp
  99. +506 −0 src/raster/image_iterator.h
  100. +36 −133 src/raster/image_traits.h
  101. +198 −0 src/raster/image_unittest.cpp
  102. +3 −3 src/raster/images_collector.cpp
  103. +15 −14 src/raster/layer.cpp
  104. +5 −5 src/raster/layer.h
  105. +6 −6 src/raster/layer_io.cpp
  106. +116 −125 src/raster/mask.cpp
  107. +6 −3 src/raster/mask.h
  108. +4 −4 src/raster/mask_io.cpp
  109. +4 −4 src/raster/median_cut.h
  110. +7 −7 src/raster/{gfxobj.cpp → object.cpp}
  111. +20 −20 src/raster/{gfxobj.h → object.h}
  112. +76 −110 src/raster/palette.cpp
  113. +7 −10 src/raster/palette.h
  114. +5 −5 src/raster/path.cpp
  115. +2 −2 src/raster/path.h
  116. +17 −15 src/raster/pen.cpp
  117. +337 −0 src/raster/primitives.cpp
  118. +54 −0 src/raster/primitives.h
  119. +67 −0 src/raster/primitives_fast.h
  120. +139 −113 src/raster/quantization.cpp
  121. +8 −1 src/raster/raster.h
  122. +3 −2 src/raster/rgbmap.cpp
  123. +2 −2 src/raster/rgbmap.h
  124. +83 −64 src/raster/rotate.cpp
  125. +15 −12 src/raster/sprite.cpp
  126. +2 −2 src/raster/sprite.h
  127. +2 −2 src/raster/stock.cpp
  128. +2 −2 src/raster/stock.h
View
@@ -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
View
@@ -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})
View
@@ -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;
}
}
View
@@ -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);
View
@@ -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;
}
View
@@ -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);
}
}
Oops, something went wrong.

0 comments on commit e5ba8e0

Please sign in to comment.