diff --git a/src/raster/color.h b/src/raster/color.h index 63c425ebc..085581136 100644 --- a/src/raster/color.h +++ b/src/raster/color.h @@ -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; diff --git a/src/raster/rotate.cpp b/src/raster/rotate.cpp index 4bd93c290..7b5c341a8 100644 --- a/src/raster/rotate.cpp +++ b/src/raster/rotate.cpp @@ -188,36 +188,46 @@ protected: class RgbDelegate : public GenericDelegate { 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 { 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 { @@ -278,7 +288,7 @@ public: template 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(bmp, sprite, xs, ys, false); + case IMAGE_RGB: { + RgbDelegate delegate(sprite->getMaskColor()); + ase_parallelogram_map(bmp, sprite, xs, ys, false, delegate); break; + } - case IMAGE_GRAYSCALE: - ase_parallelogram_map(bmp, sprite, xs, ys, false); + case IMAGE_GRAYSCALE: { + GrayscaleDelegate delegate(sprite->getMaskColor()); + ase_parallelogram_map(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(bmp, sprite, xs, ys, false); + case IMAGE_BITMAP: { + BitmapDelegate delegate; + ase_parallelogram_map(bmp, sprite, xs, ys, false, delegate); break; + } } }