Add ink type Copy Alpha+Color to custom brush

This commit is contained in:
Gaspar Capello 2019-10-09 11:58:38 -03:00 committed by David Capello
parent 7160f45296
commit 7fd1c7e0e7
2 changed files with 161 additions and 0 deletions

View File

@ -1756,6 +1756,164 @@ void BrushShadingInkProcessing<GrayscaleTraits>::processPixel(int x, int y) {
}
};
//////////////////////////////////////////////////////////////////////
// Brush Ink - Copy Alpha+Color ink type
//////////////////////////////////////////////////////////////////////
template<typename ImageTraits>
class BrushCopyInkProcessing : public BrushInkProcessingBase<ImageTraits> {
public:
BrushCopyInkProcessing(ToolLoop* loop) : BrushInkProcessingBase<ImageTraits>(loop) {
}
void processPixel(int x, int y) override {
//Do nothing
}
};
template<>
void BrushCopyInkProcessing<RgbTraits>::processPixel(int x, int y) {
alignPixelPoint(x, y);
if (m_brushMask && !get_pixel_fast<BitmapTraits>(m_brushMask, x, y))
return;
color_t c;
switch (m_brushImage->pixelFormat()) {
case IMAGE_RGB: {
c = get_pixel_fast<RgbTraits>(m_brushImage, x, y);
if (rgba_geta(c) == 0)
return;
break;
}
case IMAGE_INDEXED: {
// TODO m_palette->getEntry(c) does not work because the m_palette member is
// loaded the Graya Palette, NOT the original Indexed Palette from where m_brushImage belongs.
// This conversion can be possible if we load the palette pointer in m_brush when
// is created the custom brush in the Indexed Sprite.
c = get_pixel_fast<IndexedTraits>(m_brushImage, x, y);
if (c == m_transparentColor) {
*m_dstAddress = *m_srcAddress;
return;
}
c = m_palette->getEntry(c);
break;
}
case IMAGE_GRAYSCALE: {
c = get_pixel_fast<GrayscaleTraits>(m_brushImage, x, y);
if (graya_geta(c) == 0)
return;
c = rgba(graya_getv(c), graya_getv(c), graya_getv(c), graya_geta(c));
break;
}
case IMAGE_BITMAP: {
// TODO In which circuntance is possible this case?
c = get_pixel_fast<BitmapTraits>(m_brushImage, x, y);
c = c ? m_fgColor: m_bgColor;
break;
}
default:
ASSERT(false);
return;
}
*m_dstAddress = c;
}
template<>
void BrushCopyInkProcessing<IndexedTraits>::processPixel(int x, int y) {
alignPixelPoint(x, y);
if (m_brushMask && !get_pixel_fast<BitmapTraits>(m_brushMask, x, y))
return;
color_t c;
switch (m_brushImage->pixelFormat()) {
case IMAGE_RGB: {
c = get_pixel_fast<RgbTraits>(m_brushImage, x, y);
if (rgba_geta(c) == 0)
return;
c = m_palette->findBestfit(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c), 0);
if (c == 0)
c = *m_srcAddress;
break;
}
case IMAGE_INDEXED: {
c = get_pixel_fast<IndexedTraits>(m_brushImage, x, y);
if (c == m_transparentColor)
c = *m_srcAddress;
break;
}
case IMAGE_GRAYSCALE: {
c = get_pixel_fast<GrayscaleTraits>(m_brushImage, x, y);
if (graya_geta(c) == 0)
return;
c = m_palette->findBestfit(graya_getv(c),
graya_getv(c),
graya_getv(c),
graya_geta(c), 0);
break;
}
case IMAGE_BITMAP: {
// TODO In which circuntance is possible this case?
c = get_pixel_fast<BitmapTraits>(m_brushImage, x, y);
c = c ? m_fgColor: m_bgColor;
break;
}
default:
ASSERT(false);
return;
}
*m_dstAddress = c;
}
template<>
void BrushCopyInkProcessing<GrayscaleTraits>::processPixel(int x, int y) {
alignPixelPoint(x, y);
if (m_brushMask && !get_pixel_fast<BitmapTraits>(m_brushMask, x, y))
return;
color_t c;
switch (m_brushImage->pixelFormat()) {
case IMAGE_RGB: {
c = get_pixel_fast<RgbTraits>(m_brushImage, x, y);
if (rgba_geta(c) == 0)
return;
c = graya(rgba_luma(c), rgba_geta(c));
break;
}
case IMAGE_INDEXED: {
// TODO m_palette->getEntry(c) does not work because the
// m_palette member is loaded the Graya Palette, NOT the
// original Indexed Palette from where m_brushImage belongs.
// This conversion can be possible if we load the palette
// pointer in m_brush when is created the custom brush in the
// Indexed Sprite.
c = get_pixel_fast<IndexedTraits>(m_brushImage, x, y);
if (c == m_transparentColor) {
*m_dstAddress = *m_srcAddress;
return;
}
c = m_palette->getEntry(c);
c = graya(rgba_luma(c), rgba_geta(c));
break;
}
case IMAGE_GRAYSCALE: {
c = get_pixel_fast<GrayscaleTraits>(m_brushImage, x, y);
if (graya_geta(c) == 0)
return;
break;
}
case IMAGE_BITMAP: {
// TODO In which circuntance is possible this case?
c = get_pixel_fast<BitmapTraits>(m_brushImage, x, y);
c = c ? m_fgColor: m_bgColor;
break;
}
default:
ASSERT(false);
return;
}
*m_dstAddress = c;
}
//////////////////////////////////////////////////////////////////////
template<template<typename> class T>

View File

@ -89,6 +89,9 @@ public:
case LockAlpha:
setProc(get_ink_proc<BrushLockAlphaInkProcessing>(loop));
break;
case Copy:
setProc(get_ink_proc<BrushCopyInkProcessing>(loop));
break;
default:
setProc(get_ink_proc<BrushSimpleInkProcessing>(loop));
break;