Remove INK_* constants and ink_processing[][] array

This commit is contained in:
David Capello 2016-09-23 11:36:55 -03:00
parent 72ede7e642
commit ceca640a98
2 changed files with 38 additions and 52 deletions

View File

@ -1066,46 +1066,26 @@ void BrushInkProcessing<IndexedTraits>::processPixel(int x, int y) {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
enum { template<template<typename> class InkProcessing,
INK_COPY, typename ImageTraits>
INK_LOCKALPHA, void ink_proc(int x1, int y, int x2, void* data)
INK_TRANSPARENT,
INK_MERGE,
INK_BLUR,
INK_REPLACE,
INK_JUMBLE,
INK_SHADING,
INK_XOR,
INK_BRUSH,
MAX_INKS
};
template<typename InkProcessing>
void ink_processing_algo(int x1, int y, int x2, void* data)
{ {
ToolLoop* loop = reinterpret_cast<ToolLoop*>(data); ToolLoop* loop = reinterpret_cast<ToolLoop*>(data);
InkProcessing ink(loop); InkProcessing<ImageTraits> ink(loop);
ink(x1, y, x2, loop); ink(x1, y, x2, loop);
} }
AlgoHLine ink_processing[][3] = template<template<typename> class InkProcessing>
AlgoHLine get_ink_proc(PixelFormat pixelFormat)
{ {
#define DEFINE_INK(name) \ switch (pixelFormat) {
{ ink_processing_algo<name<RgbTraits> >, \ case IMAGE_RGB: return ink_proc<InkProcessing, RgbTraits>;
ink_processing_algo<name<GrayscaleTraits> >, \ case IMAGE_GRAYSCALE: return ink_proc<InkProcessing, GrayscaleTraits>;
ink_processing_algo<name<IndexedTraits> > } case IMAGE_INDEXED: return ink_proc<InkProcessing, IndexedTraits>;
}
DEFINE_INK(CopyInkProcessing), ASSERT(false);
DEFINE_INK(LockAlphaInkProcessing), return nullptr;
DEFINE_INK(TransparentInkProcessing), }
DEFINE_INK(MergeInkProcessing),
DEFINE_INK(BlurInkProcessing),
DEFINE_INK(ReplaceInkProcessing),
DEFINE_INK(JumbleInkProcessing),
DEFINE_INK(ShadingInkProcessing),
DEFINE_INK(XorInkProcessing),
DEFINE_INK(BrushInkProcessing)
};
} // anonymous namespace } // anonymous namespace
} // namespace tools } // namespace tools

View File

@ -53,10 +53,10 @@ public:
break; break;
} }
int depth = MID(0, loop->sprite()->pixelFormat(), 2); auto pixelFormat = loop->sprite()->pixelFormat();
if (loop->getBrush()->type() == doc::kImageBrushType) if (loop->getBrush()->type() == doc::kImageBrushType)
m_proc = ink_processing[INK_BRUSH][depth]; m_proc = get_ink_proc<BrushInkProcessing>(pixelFormat);
else { else {
switch (m_type) { switch (m_type) {
case Simple: { case Simple: {
@ -81,19 +81,19 @@ public:
// Use a faster ink, direct copy // Use a faster ink, direct copy
if (opaque) if (opaque)
m_proc = ink_processing[INK_COPY][depth]; m_proc = get_ink_proc<CopyInkProcessing>(pixelFormat);
else else
m_proc = ink_processing[INK_TRANSPARENT][depth]; m_proc = get_ink_proc<TransparentInkProcessing>(pixelFormat);
break; break;
} }
case Copy: case Copy:
m_proc = ink_processing[INK_COPY][depth]; m_proc = get_ink_proc<CopyInkProcessing>(pixelFormat);
break; break;
case LockAlpha: case LockAlpha:
m_proc = ink_processing[INK_LOCKALPHA][depth]; m_proc = get_ink_proc<LockAlphaInkProcessing>(pixelFormat);
break; break;
default: default:
m_proc = ink_processing[INK_TRANSPARENT][depth]; m_proc = get_ink_proc<TransparentInkProcessing>(pixelFormat);
break; break;
} }
} }
@ -120,7 +120,7 @@ public:
bool isShading() const override { return true; } bool isShading() const override { return true; }
void prepareInk(ToolLoop* loop) override { void prepareInk(ToolLoop* loop) override {
m_proc = ink_processing[INK_SHADING][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<ShadingInkProcessing>(loop->sprite()->pixelFormat());
} }
void inkHline(int x1, int y, int x2, ToolLoop* loop) override { void inkHline(int x1, int y, int x2, ToolLoop* loop) override {
@ -207,16 +207,16 @@ public:
color_t secondary = app_get_color_to_clear_layer(loop->getLayer()); color_t secondary = app_get_color_to_clear_layer(loop->getLayer());
if (loop->getOpacity() == 255) { if (loop->getOpacity() == 255) {
m_proc = ink_processing[INK_COPY][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<CopyInkProcessing>(loop->sprite()->pixelFormat());
} }
else { else {
// For opaque layers // For opaque layers
if (loop->getLayer()->isBackground()) { if (loop->getLayer()->isBackground()) {
m_proc = ink_processing[INK_TRANSPARENT][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<TransparentInkProcessing>(loop->sprite()->pixelFormat());
} }
// For transparent layers // For transparent layers
else { else {
m_proc = ink_processing[INK_MERGE][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<MergeInkProcessing>(loop->sprite()->pixelFormat());
if (loop->sprite()->pixelFormat() == IMAGE_INDEXED) { if (loop->sprite()->pixelFormat() == IMAGE_INDEXED) {
primary = loop->sprite()->transparentColor(); primary = loop->sprite()->transparentColor();
@ -231,14 +231,14 @@ public:
} }
case ReplaceFgWithBg: case ReplaceFgWithBg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<ReplaceInkProcessing>(loop->sprite()->pixelFormat());
loop->setPrimaryColor(loop->getFgColor()); loop->setPrimaryColor(loop->getFgColor());
loop->setSecondaryColor(loop->getBgColor()); loop->setSecondaryColor(loop->getBgColor());
break; break;
case ReplaceBgWithFg: case ReplaceBgWithFg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<ReplaceInkProcessing>(loop->sprite()->pixelFormat());
loop->setPrimaryColor(loop->getBgColor()); loop->setPrimaryColor(loop->getBgColor());
loop->setSecondaryColor(loop->getFgColor()); loop->setSecondaryColor(loop->getFgColor());
@ -263,7 +263,7 @@ public:
bool needsSpecialSourceArea() const override { return true; } bool needsSpecialSourceArea() const override { return true; }
void prepareInk(ToolLoop* loop) override { void prepareInk(ToolLoop* loop) override {
m_proc = ink_processing[INK_BLUR][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<BlurInkProcessing>(loop->sprite()->pixelFormat());
} }
void inkHline(int x1, int y, int x2, ToolLoop* loop) override { void inkHline(int x1, int y, int x2, ToolLoop* loop) override {
@ -291,7 +291,7 @@ public:
bool needsSpecialSourceArea() const override { return true; } bool needsSpecialSourceArea() const override { return true; }
void prepareInk(ToolLoop* loop) override { void prepareInk(ToolLoop* loop) override {
m_proc = ink_processing[INK_JUMBLE][MID(0, loop->sprite()->pixelFormat(), 2)]; m_proc = get_ink_proc<JumbleInkProcessing>(loop->sprite()->pixelFormat());
} }
void inkHline(int x1, int y, int x2, ToolLoop* loop) override { void inkHline(int x1, int y, int x2, ToolLoop* loop) override {
@ -313,12 +313,19 @@ class SelectionInk : public Ink {
bool m_modify_selection; bool m_modify_selection;
Mask m_mask; Mask m_mask;
Rect m_maxBounds; Rect m_maxBounds;
AlgoHLine m_proc;
public: public:
SelectionInk() { m_modify_selection = false; } SelectionInk() {
m_modify_selection = false;
}
Ink* clone() override { return new SelectionInk(*this); } Ink* clone() override { return new SelectionInk(*this); }
void prepareInk(ToolLoop* loop) override {
m_proc = get_ink_proc<XorInkProcessing>(loop->sprite()->pixelFormat());
}
bool isSelection() const override { return true; } bool isSelection() const override { return true; }
bool needsCelCoordinates() const override { bool needsCelCoordinates() const override {
return (m_modify_selection ? false: true); return (m_modify_selection ? false: true);
@ -340,8 +347,7 @@ public:
} }
// TODO show the selection-preview with a XOR color or something like that // TODO show the selection-preview with a XOR color or something like that
else { else {
ink_processing[INK_XOR][MID(0, loop->sprite()->pixelFormat(), 2)] (*m_proc)(x1, y, x2, loop);
(x1, y, x2, loop);
} }
} }