Skip to content

Commit

Permalink
support -alpha remove-opaque option
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Dec 31, 2023
1 parent 6c76d71 commit 0ce621f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
43 changes: 43 additions & 0 deletions MagickCore/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,49 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
image->alpha_trait=image->background_color.alpha_trait;
break;
}
case RemoveOpaqueAlphaChannel:
{
MagickBooleanType
opaque = MagickTrue;

/*
Remove opaque alpha channel.
*/
if ((image->alpha_trait & BlendPixelTrait) == 0)
break;
image_view=AcquireVirtualCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static) shared(opaque,status) \
magick_number_threads(image,image,image->rows,1)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
const Quantum
*magick_restrict p;

ssize_t
x;

if ((status == MagickFalse) || (opaque == MagickFalse))
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
if (GetPixelAlpha(image,p) != OpaqueAlpha)
opaque=MagickFalse;
p+=GetPixelChannels(image);
}
}
image_view=DestroyCacheView(image_view);
if (opaque != MagickFalse)
image->alpha_trait=UndefinedPixelTrait;
break;
}
case SetAlphaChannel:
{
if ((image->alpha_trait & BlendPixelTrait) == 0)
Expand Down
21 changes: 21 additions & 0 deletions MagickCore/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
extern "C" {
#endif

typedef enum
{
UndefinedAlphaChannel,
ActivateAlphaChannel,
AssociateAlphaChannel,
BackgroundAlphaChannel,
CopyAlphaChannel,
DeactivateAlphaChannel,
DiscreteAlphaChannel,
DisassociateAlphaChannel,
ExtractAlphaChannel,
OffAlphaChannel,
OnAlphaChannel,
OpaqueAlphaChannel,
RemoveAlphaChannel,
SetAlphaChannel,
ShapeAlphaChannel,
TransparentAlphaChannel,
RemoveOpaqueAlphaChannel
} AlphaChannelOption;

extern MagickExport Image
*ChannelFxImage(const Image *,const char *,ExceptionInfo *),
*CombineImages(const Image *,const ColorspaceType,ExceptionInfo *),
Expand Down
20 changes: 0 additions & 20 deletions MagickCore/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ extern "C" {
#define OpaqueAlpha ((Quantum) QuantumRange)
#define TransparentAlpha ((Quantum) 0)

typedef enum
{
UndefinedAlphaChannel,
ActivateAlphaChannel,
AssociateAlphaChannel,
BackgroundAlphaChannel,
CopyAlphaChannel,
DeactivateAlphaChannel,
DiscreteAlphaChannel,
DisassociateAlphaChannel,
ExtractAlphaChannel,
OffAlphaChannel,
OnAlphaChannel,
OpaqueAlphaChannel,
RemoveAlphaChannel,
SetAlphaChannel,
ShapeAlphaChannel,
TransparentAlphaChannel
} AlphaChannelOption;

typedef enum
{
UndefinedType,
Expand Down
2 changes: 2 additions & 0 deletions MagickCore/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "MagickCore/studio.h"
#include "MagickCore/artifact.h"
#include "MagickCore/cache.h"
#include "MagickCore/channel.h"
#include "MagickCore/color.h"
#include "MagickCore/compare.h"
#include "MagickCore/constitute.h"
Expand Down Expand Up @@ -115,6 +116,7 @@ static const OptionInfo
{ "On", OnAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Opaque", OpaqueAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Remove", RemoveAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "RemoveOpaque", RemoveOpaqueAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Set", SetAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Shape", ShapeAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Reset", SetAlphaChannel, DeprecateOptionFlag, MagickTrue },
Expand Down

0 comments on commit 0ce621f

Please sign in to comment.