Skip to content

Commit e5ba8e0

Browse files
committed
Encapsulate Image implementation (private members, accessors, iterators, 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
1 parent 7657461 commit e5ba8e0

File tree

128 files changed

+4922
-3763
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+4922
-3763
lines changed

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Very high priority (next release?)
22

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

src/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ else()
145145
endif()
146146

147147
######################################################################
148-
# ASEPRITE libraries
148+
# Aseprite Libraries (in preferred order to be built)
149149

150-
add_subdirectory(app)
151150
add_subdirectory(base)
152151
add_subdirectory(filters)
153152
add_subdirectory(gfx)
@@ -157,6 +156,8 @@ add_subdirectory(she)
157156
add_subdirectory(ui)
158157
add_subdirectory(undo)
159158

159+
add_subdirectory(app)
160+
160161
if(V8_FOUND)
161162
list(APPEND libs3rdparty ${V8_LIBRARIES})
162163
endif()
@@ -242,6 +243,7 @@ endfunction()
242243

243244
find_unittests(base base-lib ${sys_libs})
244245
find_unittests(gfx gfx-lib base-lib ${sys_libs})
246+
find_unittests(raster raster-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
245247
find_unittests(ui ui-lib she gfx-lib base-lib ${libs3rdparty} ${sys_libs})
246248
find_unittests(file ${all_libs})
247249
find_unittests(app ${all_libs})

src/app/color.cpp

+28-27
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "gfx/rgb.h"
2929
#include "raster/image.h"
3030
#include "raster/palette.h"
31+
#include "raster/primitives.h"
3132

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

8586
// static
86-
Color Color::fromImage(PixelFormat pixelFormat, int c)
87+
Color Color::fromImage(PixelFormat pixelFormat, color_t c)
8788
{
8889
Color color = Color::fromMask();
8990

9091
switch (pixelFormat) {
9192

9293
case IMAGE_RGB:
93-
if (_rgba_geta(c) > 0) {
94-
color = Color::fromRgb(_rgba_getr(c),
95-
_rgba_getg(c),
96-
_rgba_getb(c));
94+
if (rgba_geta(c) > 0) {
95+
color = Color::fromRgb(rgba_getr(c),
96+
rgba_getg(c),
97+
rgba_getb(c));
9798
}
9899
break;
99100

100101
case IMAGE_GRAYSCALE:
101-
if (_graya_geta(c) > 0) {
102-
color = Color::fromGray(_graya_getv(c));
102+
if (graya_geta(c) > 0) {
103+
color = Color::fromGray(graya_getv(c));
103104
}
104105
break;
105106

@@ -114,8 +115,8 @@ Color Color::fromImage(PixelFormat pixelFormat, int c)
114115
// static
115116
Color Color::fromImageGetPixel(Image *image, int x, int y)
116117
{
117-
if ((x >= 0) && (y >= 0) && (x < image->w) && (y < image->h))
118-
return Color::fromImage(image->getPixelFormat(), image_getpixel(image, x, y));
118+
if ((x >= 0) && (y >= 0) && (x < image->getWidth()) && (y < image->getHeight()))
119+
return Color::fromImage(image->getPixelFormat(), raster::get_pixel(image, x, y));
119120
else
120121
return Color::fromMask();
121122
}
@@ -245,9 +246,9 @@ std::string Color::toHumanReadableString(PixelFormat pixelFormat, HumanReadableS
245246
uint32_t _c = get_current_palette()->getEntry(i);
246247
result << "Index " << i
247248
<< " (RGB "
248-
<< (int)_rgba_getr(_c) << " "
249-
<< (int)_rgba_getg(_c) << " "
250-
<< (int)_rgba_getb(_c) << ")";
249+
<< (int)rgba_getr(_c) << " "
250+
<< (int)rgba_getg(_c) << " "
251+
<< (int)rgba_getb(_c) << ")";
251252
}
252253
else {
253254
result << "Index "
@@ -381,7 +382,7 @@ int Color::getRed() const
381382
int i = m_value.index;
382383
ASSERT(i >= 0 && i < get_current_palette()->size());
383384

384-
return _rgba_getr(get_current_palette()->getEntry(i));
385+
return rgba_getr(get_current_palette()->getEntry(i));
385386
}
386387

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

415-
return _rgba_getg(get_current_palette()->getEntry(i));
416+
return rgba_getg(get_current_palette()->getEntry(i));
416417
}
417418

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

446-
return _rgba_getb(get_current_palette()->getEntry(i));
447+
return rgba_getb(get_current_palette()->getEntry(i));
447448
}
448449

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

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

479-
return Hsv(Rgb(_rgba_getr(c),
480-
_rgba_getg(c),
481-
_rgba_getb(c))).hueInt();
480+
return Hsv(Rgb(rgba_getr(c),
481+
rgba_getg(c),
482+
rgba_getb(c))).hueInt();
482483
}
483484

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

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

514-
return Hsv(Rgb(_rgba_getr(c),
515-
_rgba_getg(c),
516-
_rgba_getb(c))).saturationInt();
515+
return Hsv(Rgb(rgba_getr(c),
516+
rgba_getg(c),
517+
rgba_getb(c))).saturationInt();
517518
}
518519

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

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

549-
return Hsv(Rgb(_rgba_getr(c),
550-
_rgba_getg(c),
551-
_rgba_getb(c))).valueInt();
550+
return Hsv(Rgb(rgba_getr(c),
551+
rgba_getg(c),
552+
rgba_getb(c))).valueInt();
552553
}
553554

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

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

584-
return 255 * Hsv(Rgb(_rgba_getr(c),
585-
_rgba_getg(c),
586-
_rgba_getb(c))).valueInt() / 100;
585+
return 255 * Hsv(Rgb(rgba_getr(c),
586+
rgba_getg(c),
587+
rgba_getb(c))).valueInt() / 100;
587588
}
588589

589590
}

src/app/color.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef APP_COLOR_H_INCLUDED
2020
#define APP_COLOR_H_INCLUDED
2121

22+
#include "raster/color.h"
2223
#include "raster/pixel_format.h"
2324

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

59-
static Color fromImage(PixelFormat pixelFormat, int pixel);
60+
static Color fromImage(PixelFormat pixelFormat, color_t c);
6061
static Color fromImageGetPixel(Image* image, int x, int y);
6162
static Color fromString(const std::string& str);
6263

src/app/color_utils.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ ui::Color color_utils::color_for_ui(const app::Color& color)
100100
ASSERT(i >= 0 && i < (int)get_current_palette()->size());
101101

102102
uint32_t _c = get_current_palette()->getEntry(i);
103-
c = ui::rgba(_rgba_getr(_c),
104-
_rgba_getg(_c),
105-
_rgba_getb(_c), 255);
103+
c = ui::rgba(rgba_getr(_c),
104+
rgba_getg(_c),
105+
rgba_getb(_c), 255);
106106
break;
107107
}
108108

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

143143
uint32_t _c = get_current_palette()->getEntry(c);
144144
c = makeacol_depth(depth,
145-
_rgba_getr(_c),
146-
_rgba_getg(_c),
147-
_rgba_getb(_c), 255);
145+
rgba_getr(_c),
146+
rgba_getg(_c),
147+
rgba_getb(_c), 255);
148148
}
149149
break;
150150

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

156-
int color_utils::color_for_image(const app::Color& color, PixelFormat format)
156+
raster::color_t color_utils::color_for_image(const app::Color& color, PixelFormat format)
157157
{
158158
if (color.getType() == app::Color::MaskType)
159159
return 0;
160160

161-
int c = -1;
161+
raster::color_t c = -1;
162162

163163
switch (format) {
164164
case IMAGE_RGB:
165-
c = _rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
165+
c = rgba(color.getRed(), color.getGreen(), color.getBlue(), 255);
166166
break;
167167
case IMAGE_GRAYSCALE:
168-
c = _graya(color.getGray(), 255);
168+
c = graya(color.getGray(), 255);
169169
break;
170170
case IMAGE_INDEXED:
171171
if (color.getType() == app::Color::IndexType)
@@ -178,9 +178,9 @@ int color_utils::color_for_image(const app::Color& color, PixelFormat format)
178178
return c;
179179
}
180180

181-
int color_utils::color_for_layer(const app::Color& color, Layer* layer)
181+
raster::color_t color_utils::color_for_layer(const app::Color& color, Layer* layer)
182182
{
183-
int pixel_color;
183+
raster::color_t pixel_color;
184184

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

196-
int color_utils::fixup_color_for_layer(Layer *layer, int color)
196+
raster::color_t color_utils::fixup_color_for_layer(Layer *layer, raster::color_t color)
197197
{
198198
if (layer->isBackground())
199199
return fixup_color_for_background(layer->getSprite()->getPixelFormat(), color);
200200
else
201201
return color;
202202
}
203203

204-
int color_utils::fixup_color_for_background(PixelFormat format, int color)
204+
raster::color_t color_utils::fixup_color_for_background(PixelFormat format, raster::color_t color)
205205
{
206206
switch (format) {
207207
case IMAGE_RGB:
208-
if (_rgba_geta(color) < 255) {
209-
return _rgba(_rgba_getr(color),
210-
_rgba_getg(color),
211-
_rgba_getb(color), 255);
208+
if (rgba_geta(color) < 255) {
209+
return rgba(rgba_getr(color),
210+
rgba_getg(color),
211+
rgba_getb(color), 255);
212212
}
213213
break;
214214
case IMAGE_GRAYSCALE:
215-
if (_graya_geta(color) < 255) {
216-
return _graya(_graya_getv(color), 255);
215+
if (graya_geta(color) < 255) {
216+
return graya(graya_getv(color), 255);
217217
}
218218
break;
219219
}

src/app/color_utils.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define APP_COLOR_UTILS_H_INCLUDED
2121

2222
#include "app/color.h"
23+
#include "raster/color.h"
2324
#include "raster/pixel_format.h"
2425
#include "ui/color.h"
2526

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

3637
ui::Color color_for_ui(const app::Color& color);
3738
int color_for_allegro(const app::Color& color, int depth);
38-
int color_for_image(const app::Color& color, raster::PixelFormat format);
39-
int color_for_layer(const app::Color& color, raster::Layer* layer);
39+
raster::color_t color_for_image(const app::Color& color, raster::PixelFormat format);
40+
raster::color_t color_for_layer(const app::Color& color, raster::Layer* layer);
4041

41-
int fixup_color_for_layer(raster::Layer* layer, int color);
42-
int fixup_color_for_background(raster::PixelFormat format, int color);
42+
raster::color_t fixup_color_for_layer(raster::Layer* layer, raster::color_t color);
43+
raster::color_t fixup_color_for_background(raster::PixelFormat format, raster::color_t color);
4344

4445
} // namespace color_utils
4546
} // namespace app

src/app/commands/cmd_cel_properties.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ void CelPropertiesCommand::onExecute(Context* context)
9999
label_pos->setTextf("%d, %d", cel->getX(), cel->getY());
100100

101101
// Dimension (and memory size)
102-
int memsize =
103-
image_line_size(sprite->getStock()->getImage(cel->getImage()),
104-
sprite->getStock()->getImage(cel->getImage())->w)*
105-
sprite->getStock()->getImage(cel->getImage())->h;
102+
Image* image = sprite->getStock()->getImage(cel->getImage());
103+
int memsize = image->getRowStrideSize() * image->getHeight();
106104

107105
label_size->setTextf("%dx%d (%s)",
108-
sprite->getStock()->getImage(cel->getImage())->w,
109-
sprite->getStock()->getImage(cel->getImage())->h,
106+
sprite->getStock()->getImage(cel->getImage())->getWidth(),
107+
sprite->getStock()->getImage(cel->getImage())->getHeight(),
110108
base::get_pretty_memory_size(memsize).c_str());
111109

112110
// Opacity

src/app/commands/cmd_export_sprite_sheet.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "raster/image.h"
3939
#include "raster/layer.h"
4040
#include "raster/palette.h"
41+
#include "raster/primitives.h"
4142
#include "raster/sprite.h"
4243
#include "raster/stock.h"
4344
#include "ui/ui.h"
@@ -146,7 +147,7 @@ class ExportSpriteSheetWindow : public Window {
146147
int sheet_h = sprite->getHeight()*((nframes/columns)+((nframes%columns)>0?1:0));
147148
base::UniquePtr<Image> resultImage(Image::create(sprite->getPixelFormat(), sheet_w, sheet_h));
148149
base::UniquePtr<Image> tempImage(Image::create(sprite->getPixelFormat(), sprite->getWidth(), sprite->getHeight()));
149-
image_clear(resultImage, 0);
150+
raster::clear_image(resultImage, 0);
150151

151152
int column = 0, row = 0;
152153
for (FrameNumber frame(0); frame<nframes; ++frame) {

src/app/commands/cmd_flip.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ void FlipCommand::onExecute(Context* context)
8989
bool alreadyFlipped = false;
9090

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

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

@@ -153,13 +151,13 @@ void FlipCommand::onExecute(Context* context)
153151
api.setCelPosition
154152
(sprite, cel,
155153
(m_flipType == raster::algorithm::FlipHorizontal ?
156-
sprite->getWidth() - image->w - cel->getX():
154+
sprite->getWidth() - image->getWidth() - cel->getX():
157155
cel->getX()),
158156
(m_flipType == raster::algorithm::FlipVertical ?
159-
sprite->getHeight() - image->h - cel->getY():
157+
sprite->getHeight() - image->getHeight() - cel->getY():
160158
cel->getY()));
161159

162-
api.flipImage(image, gfx::Rect(0, 0, image->w, image->h), m_flipType);
160+
api.flipImage(image, image->getBounds(), m_flipType);
163161
}
164162
}
165163

0 commit comments

Comments
 (0)