Skip to content

Commit

Permalink
-alpha off-if-opaque turns off the alpha channel if its entirely opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jan 1, 2024
1 parent 1a1b0f9 commit 83002fb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
84 changes: 42 additions & 42 deletions magick/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,48 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
image->matte=MagickFalse;
break;
}
case OffIfOpaqueAlphaChannel:
{
MagickBooleanType
opaque = MagickTrue;

/*
Remove opaque alpha channel.
*/
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,4)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
const PixelPacket
*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 PixelPacket *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
if (GetPixelOpacity(p) != OpaqueOpacity)
opaque=MagickFalse;
p++;
}
}
image_view=DestroyCacheView(image_view);
if (opaque != MagickFalse)
image->matte=MagickFalse;
break;
}
case ResetAlphaChannel: /* deprecated */
case RemoveAlphaChannel:
case FlattenAlphaChannel:
{
Expand Down Expand Up @@ -976,48 +1018,6 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
image_view=DestroyCacheView(image_view);
return(status);
}
case DeactivateIfOpaqueAlphaChannel:
{
MagickBooleanType
opaque = MagickTrue;

/*
Remove opaque alpha channel.
*/
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,4)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
const PixelPacket
*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 PixelPacket *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
if (GetPixelOpacity(p) != OpaqueOpacity)
opaque=MagickFalse;
p++;
}
}
image_view=DestroyCacheView(image_view);
if (opaque != MagickFalse)
image->matte=MagickFalse;
break;
}
case ResetAlphaChannel: /* deprecated */
case OpaqueAlphaChannel:
{
status=SetImageOpacity(image,OpaqueOpacity);
Expand Down
2 changes: 1 addition & 1 deletion magick/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ typedef enum
RemoveAlphaChannel,
AssociateAlphaChannel,
DisassociateAlphaChannel,
DeactivateIfOpaqueAlphaChannel
OffIfOpaqueAlphaChannel
} AlphaChannelType;

extern MagickExport Image
Expand Down
2 changes: 1 addition & 1 deletion magick/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ static const OptionInfo
{ "Background", BackgroundAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Copy", CopyAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Deactivate", DeactivateAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "DeactivateIfOpaque", DeactivateIfOpaqueAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Disassociate", DisassociateAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Extract", ExtractAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Flatten", FlattenAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Off", DeactivateAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "OffIfOpaque", OffIfOpaqueAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "On", ActivateAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Opaque", OpaqueAlphaChannel, UndefinedOptionFlag, MagickFalse },
{ "Remove", RemoveAlphaChannel, UndefinedOptionFlag, MagickFalse },
Expand Down

0 comments on commit 83002fb

Please sign in to comment.