mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Remove INK_* constants and ink_processing[][] array
This commit is contained in:
parent
72ede7e642
commit
ceca640a98
@ -1066,46 +1066,26 @@ void BrushInkProcessing<IndexedTraits>::processPixel(int x, int y) {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum {
|
||||
INK_COPY,
|
||||
INK_LOCKALPHA,
|
||||
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)
|
||||
template<template<typename> class InkProcessing,
|
||||
typename ImageTraits>
|
||||
void ink_proc(int x1, int y, int x2, void* data)
|
||||
{
|
||||
ToolLoop* loop = reinterpret_cast<ToolLoop*>(data);
|
||||
InkProcessing ink(loop);
|
||||
InkProcessing<ImageTraits> ink(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) \
|
||||
{ ink_processing_algo<name<RgbTraits> >, \
|
||||
ink_processing_algo<name<GrayscaleTraits> >, \
|
||||
ink_processing_algo<name<IndexedTraits> > }
|
||||
|
||||
DEFINE_INK(CopyInkProcessing),
|
||||
DEFINE_INK(LockAlphaInkProcessing),
|
||||
DEFINE_INK(TransparentInkProcessing),
|
||||
DEFINE_INK(MergeInkProcessing),
|
||||
DEFINE_INK(BlurInkProcessing),
|
||||
DEFINE_INK(ReplaceInkProcessing),
|
||||
DEFINE_INK(JumbleInkProcessing),
|
||||
DEFINE_INK(ShadingInkProcessing),
|
||||
DEFINE_INK(XorInkProcessing),
|
||||
DEFINE_INK(BrushInkProcessing)
|
||||
};
|
||||
switch (pixelFormat) {
|
||||
case IMAGE_RGB: return ink_proc<InkProcessing, RgbTraits>;
|
||||
case IMAGE_GRAYSCALE: return ink_proc<InkProcessing, GrayscaleTraits>;
|
||||
case IMAGE_INDEXED: return ink_proc<InkProcessing, IndexedTraits>;
|
||||
}
|
||||
ASSERT(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
} // namespace tools
|
||||
|
@ -53,10 +53,10 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
int depth = MID(0, loop->sprite()->pixelFormat(), 2);
|
||||
auto pixelFormat = loop->sprite()->pixelFormat();
|
||||
|
||||
if (loop->getBrush()->type() == doc::kImageBrushType)
|
||||
m_proc = ink_processing[INK_BRUSH][depth];
|
||||
m_proc = get_ink_proc<BrushInkProcessing>(pixelFormat);
|
||||
else {
|
||||
switch (m_type) {
|
||||
case Simple: {
|
||||
@ -81,19 +81,19 @@ public:
|
||||
|
||||
// Use a faster ink, direct copy
|
||||
if (opaque)
|
||||
m_proc = ink_processing[INK_COPY][depth];
|
||||
m_proc = get_ink_proc<CopyInkProcessing>(pixelFormat);
|
||||
else
|
||||
m_proc = ink_processing[INK_TRANSPARENT][depth];
|
||||
m_proc = get_ink_proc<TransparentInkProcessing>(pixelFormat);
|
||||
break;
|
||||
}
|
||||
case Copy:
|
||||
m_proc = ink_processing[INK_COPY][depth];
|
||||
m_proc = get_ink_proc<CopyInkProcessing>(pixelFormat);
|
||||
break;
|
||||
case LockAlpha:
|
||||
m_proc = ink_processing[INK_LOCKALPHA][depth];
|
||||
m_proc = get_ink_proc<LockAlphaInkProcessing>(pixelFormat);
|
||||
break;
|
||||
default:
|
||||
m_proc = ink_processing[INK_TRANSPARENT][depth];
|
||||
m_proc = get_ink_proc<TransparentInkProcessing>(pixelFormat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ public:
|
||||
bool isShading() const override { return true; }
|
||||
|
||||
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 {
|
||||
@ -207,16 +207,16 @@ public:
|
||||
color_t secondary = app_get_color_to_clear_layer(loop->getLayer());
|
||||
|
||||
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 {
|
||||
// For opaque layers
|
||||
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
|
||||
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) {
|
||||
primary = loop->sprite()->transparentColor();
|
||||
@ -231,14 +231,14 @@ public:
|
||||
}
|
||||
|
||||
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->setSecondaryColor(loop->getBgColor());
|
||||
break;
|
||||
|
||||
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->setSecondaryColor(loop->getFgColor());
|
||||
@ -263,7 +263,7 @@ public:
|
||||
bool needsSpecialSourceArea() const override { return true; }
|
||||
|
||||
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 {
|
||||
@ -291,7 +291,7 @@ public:
|
||||
bool needsSpecialSourceArea() const override { return true; }
|
||||
|
||||
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 {
|
||||
@ -313,12 +313,19 @@ class SelectionInk : public Ink {
|
||||
bool m_modify_selection;
|
||||
Mask m_mask;
|
||||
Rect m_maxBounds;
|
||||
AlgoHLine m_proc;
|
||||
|
||||
public:
|
||||
SelectionInk() { m_modify_selection = false; }
|
||||
SelectionInk() {
|
||||
m_modify_selection = false;
|
||||
}
|
||||
|
||||
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 needsCelCoordinates() const override {
|
||||
return (m_modify_selection ? false: true);
|
||||
@ -340,8 +347,7 @@ public:
|
||||
}
|
||||
// TODO show the selection-preview with a XOR color or something like that
|
||||
else {
|
||||
ink_processing[INK_XOR][MID(0, loop->sprite()->pixelFormat(), 2)]
|
||||
(x1, y, x2, loop);
|
||||
(*m_proc)(x1, y, x2, loop);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user