This source file includes following definitions.
- ClearPixelIterator
- ClonePixelIterator
- DestroyPixelIterator
- IsPixelIterator
- NewPixelIterator
- PixelClearIteratorException
- NewPixelRegionIterator
- PixelGetCurrentIteratorRow
- PixelGetIteratorException
- PixelGetIteratorExceptionType
- PixelGetIteratorRow
- PixelGetNextIteratorRow
- PixelGetPreviousRow
- PixelGetPreviousIteratorRow
- PixelResetIterator
- PixelSetFirstIteratorRow
- PixelSetIteratorRow
- PixelSetLastIteratorRow
- PixelSyncIterator
#include "wand/studio.h"
#include "wand/MagickWand.h"
#include "wand/magick-wand-private.h"
#include "wand/pixel-iterator.h"
#include "wand/pixel-wand.h"
#include "wand/wand.h"
#define PixelIteratorId "PixelIterator"
struct _PixelIterator
{
size_t
id;
char
name[MaxTextExtent];
ExceptionInfo
*exception;
CacheView
*view;
RectangleInfo
region;
MagickBooleanType
active;
ssize_t
y;
PixelWand
**pixel_wands;
MagickBooleanType
debug;
size_t
signature;
};
WandExport void ClearPixelIterator(PixelIterator *iterator)
{
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
iterator->region.width);
ClearMagickException(iterator->exception);
iterator->pixel_wands=NewPixelWands(iterator->region.width);
iterator->active=MagickFalse;
iterator->y=0;
iterator->debug=IsEventLogging();
}
WandExport PixelIterator *ClonePixelIterator(const PixelIterator *iterator)
{
PixelIterator
*clone_iterator;
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
clone_iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*clone_iterator));
if (clone_iterator == (PixelIterator *) NULL)
ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
iterator->name);
(void) ResetMagickMemory(clone_iterator,0,sizeof(*clone_iterator));
clone_iterator->id=AcquireWandId();
(void) FormatLocaleString(clone_iterator->name,MaxTextExtent,"%s-%.20g",
PixelIteratorId,(double) clone_iterator->id);
clone_iterator->exception=AcquireExceptionInfo();
InheritException(clone_iterator->exception,iterator->exception);
clone_iterator->view=CloneCacheView(iterator->view);
clone_iterator->region=iterator->region;
clone_iterator->active=iterator->active;
clone_iterator->y=iterator->y;
clone_iterator->pixel_wands=ClonePixelWands((const PixelWand **)
iterator->pixel_wands,iterator->region.width);
clone_iterator->debug=iterator->debug;
if (clone_iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",
clone_iterator->name);
clone_iterator->signature=WandSignature;
return(clone_iterator);
}
WandExport PixelIterator *DestroyPixelIterator(PixelIterator *iterator)
{
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->view=DestroyCacheView(iterator->view);
iterator->pixel_wands=DestroyPixelWands(iterator->pixel_wands,
iterator->region.width);
iterator->exception=DestroyExceptionInfo(iterator->exception);
iterator->signature=(~WandSignature);
RelinquishWandId(iterator->id);
iterator=(PixelIterator *) RelinquishMagickMemory(iterator);
return(iterator);
}
WandExport MagickBooleanType IsPixelIterator(const PixelIterator *iterator)
{
size_t
length;
if (iterator == (const PixelIterator *) NULL)
return(MagickFalse);
if (iterator->signature != WandSignature)
return(MagickFalse);
length=strlen(PixelIteratorId);
if (LocaleNCompare(iterator->name,PixelIteratorId,length) != 0)
return(MagickFalse);
return(MagickTrue);
}
WandExport PixelIterator *NewPixelIterator(MagickWand *wand)
{
const char
*quantum;
ExceptionInfo
*exception;
Image
*image;
PixelIterator
*iterator;
size_t
depth;
CacheView
*view;
depth=MAGICKCORE_QUANTUM_DEPTH;
quantum=GetMagickQuantumDepth(&depth);
if (depth != MAGICKCORE_QUANTUM_DEPTH)
ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
assert(wand != (MagickWand *) NULL);
image=GetImageFromMagickWand(wand);
if (image == (Image *) NULL)
return((PixelIterator *) NULL);
exception=AcquireExceptionInfo();
view=AcquireVirtualCacheView(image,exception);
if (view == (CacheView *) NULL)
return((PixelIterator *) NULL);
iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
if (iterator == (PixelIterator *) NULL)
ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
GetExceptionMessage(errno));
(void) ResetMagickMemory(iterator,0,sizeof(*iterator));
iterator->id=AcquireWandId();
(void) FormatLocaleString(iterator->name,MaxTextExtent,"%s-%.20g",
PixelIteratorId,(double) iterator->id);
iterator->exception=exception;
iterator->view=view;
SetGeometry(image,&iterator->region);
iterator->region.width=image->columns;
iterator->region.height=image->rows;
iterator->region.x=0;
iterator->region.y=0;
iterator->pixel_wands=NewPixelWands(iterator->region.width);
iterator->y=0;
iterator->debug=IsEventLogging();
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->signature=WandSignature;
return(iterator);
}
WandExport MagickBooleanType PixelClearIteratorException(
PixelIterator *iterator)
{
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
ClearMagickException(iterator->exception);
return(MagickTrue);
}
WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,
const ssize_t x,const ssize_t y,const size_t width,const size_t height)
{
CacheView
*view;
const char
*quantum;
ExceptionInfo
*exception;
Image
*image;
PixelIterator
*iterator;
size_t
depth;
assert(wand != (MagickWand *) NULL);
depth=MAGICKCORE_QUANTUM_DEPTH;
quantum=GetMagickQuantumDepth(&depth);
if (depth != MAGICKCORE_QUANTUM_DEPTH)
ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
if ((width == 0) || (height == 0))
ThrowWandFatalException(WandError,"ZeroRegionSize",quantum);
image=GetImageFromMagickWand(wand);
if (image == (Image *) NULL)
return((PixelIterator *) NULL);
exception=AcquireExceptionInfo();
view=AcquireVirtualCacheView(image,exception);
if (view == (CacheView *) NULL)
return((PixelIterator *) NULL);
iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator));
if (iterator == (PixelIterator *) NULL)
ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
wand->name);
(void) ResetMagickMemory(iterator,0,sizeof(*iterator));
iterator->id=AcquireWandId();
(void) FormatLocaleString(iterator->name,MaxTextExtent,"%s-%.20g",
PixelIteratorId,(double) iterator->id);
iterator->exception=exception;
iterator->view=view;
SetGeometry(image,&iterator->region);
iterator->region.width=width;
iterator->region.height=height;
iterator->region.x=x;
iterator->region.y=y;
iterator->pixel_wands=NewPixelWands(iterator->region.width);
iterator->y=0;
iterator->debug=IsEventLogging();
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->signature=WandSignature;
return(iterator);
}
WandExport PixelWand **PixelGetCurrentIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
register const IndexPacket
*indexes;
register const PixelPacket
*pixels;
register ssize_t
x;
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
*number_wands=0;
iterator->active=MagickTrue;
pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
iterator->region.y+iterator->y,iterator->region.width,1,
iterator->exception);
if (pixels == (const PixelPacket *) NULL)
{
InheritException(iterator->exception,GetCacheViewException(
iterator->view));
return((PixelWand **) NULL);
}
indexes=GetCacheViewVirtualIndexQueue(iterator->view);
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetBlackQuantum(iterator->pixel_wands[x],
GetPixelBlack(indexes+x));
if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetIndex(iterator->pixel_wands[x],
GetPixelBlack(indexes+x));
*number_wands=iterator->region.width;
return(iterator->pixel_wands);
}
WandExport char *PixelGetIteratorException(const PixelIterator *iterator,
ExceptionType *severity)
{
char
*description;
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
assert(severity != (ExceptionType *) NULL);
*severity=iterator->exception->severity;
description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent,
sizeof(*description));
if (description == (char *) NULL)
ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
iterator->name);
*description='\0';
if (iterator->exception->reason != (char *) NULL)
(void) CopyMagickString(description,GetLocaleExceptionMessage(
iterator->exception->severity,iterator->exception->reason),MaxTextExtent);
if (iterator->exception->description != (char *) NULL)
{
(void) ConcatenateMagickString(description," (",MaxTextExtent);
(void) ConcatenateMagickString(description,GetLocaleExceptionMessage(
iterator->exception->severity,iterator->exception->description),
MaxTextExtent);
(void) ConcatenateMagickString(description,")",MaxTextExtent);
}
return(description);
}
WandExport ExceptionType PixelGetIteratorExceptionType(
const PixelIterator *iterator)
{
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
return(iterator->exception->severity);
}
WandExport ssize_t PixelGetIteratorRow(PixelIterator *iterator)
{
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
return(iterator->y);
}
WandExport PixelWand **PixelGetNextIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
register const IndexPacket
*indexes;
register const PixelPacket
*pixels;
register ssize_t
x;
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
*number_wands=0;
if (iterator->active != MagickFalse)
iterator->y++;
if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
return((PixelWand **) NULL);
pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
iterator->region.y+iterator->y,iterator->region.width,1,
iterator->exception);
if (pixels == (const PixelPacket *) NULL)
{
InheritException(iterator->exception,GetCacheViewException(
iterator->view));
return((PixelWand **) NULL);
}
indexes=GetCacheViewVirtualIndexQueue(iterator->view);
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetBlackQuantum(iterator->pixel_wands[x],
GetPixelBlack(indexes+x));
if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetIndex(iterator->pixel_wands[x],
GetPixelIndex(indexes+x));
*number_wands=iterator->region.width;
return(iterator->pixel_wands);
}
WandExport PixelWand **PixelGetPreviousRow(PixelIterator *iterator)
{
size_t
number_wands;
return(PixelGetPreviousIteratorRow(iterator,&number_wands));
}
WandExport PixelWand **PixelGetPreviousIteratorRow(PixelIterator *iterator,
size_t *number_wands)
{
register const IndexPacket
*indexes;
register const PixelPacket
*pixels;
register ssize_t
x;
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
*number_wands=0;
if (iterator->active != MagickFalse)
iterator->y--;
if (PixelSetIteratorRow(iterator,iterator->y) == MagickFalse)
return((PixelWand **) NULL);
pixels=GetCacheViewVirtualPixels(iterator->view,iterator->region.x,
iterator->region.y+iterator->y,iterator->region.width,1,
iterator->exception);
if (pixels == (const PixelPacket *) NULL)
{
InheritException(iterator->exception,GetCacheViewException(
iterator->view));
return((PixelWand **) NULL);
}
indexes=GetCacheViewVirtualIndexQueue(iterator->view);
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetQuantumColor(iterator->pixel_wands[x],pixels+x);
if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetBlackQuantum(iterator->pixel_wands[x],
GetPixelBlack(indexes+x));
if (GetCacheViewStorageClass(iterator->view) == PseudoClass)
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelSetIndex(iterator->pixel_wands[x],
GetPixelIndex(indexes+x));
*number_wands=iterator->region.width;
return(iterator->pixel_wands);
}
WandExport void PixelResetIterator(PixelIterator *iterator)
{
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->active=MagickFalse;
iterator->y=0;
}
WandExport void PixelSetFirstIteratorRow(PixelIterator *iterator)
{
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->active=MagickFalse;
iterator->y=iterator->region.y;
}
WandExport MagickBooleanType PixelSetIteratorRow(PixelIterator *iterator,
const ssize_t row)
{
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
if ((row < 0) || (row >= (ssize_t) iterator->region.height))
return(MagickFalse);
iterator->active=MagickTrue;
iterator->y=row;
return(MagickTrue);
}
WandExport void PixelSetLastIteratorRow(PixelIterator *iterator)
{
assert(iterator != (PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
iterator->active=MagickFalse;
iterator->y=(ssize_t) iterator->region.height-1;
}
WandExport MagickBooleanType PixelSyncIterator(PixelIterator *iterator)
{
ExceptionInfo
*exception;
register IndexPacket
*magick_restrict indexes;
register ssize_t
x;
register PixelPacket
*magick_restrict pixels;
assert(iterator != (const PixelIterator *) NULL);
assert(iterator->signature == WandSignature);
if (iterator->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name);
if (SetCacheViewStorageClass(iterator->view,DirectClass) == MagickFalse)
return(MagickFalse);
exception=iterator->exception;
pixels=GetCacheViewAuthenticPixels(iterator->view,iterator->region.x,
iterator->region.y+iterator->y,iterator->region.width,1,exception);
if (pixels == (PixelPacket *) NULL)
{
InheritException(iterator->exception,GetCacheViewException(
iterator->view));
return(MagickFalse);
}
indexes=GetCacheViewAuthenticIndexQueue(iterator->view);
for (x=0; x < (ssize_t) iterator->region.width; x++)
PixelGetQuantumColor(iterator->pixel_wands[x],pixels+x);
if (GetCacheViewColorspace(iterator->view) == CMYKColorspace)
for (x=0; x < (ssize_t) iterator->region.width; x++)
SetPixelBlack(indexes+x,PixelGetBlackQuantum(
iterator->pixel_wands[x]));
if (SyncCacheViewAuthenticPixels(iterator->view,exception) == MagickFalse)
{
InheritException(iterator->exception,GetCacheViewException(
iterator->view));
return(MagickFalse);
}
return(MagickTrue);
}