From ae7904e7a87c0d5ef17b4bfeddbf3221d6a7325f Mon Sep 17 00:00:00 2001 From: Austin Blanton Date: Thu, 28 Aug 2014 14:23:06 -0400 Subject: [PATCH] Add DiscardAlphaTransform to drop 4th channel if exists --- openbr/plugins/cvt.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+), 0 deletions(-) diff --git a/openbr/plugins/cvt.cpp b/openbr/plugins/cvt.cpp index fc8d9fb..2dedfcd 100644 --- a/openbr/plugins/cvt.cpp +++ b/openbr/plugins/cvt.cpp @@ -162,6 +162,34 @@ BR_REGISTER(Transform, EnsureChannelsTransform) /*! * \ingroup transforms + * \brief Drop the alpha channel (if exists). + * \author Austin Blanton \cite imaus10 + */ +class DiscardAlphaTransform : public UntrainableTransform +{ + Q_OBJECT + + void project(const Template &src, Template &dst) const + { + if (src.m().channels() > 4 || src.m().channels() == 2) { + dst.file.fte = true; + return; + } + + dst = src; + if (src.m().channels() == 4) { + std::vector mv; + split(src, mv); + mv.pop_back(); + merge(mv, dst); + } + } +}; + +BR_REGISTER(Transform, DiscardAlphaTransform) + +/*! + * \ingroup transforms * \brief Normalized RG color space. * \author Josh Klontz \cite jklontz */ -- libgit2 0.21.4