mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-26 18:41:20 +00:00
Fix ase_parallelogram_map_standard() for RGB and Grayscale images with customized transparent color
This commit is contained in:
parent
1d3854c670
commit
47cdd4af67
@ -29,10 +29,16 @@ namespace raster {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// RGBA
|
||||
|
||||
const int rgba_r_shift = 0;
|
||||
const int rgba_g_shift = 8;
|
||||
const int rgba_b_shift = 16;
|
||||
const int rgba_a_shift = 24;
|
||||
const uint32_t rgba_r_shift = 0;
|
||||
const uint32_t rgba_g_shift = 8;
|
||||
const uint32_t rgba_b_shift = 16;
|
||||
const uint32_t rgba_a_shift = 24;
|
||||
|
||||
const uint32_t rgba_r_mask = 0x000000ff;
|
||||
const uint32_t rgba_g_mask = 0x0000ff00;
|
||||
const uint32_t rgba_b_mask = 0x00ff0000;
|
||||
const uint32_t rgba_rgb_mask = 0x00ffffff;
|
||||
const uint32_t rgba_a_mask = 0xff000000;
|
||||
|
||||
inline uint8_t rgba_getr(uint32_t c) {
|
||||
return (c >> rgba_r_shift) & 0xff;
|
||||
@ -60,8 +66,11 @@ namespace raster {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Grayscale
|
||||
|
||||
const int graya_v_shift = 0;
|
||||
const int graya_a_shift = 8;
|
||||
const uint16_t graya_v_shift = 0;
|
||||
const uint16_t graya_a_shift = 8;
|
||||
|
||||
const uint16_t graya_v_mask = 0x00ff;
|
||||
const uint16_t graya_a_mask = 0xff00;
|
||||
|
||||
inline uint8_t graya_getv(uint16_t c) {
|
||||
return (c >> graya_v_shift) & 0xff;
|
||||
|
@ -188,36 +188,46 @@ protected:
|
||||
|
||||
class RgbDelegate : public GenericDelegate<RgbTraits> {
|
||||
public:
|
||||
RgbDelegate() {
|
||||
RgbDelegate(color_t mask_color) {
|
||||
m_blender = rgba_blenders[BLEND_MODE_NORMAL];
|
||||
m_mask_color = mask_color & rgba_rgb_mask;
|
||||
}
|
||||
|
||||
void feedLine(Image* spr, int spr_x, int spr_y) {
|
||||
ASSERT(m_it != m_end);
|
||||
|
||||
*m_it = m_blender(*m_it, spr->getPixel(spr_x, spr_y), 255);
|
||||
register int c = spr->getPixel(spr_x, spr_y);
|
||||
if ((c & rgba_rgb_mask) != m_mask_color)
|
||||
*m_it = m_blender(*m_it, c, 255);
|
||||
|
||||
++m_it;
|
||||
}
|
||||
|
||||
private:
|
||||
BLEND_COLOR m_blender;
|
||||
color_t m_mask_color;
|
||||
};
|
||||
|
||||
class GrayscaleDelegate : public GenericDelegate<GrayscaleTraits> {
|
||||
public:
|
||||
GrayscaleDelegate() {
|
||||
GrayscaleDelegate(color_t mask_color) {
|
||||
m_blender = graya_blenders[BLEND_MODE_NORMAL];
|
||||
m_mask_color = mask_color & graya_v_mask;
|
||||
}
|
||||
|
||||
void feedLine(Image* spr, int spr_x, int spr_y) {
|
||||
ASSERT(m_it != m_end);
|
||||
|
||||
*m_it = m_blender(*m_it, spr->getPixel(spr_x, spr_y), 255);
|
||||
register int c = spr->getPixel(spr_x, spr_y);
|
||||
if ((c & graya_v_mask) != m_mask_color)
|
||||
*m_it = m_blender(*m_it, c, 255);
|
||||
|
||||
++m_it;
|
||||
}
|
||||
|
||||
private:
|
||||
BLEND_COLOR m_blender;
|
||||
color_t m_mask_color;
|
||||
};
|
||||
|
||||
class IndexedDelegate : public GenericDelegate<IndexedTraits> {
|
||||
@ -278,7 +288,7 @@ public:
|
||||
template<class Traits, class Delegate>
|
||||
static void ase_parallelogram_map(
|
||||
Image *bmp, Image *spr, fixed xs[4], fixed ys[4],
|
||||
int sub_pixel_accuracy, Delegate delegate = Delegate())
|
||||
int sub_pixel_accuracy, Delegate delegate)
|
||||
{
|
||||
/* Index in xs[] and ys[] to topmost point. */
|
||||
int top_index;
|
||||
@ -685,13 +695,17 @@ static void ase_parallelogram_map_standard(Image *bmp, Image *sprite,
|
||||
{
|
||||
switch (bmp->getPixelFormat()) {
|
||||
|
||||
case IMAGE_RGB:
|
||||
ase_parallelogram_map<RgbTraits, RgbDelegate>(bmp, sprite, xs, ys, false);
|
||||
case IMAGE_RGB: {
|
||||
RgbDelegate delegate(sprite->getMaskColor());
|
||||
ase_parallelogram_map<RgbTraits, RgbDelegate>(bmp, sprite, xs, ys, false, delegate);
|
||||
break;
|
||||
}
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
ase_parallelogram_map<GrayscaleTraits, GrayscaleDelegate>(bmp, sprite, xs, ys, false);
|
||||
case IMAGE_GRAYSCALE: {
|
||||
GrayscaleDelegate delegate(sprite->getMaskColor());
|
||||
ase_parallelogram_map<GrayscaleTraits, GrayscaleDelegate>(bmp, sprite, xs, ys, false, delegate);
|
||||
break;
|
||||
}
|
||||
|
||||
case IMAGE_INDEXED: {
|
||||
IndexedDelegate delegate(sprite->getMaskColor());
|
||||
@ -699,9 +713,11 @@ static void ase_parallelogram_map_standard(Image *bmp, Image *sprite,
|
||||
break;
|
||||
}
|
||||
|
||||
case IMAGE_BITMAP:
|
||||
ase_parallelogram_map<BitmapTraits, BitmapDelegate>(bmp, sprite, xs, ys, false);
|
||||
case IMAGE_BITMAP: {
|
||||
BitmapDelegate delegate;
|
||||
ase_parallelogram_map<BitmapTraits, BitmapDelegate>(bmp, sprite, xs, ys, false, delegate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user