diff --git a/src/settings/ink_type.h b/src/settings/ink_type.h index 482329ae6..77a65f3e9 100644 --- a/src/settings/ink_type.h +++ b/src/settings/ink_type.h @@ -26,6 +26,7 @@ enum InkType { kDefaultInk, kOpaqueInk, + kPutAlphaInk, kMergeInk, kShadingInk, kReplaceInk, diff --git a/src/tools/ink_processing.h b/src/tools/ink_processing.h index cd8fd16b8..19f3e89e2 100644 --- a/src/tools/ink_processing.h +++ b/src/tools/ink_processing.h @@ -116,6 +116,45 @@ static void ink_hline8_opaque(int x1, int y, int x2, ToolLoop* loop) /* memset(((uint8_t**)data->dst_image->line)[y]+x1, data->color, x2-x1+1); */ } +////////////////////////////////////////////////////////////////////// +// Putalpha Ink +////////////////////////////////////////////////////////////////////// + +static void ink_hline32_putalpha(int x1, int y, int x2, ToolLoop* loop) +{ + int c = loop->getPrimaryColor(); + int opacity = loop->getOpacity(); + + DEFINE_INK_PROCESSING_DST + (RgbTraits, + *dst_address = _rgba(_rgba_getr(c), + _rgba_getg(c), + _rgba_getb(c), + opacity) + ); +} + +static void ink_hline16_putalpha(int x1, int y, int x2, ToolLoop* loop) +{ + int c = loop->getPrimaryColor(); + int opacity = loop->getOpacity(); + + DEFINE_INK_PROCESSING_DST + (GrayscaleTraits, + *dst_address = _graya(_graya_getv(c), + opacity) + ); +} + +static void ink_hline8_putalpha(int x1, int y, int x2, ToolLoop* loop) +{ + int c = loop->getPrimaryColor(); + + DEFINE_INK_PROCESSING_DST + (IndexedTraits, + *dst_address = c ); +} + ////////////////////////////////////////////////////////////////////// // Transparent Ink ////////////////////////////////////////////////////////////////////// @@ -484,6 +523,7 @@ static void ink_hline8_shading(int x1, int y, int x2, ToolLoop* loop) enum { INK_OPAQUE, + INK_PUTALPHA, INK_TRANSPARENT, INK_BLUR, INK_REPLACE, @@ -500,6 +540,7 @@ static AlgoHLine ink_processing[][3] = (AlgoHLine)ink_hline8_##name } DEF_INK(opaque), + DEF_INK(putalpha), DEF_INK(transparent), DEF_INK(blur), DEF_INK(replace), diff --git a/src/tools/inks.h b/src/tools/inks.h index 253b6742a..cc4a9b147 100644 --- a/src/tools/inks.h +++ b/src/tools/inks.h @@ -32,7 +32,7 @@ class PaintInk : public Ink { public: - enum Type { Normal, WithFg, WithBg }; + enum Type { Merge, WithFg, WithBg, Opaque, PutAlpha }; private: AlgoHLine m_proc; @@ -47,7 +47,7 @@ public: { switch (m_type) { - case Normal: + case Merge: // Do nothing, use the default colors break; @@ -64,9 +64,21 @@ public: break; } - m_proc = loop->getOpacity() == 255 ? - ink_processing[INK_OPAQUE][MID(0, loop->getSprite()->getPixelFormat(), 2)]: - ink_processing[INK_TRANSPARENT][MID(0, loop->getSprite()->getPixelFormat(), 2)]; + int depth = MID(0, loop->getSprite()->getPixelFormat(), 2); + + switch (m_type) { + case Opaque: + m_proc = ink_processing[INK_OPAQUE][depth]; + break; + case PutAlpha: + m_proc = ink_processing[INK_PUTALPHA][depth]; + break; + default: + m_proc = (loop->getOpacity() == 255 ? + ink_processing[INK_OPAQUE][depth]: + ink_processing[INK_TRANSPARENT][depth]); + break; + } } void inkHline(int x1, int y, int x2, ToolLoop* loop) diff --git a/src/tools/tool_box.cpp b/src/tools/tool_box.cpp index a8e4939d3..4dbd603ac 100644 --- a/src/tools/tool_box.cpp +++ b/src/tools/tool_box.cpp @@ -51,6 +51,8 @@ const char* WellKnownInks::Selection = "selection"; const char* WellKnownInks::Paint = "paint"; const char* WellKnownInks::PaintFg = "paint_fg"; const char* WellKnownInks::PaintBg = "paint_bg"; +const char* WellKnownInks::PaintOpaque = "paint_opaque"; +const char* WellKnownInks::PaintPutAlpha = "paint_put_alpha"; const char* WellKnownInks::Shading = "shading"; const char* WellKnownInks::Eraser = "eraser"; const char* WellKnownInks::ReplaceFgWithBg = "replace_fg_with_bg"; @@ -69,9 +71,11 @@ ToolBox::ToolBox() PRINTF("Toolbox module: installing\n"); m_inks[WellKnownInks::Selection] = new SelectionInk(); - m_inks[WellKnownInks::Paint] = new PaintInk(PaintInk::Normal); + m_inks[WellKnownInks::Paint] = new PaintInk(PaintInk::Merge); m_inks[WellKnownInks::PaintFg] = new PaintInk(PaintInk::WithFg); m_inks[WellKnownInks::PaintBg] = new PaintInk(PaintInk::WithBg); + m_inks[WellKnownInks::PaintOpaque] = new PaintInk(PaintInk::Opaque); + m_inks[WellKnownInks::PaintPutAlpha] = new PaintInk(PaintInk::PutAlpha); m_inks[WellKnownInks::Shading] = new ShadingInk(); m_inks[WellKnownInks::Eraser] = new EraserInk(EraserInk::Eraser); m_inks[WellKnownInks::ReplaceFgWithBg] = new EraserInk(EraserInk::ReplaceFgWithBg); diff --git a/src/tools/tool_box.h b/src/tools/tool_box.h index d6e2b1494..0499f634a 100644 --- a/src/tools/tool_box.h +++ b/src/tools/tool_box.h @@ -38,6 +38,8 @@ namespace WellKnownInks { extern const char* Paint; extern const char* PaintFg; extern const char* PaintBg; + extern const char* PaintOpaque; + extern const char* PaintPutAlpha; extern const char* Shading; extern const char* Eraser; extern const char* ReplaceFgWithBg; diff --git a/src/widgets/context_bar.cpp b/src/widgets/context_bar.cpp index f5280a671..f70a1889e 100644 --- a/src/widgets/context_bar.cpp +++ b/src/widgets/context_bar.cpp @@ -248,6 +248,7 @@ public: // The same order as in InkType addItem("Default"); addItem("Opaque"); + addItem("Put Alpha"); addItem("Merge"); addItem("Shading"); addItem("Replace"); diff --git a/src/widgets/editor/tool_loop_impl.cpp b/src/widgets/editor/tool_loop_impl.cpp index 1fd6cebc1..11b43f8dd 100644 --- a/src/widgets/editor/tool_loop_impl.cpp +++ b/src/widgets/editor/tool_loop_impl.cpp @@ -276,7 +276,10 @@ private: const char* id = WellKnownInks::Paint; switch (inkType) { case kOpaqueInk: - id = WellKnownInks::Paint; + id = WellKnownInks::PaintOpaque; + break; + case kPutAlphaInk: + id = WellKnownInks::PaintPutAlpha; break; case kMergeInk: id = WellKnownInks::Paint; @@ -303,6 +306,7 @@ private: id = WellKnownInks::Jumble; break; } + return App::instance()->getToolBox()->getInkById(id); }