本文整理汇总了C++中RelinquishMagickMemory函数的典型用法代码示例。如果您正苦于以下问题:C++ RelinquishMagickMemory函数的具体用法?C++ RelinquishMagickMemory怎么用?C++ RelinquishMagickMemory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RelinquishMagickMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MergeConnectedComponents
//.........这里部分代码省略.........
object[i].area++;
p+=GetPixelChannels(image);
}
}
image_view=DestroyCacheView(image_view);
for (i=0; i < (ssize_t) number_objects; i++)
{
object[i].bounding_box.width-=(object[i].bounding_box.x-1);
object[i].bounding_box.height-=(object[i].bounding_box.y-1);
}
/*
Merge objects below area threshold.
*/
image_view=AcquireAuthenticCacheView(image,exception);
for (i=0; i < (ssize_t) number_objects; i++)
{
double
census;
RectangleInfo
bounding_box;
register ssize_t
j;
size_t
id;
if (status == MagickFalse)
continue;
if ((double) object[i].area >= area_threshold)
continue;
for (j=0; j < (ssize_t) number_objects; j++)
object[j].census=0;
bounding_box=object[i].bounding_box;
for (y=0; y < (ssize_t) bounding_box.height+2; y++)
{
register const Quantum
*magick_restrict p;
register ssize_t
x;
if (status == MagickFalse)
continue;
p=GetCacheViewVirtualPixels(image_view,bounding_box.x-1,bounding_box.y+y-
1,bounding_box.width+2,1,exception);
if (p == (const Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) bounding_box.width+2; x++)
{
j=(ssize_t) GetPixelIntensity(image,p);
if (j != i)
object[j].census++;
p+=GetPixelChannels(image);
}
}
census=0;
id=0;
for (j=0; j < (ssize_t) number_objects; j++)
if (census < object[j].census)
{
census=object[j].census;
id=(size_t) j;
}
object[id].area+=object[i].area;
for (y=0; y < (ssize_t) bounding_box.height; y++)
{
register Quantum
*magick_restrict q;
register ssize_t
x;
if (status == MagickFalse)
continue;
q=GetCacheViewAuthenticPixels(image_view,bounding_box.x,bounding_box.y+y,
bounding_box.width,1,exception);
if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) bounding_box.width; x++)
{
if ((ssize_t) GetPixelIntensity(image,q) == i)
*q=(Quantum) id;
q+=GetPixelChannels(image);
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
}
}
image_view=DestroyCacheView(image_view);
object=(CCObject *) RelinquishMagickMemory(object);
return(status);
}
示例2: load_tile_rle
//.........这里部分代码省略.........
SetPixelGray(tile_image,ScaleCharToQuantum(data),q);
else
{
SetPixelRed(tile_image,ScaleCharToQuantum(data),q);
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
}
SetPixelAlpha(tile_image,alpha,q);
break;
}
case 1:
{
if (inDocInfo->image_type == GIMP_GRAY)
SetPixelAlpha(tile_image,ScaleCharToQuantum(data),q);
else
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
break;
}
case 2:
{
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
break;
}
case 3:
{
SetPixelAlpha(tile_image,ScaleCharToQuantum(data),q);
break;
}
}
q+=GetPixelChannels(tile_image);
}
}
else
{
length+=1;
if (length == 128)
{
if (xcfdata >= xcfdatalimit)
goto bogus_rle;
length=(size_t) ((*xcfdata << 8) + xcfdata[1]);
xcfdata+=2;
}
size-=length;
if (size < 0)
goto bogus_rle;
if (xcfdata > xcfdatalimit)
goto bogus_rle;
pixel=(*xcfdata++);
for (j=0; j < (ssize_t) length; j++)
{
data=pixel;
switch (i)
{
case 0:
{
if (inDocInfo->image_type == GIMP_GRAY)
SetPixelGray(tile_image,ScaleCharToQuantum(data),q);
else
{
SetPixelRed(tile_image,ScaleCharToQuantum(data),q);
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
}
SetPixelAlpha(tile_image,alpha,q);
break;
}
case 1:
{
if (inDocInfo->image_type == GIMP_GRAY)
SetPixelAlpha(tile_image,ScaleCharToQuantum(data),q);
else
SetPixelGreen(tile_image,ScaleCharToQuantum(data),q);
break;
}
case 2:
{
SetPixelBlue(tile_image,ScaleCharToQuantum(data),q);
break;
}
case 3:
{
SetPixelAlpha(tile_image,ScaleCharToQuantum(data),q);
break;
}
}
q+=GetPixelChannels(tile_image);
}
}
}
if (SyncAuthenticPixels(tile_image,exception) == MagickFalse)
break;
}
xcfodata=(unsigned char *) RelinquishMagickMemory(xcfodata);
return(MagickTrue);
bogus_rle:
if (xcfodata != (unsigned char *) NULL)
xcfodata=(unsigned char *) RelinquishMagickMemory(xcfodata);
return(MagickFalse);
}
示例3: SerializeImage
static MagickBooleanType SerializeImage(const ImageInfo *image_info,
Image *image,unsigned char **pixels,size_t *length)
{
long
y;
MagickBooleanType
status;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register long
x;
register unsigned char
*q;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=MagickTrue;
*length=(image->colorspace == CMYKColorspace ? 4 : 3)*
(size_t) image->columns*image->rows;
*pixels=(unsigned char *) AcquireQuantumMemory(*length,sizeof(**pixels));
if (*pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
q=(*pixels);
for (y=0; y < (long) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetVirtualIndexQueue(image);
if (image->colorspace != CMYKColorspace)
for (x=0; x < (long) image->columns; x++)
{
*q++=ScaleQuantumToChar(p->red);
*q++=ScaleQuantumToChar(p->green);
*q++=ScaleQuantumToChar(p->blue);
p++;
}
else
for (x=0; x < (long) image->columns; x++)
{
*q++=ScaleQuantumToChar(p->red);
*q++=ScaleQuantumToChar(p->green);
*q++=ScaleQuantumToChar(p->blue);
*q++=ScaleQuantumToChar(indexes[x]);
p++;
}
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,y,image->rows);
if (status == MagickFalse)
break;
}
}
if (status == MagickFalse)
*pixels=(unsigned char *) RelinquishMagickMemory(*pixels);
return(status);
}
示例4: LoadCoderList
static MagickBooleanType LoadCoderList(const char *xml,const char *filename,
const size_t depth,ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
*token;
const char
*q;
CoderInfo
*coder_info;
MagickBooleanType
status;
/*
Load the coder map file.
*/
(void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
"Loading coder configuration file \"%s\" ...",filename);
if (xml == (const char *) NULL)
return(MagickFalse);
if (coder_list == (SplayTreeInfo *) NULL)
{
coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
DestroyCoderNode);
if (coder_list == (SplayTreeInfo *) NULL)
{
ThrowFileException(exception,ResourceLimitError,
"MemoryAllocationFailed",filename);
return(MagickFalse);
}
}
status=MagickTrue;
coder_info=(CoderInfo *) NULL;
token=AcquireString(xml);
for (q=(char *) xml; *q != '\0'; )
{
/*
Interpret XML.
*/
GetMagickToken(q,&q,token);
if (*token == '\0')
break;
(void) CopyMagickString(keyword,token,MaxTextExtent);
if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
{
/*
Doctype element.
*/
while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
GetMagickToken(q,&q,token);
continue;
}
if (LocaleNCompare(keyword,"<!--",4) == 0)
{
/*
Comment element.
*/
while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
GetMagickToken(q,&q,token);
continue;
}
if (LocaleCompare(keyword,"<include") == 0)
{
/*
Include element.
*/
while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
{
(void) CopyMagickString(keyword,token,MaxTextExtent);
GetMagickToken(q,&q,token);
if (*token != '=')
continue;
GetMagickToken(q,&q,token);
if (LocaleCompare(keyword,"file") == 0)
{
if (depth > 200)
(void) ThrowMagickException(exception,GetMagickModule(),
ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
else
{
char
path[MaxTextExtent],
*xml;
GetPathComponent(filename,HeadPath,path);
if (*path != '\0')
(void) ConcatenateMagickString(path,DirectorySeparator,
MaxTextExtent);
if (*token == *DirectorySeparator)
(void) CopyMagickString(path,token,MaxTextExtent);
else
(void) ConcatenateMagickString(path,token,MaxTextExtent);
xml=FileToString(path,~0,exception);
if (xml != (char *) NULL)
{
status=LoadCoderList(xml,path,depth+1,exception);
xml=(char *) RelinquishMagickMemory(xml);
//.........这里部分代码省略.........
示例5: WritePS2Image
//.........这里部分代码省略.........
if ((double) (geometry.y+(geometry.height+text_size)-1) > bounds.y2)
bounds.y2=(double) geometry.y+(geometry.height+text_size)-1;
value=GetImageProperty(image,"label",exception);
if (value != (const char *) NULL)
(void) WriteBlobString(image,"%%PageResources: font Times-Roman\n");
if (LocaleCompare(image_info->magick,"PS2") != 0)
(void) WriteBlobString(image,"userdict begin\n");
start=TellBlob(image);
(void) FormatLocaleString(buffer,MagickPathExtent,
"%%%%BeginData:%13ld %s Bytes\n",0L,
compression == NoCompression ? "ASCII" : "Binary");
(void) WriteBlobString(image,buffer);
stop=TellBlob(image);
(void) WriteBlobString(image,"DisplayImage\n");
/*
Output image data.
*/
(void) FormatLocaleString(buffer,MagickPathExtent,"%.20g %.20g\n%g %g\n%g\n",
(double) geometry.x,(double) geometry.y,scale.x,scale.y,pointsize);
(void) WriteBlobString(image,buffer);
labels=(char **) NULL;
value=GetImageProperty(image,"label",exception);
if (value != (const char *) NULL)
labels=StringToList(value);
if (labels != (char **) NULL)
{
for (i=0; labels[i] != (char *) NULL; i++)
{
(void) FormatLocaleString(buffer,MagickPathExtent,"%s \n",
labels[i]);
(void) WriteBlobString(image,buffer);
labels[i]=DestroyString(labels[i]);
}
labels=(char **) RelinquishMagickMemory(labels);
}
number_pixels=(MagickSizeType) image->columns*image->rows;
if (number_pixels != (MagickSizeType) ((size_t) number_pixels))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
if ((compression == FaxCompression) || (compression == Group4Compression) ||
((image_info->type != TrueColorType) &&
(SetImageGray(image,exception) != MagickFalse)))
{
(void) FormatLocaleString(buffer,MagickPathExtent,"%.20g %.20g\n1\n%d\n",
(double) image->columns,(double) image->rows,(int)
(image->colorspace == CMYKColorspace));
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MagickPathExtent,"%d\n",
(int) ((compression != FaxCompression) &&
(compression != Group4Compression)));
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"0\n");
(void) FormatLocaleString(buffer,MagickPathExtent,"%d\n",
(compression == FaxCompression) ||
(compression == Group4Compression) ? 1 : 8);
(void) WriteBlobString(image,buffer);
switch (compression)
{
case FaxCompression:
case Group4Compression:
{
if (LocaleCompare(CCITTParam,"0") == 0)
{
(void) HuffmanEncodeImage(image_info,image,image,exception);
break;
}
(void) Huffman2DEncodeImage(image_info,image,image,exception);
示例6: ListTypeInfo
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L i s t T y p e I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ListTypeInfo() lists the fonts to a file.
%
% The format of the ListTypeInfo method is:
%
% MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o file: An pointer to a FILE.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType ListTypeInfo(FILE *file,ExceptionInfo *exception)
{
char
weight[MaxTextExtent];
const char
*family,
*glyphs,
*name,
*path,
*stretch,
*style;
const TypeInfo
**type_info;
register ssize_t
i;
size_t
number_fonts;
if (file == (FILE *) NULL)
file=stdout;
number_fonts=0;
type_info=GetTypeInfoList("*",&number_fonts,exception);
if (type_info == (const TypeInfo **) NULL)
return(MagickFalse);
*weight='\0';
path=(const char *) NULL;
for (i=0; i < (ssize_t) number_fonts; i++)
{
if (type_info[i]->stealth != MagickFalse)
continue;
if (((path == (const char *) NULL) ||
(LocaleCompare(path,type_info[i]->path) != 0)) &&
(type_info[i]->path != (char *) NULL))
(void) FormatLocaleFile(file,"\nPath: %s\n",type_info[i]->path);
path=type_info[i]->path;
name="unknown";
if (type_info[i]->name != (char *) NULL)
name=type_info[i]->name;
family="unknown";
if (type_info[i]->family != (char *) NULL)
family=type_info[i]->family;
style=CommandOptionToMnemonic(MagickStyleOptions,type_info[i]->style);
stretch=CommandOptionToMnemonic(MagickStretchOptions,type_info[i]->stretch);
glyphs="unknown";
if (type_info[i]->glyphs != (char *) NULL)
glyphs=type_info[i]->glyphs;
(void) FormatLocaleString(weight,MaxTextExtent,"%.20g",(double)
type_info[i]->weight);
(void) FormatLocaleFile(file," Font: %s\n",name);
(void) FormatLocaleFile(file," family: %s\n",family);
(void) FormatLocaleFile(file," style: %s\n",style);
(void) FormatLocaleFile(file," stretch: %s\n",stretch);
(void) FormatLocaleFile(file," weight: %s\n",weight);
(void) FormatLocaleFile(file," glyphs: %s\n",glyphs);
}
(void) fflush(file);
type_info=(const TypeInfo **) RelinquishMagickMemory((void *) type_info);
return(MagickTrue);
}
示例7: ListMagicInfo
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L i s t M a g i c I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ListMagicInfo() lists the magic info to a file.
%
% The format of the ListMagicInfo method is:
%
% MagickBooleanType ListMagicInfo(FILE *file,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o file: An pointer to a FILE.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType ListMagicInfo(FILE *file,
ExceptionInfo *exception)
{
const char
*path;
const MagicInfo
**magic_info;
register ssize_t
i;
size_t
number_aliases;
ssize_t
j;
if (file == (const FILE *) NULL)
file=stdout;
magic_info=GetMagicInfoList("*",&number_aliases,exception);
if (magic_info == (const MagicInfo **) NULL)
return(MagickFalse);
j=0;
path=(const char *) NULL;
for (i=0; i < (ssize_t) number_aliases; i++)
{
if (magic_info[i]->stealth != MagickFalse)
continue;
if ((path == (const char *) NULL) ||
(LocaleCompare(path,magic_info[i]->path) != 0))
{
if (magic_info[i]->path != (char *) NULL)
(void) FormatLocaleFile(file,"\nPath: %s\n\n",magic_info[i]->path);
(void) FormatLocaleFile(file,"Name Offset Target\n");
(void) FormatLocaleFile(file,
"-------------------------------------------------"
"------------------------------\n");
}
path=magic_info[i]->path;
(void) FormatLocaleFile(file,"%s",magic_info[i]->name);
for (j=(ssize_t) strlen(magic_info[i]->name); j <= 9; j++)
(void) FormatLocaleFile(file," ");
(void) FormatLocaleFile(file,"%6ld ",(long) magic_info[i]->offset);
if (magic_info[i]->target != (char *) NULL)
{
register ssize_t
j;
for (j=0; magic_info[i]->target[j] != '\0'; j++)
if (isprint((int) ((unsigned char) magic_info[i]->target[j])) != 0)
(void) FormatLocaleFile(file,"%c",magic_info[i]->target[j]);
else
(void) FormatLocaleFile(file,"\\%03o",(unsigned int)
((unsigned char) magic_info[i]->target[j]));
}
(void) FormatLocaleFile(file,"\n");
}
(void) fflush(file);
magic_info=(const MagicInfo **) RelinquishMagickMemory((void *) magic_info);
return(MagickTrue);
}
示例8: WriteHRZImage
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e H R Z I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteHRZImage() writes an image to a file in HRZ X image format.
%
% The format of the WriteHRZImage method is:
%
% MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
{
Image
*hrz_image;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x,
y;
register unsigned char
*q;
ssize_t
count;
unsigned char
*pixels;
/*
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
hrz_image=ResizeImage(image,256,240,image->filter,image->blur,
&image->exception);
if (hrz_image == (Image *) NULL)
return(MagickFalse);
(void) TransformImageColorspace(hrz_image,sRGBColorspace);
/*
Allocate memory for pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns,
3*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
{
hrz_image=DestroyImage(hrz_image);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
/*
Convert MIFF to HRZ raster pixels.
*/
for (y=0; y < (ssize_t) hrz_image->rows; y++)
{
p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
q=pixels;
for (x=0; x < (ssize_t) hrz_image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelRed(p)/4);
*q++=ScaleQuantumToChar(GetPixelGreen(p)/4);
*q++=ScaleQuantumToChar(GetPixelBlue(p)/4);
p++;
}
count=WriteBlob(image,(size_t) (q-pixels),pixels);
if (count != (ssize_t) (q-pixels))
break;
status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
hrz_image=DestroyImage(hrz_image);
//.........这里部分代码省略.........
示例9: ReadHRZImage
//.........这里部分代码省略.........
%
% Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o exception: return any errors or warnings in this structure.
%
*/
static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
ssize_t
count,
y;
size_t
length;
unsigned char
*pixels;
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Convert HRZ raster image to pixel packets.
*/
image->columns=256;
image->rows=240;
image->depth=8;
status=SetImageExtent(image,image->columns,image->rows);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
return(DestroyImageList(image));
}
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,3*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) (3*image->columns);
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if ((size_t) count != length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(4**p++));
SetPixelGreen(q,ScaleCharToQuantum(4**p++));
SetPixelBlue(q,ScaleCharToQuantum(4**p++));
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
示例10: assert
//.........这里部分代码省略.........
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Read image into a buffer.
*/
buffer=(unsigned char *) AcquireQuantumMemory((size_t) GetBlobSize(image),
sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,(size_t) GetBlobSize(image),buffer);
if ((count == 0) || (LocaleNCompare((char *) buffer,"SFW",3) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
image=DestroyImage(image);
/*
Find the start of the JFIF data
*/
header=SFWScan(buffer,buffer+count-1,(const unsigned char *)
"\377\310\377\320",4);
if (header == (unsigned char *) NULL)
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
TranslateSFWMarker(header); /* translate soi and app tags */
TranslateSFWMarker(header+2);
(void) CopyMagickMemory(header+6,"JFIF\0\001\0",7); /* JFIF magic */
/*
Translate remaining markers.
*/
offset=header+2;
offset+=(offset[2] << 8)+offset[3]+2;
for ( ; ; )
{
TranslateSFWMarker(offset);
if (offset[1] == 0xda)
break;
offset+=(offset[2] << 8)+offset[3]+2;
}
offset--;
data=SFWScan(offset,buffer+count-1,(const unsigned char *) "\377\311",2);
if (data == (unsigned char *) NULL)
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
TranslateSFWMarker(data++); /* translate eoi marker */
/*
Write JFIF file.
*/
read_info=CloneImageInfo(image_info);
read_info->blob=(void *) NULL;
read_info->length=0;
file=(FILE *) NULL;
示例11: GetImageChannelDepth
MagickExport size_t GetImageChannelDepth(const Image *image,
const ChannelType channel,ExceptionInfo *exception)
{
CacheView
*image_view;
ssize_t
y;
MagickBooleanType
status;
register ssize_t
id;
size_t
*current_depth,
depth,
number_threads;
/*
Compute image depth.
*/
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
number_threads=GetOpenMPMaximumThreads();
current_depth=(size_t *) AcquireQuantumMemory(number_threads,
sizeof(*current_depth));
if (current_depth == (size_t *) NULL)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
status=MagickTrue;
for (id=0; id < (ssize_t) number_threads; id++)
current_depth[id]=1;
if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse))
{
register const PixelPacket
*restrict p;
register ssize_t
i;
p=image->colormap;
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(dynamic,4) shared(status)
#endif
for (i=0; i < (ssize_t) image->colors; i++)
{
const int
id = GetOpenMPThreadId();
if (status == MagickFalse)
continue;
while (current_depth[id] < MAGICKCORE_QUANTUM_DEPTH)
{
MagickStatusType
status;
QuantumAny
range;
status=0;
range=GetQuantumRange(current_depth[id]);
if ((channel & RedChannel) != 0)
status|=p->red != ScaleAnyToQuantum(ScaleQuantumToAny(p->red,
range),range);
if ((channel & GreenChannel) != 0)
status|=p->green != ScaleAnyToQuantum(ScaleQuantumToAny(p->green,
range),range);
if ((channel & BlueChannel) != 0)
status|=p->blue != ScaleAnyToQuantum(ScaleQuantumToAny(p->blue,
range),range);
if (status == 0)
break;
current_depth[id]++;
}
p++;
}
depth=current_depth[0];
for (id=1; id < (ssize_t) number_threads; id++)
if (depth < current_depth[id])
depth=current_depth[id];
current_depth=(size_t *) RelinquishMagickMemory(current_depth);
return(depth);
}
image_view=AcquireCacheView(image);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(dynamic,4) shared(status)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
const int
id = GetOpenMPThreadId();
register const IndexPacket
*restrict indexes;
register const PixelPacket
*restrict p;
//.........这里部分代码省略.........
示例12: ReadVIFFImage
//.........这里部分代码省略.........
{
MSBOrderLong(viff_colormap,(bytes_per_pixel*image->colors*
viff_info.map_rows));
break;
}
default: break;
}
for (i=0; i < (ssize_t) (viff_info.map_rows*image->colors); i++)
{
switch ((int) viff_info.map_storage_type)
{
case VFF_MAPTYP_2_BYTE: value=1.0*((short *) viff_colormap)[i]; break;
case VFF_MAPTYP_4_BYTE: value=1.0*((int *) viff_colormap)[i]; break;
case VFF_MAPTYP_FLOAT: value=((float *) viff_colormap)[i]; break;
case VFF_MAPTYP_DOUBLE: value=((double *) viff_colormap)[i]; break;
default: value=1.0*viff_colormap[i]; break;
}
if (i < (ssize_t) image->colors)
{
image->colormap[i].red=ScaleCharToQuantum((unsigned char) value);
image->colormap[i].green=
ScaleCharToQuantum((unsigned char) value);
image->colormap[i].blue=ScaleCharToQuantum((unsigned char) value);
}
else
if (i < (ssize_t) (2*image->colors))
image->colormap[i % image->colors].green=
ScaleCharToQuantum((unsigned char) value);
else
if (i < (ssize_t) (3*image->colors))
image->colormap[i % image->colors].blue=
ScaleCharToQuantum((unsigned char) value);
}
viff_colormap=(unsigned char *) RelinquishMagickMemory(viff_colormap);
break;
}
default:
ThrowReaderException(CoderError,"ColormapTypeNotSupported");
}
/*
Initialize image structure.
*/
image->alpha_trait=viff_info.number_data_bands == 4 ? BlendPixelTrait :
UndefinedPixelTrait;
image->storage_class=(viff_info.number_data_bands < 3 ? PseudoClass :
DirectClass);
image->columns=viff_info.rows;
image->rows=viff_info.columns;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
/*
Allocate VIFF pixels.
*/
switch ((int) viff_info.data_storage_type)
{
case VFF_TYP_2_BYTE: bytes_per_pixel=2; break;
case VFF_TYP_4_BYTE: bytes_per_pixel=4; break;
case VFF_TYP_FLOAT: bytes_per_pixel=4; break;
case VFF_TYP_DOUBLE: bytes_per_pixel=8; break;
default: bytes_per_pixel=1; break;
}
if (viff_info.data_storage_type == VFF_TYP_BIT)
示例13: AccelerateConvolveImage
MagickExport MagickBooleanType AccelerateConvolveImage(const Image *image,
const KernelInfo *kernel,Image *convolve_image,ExceptionInfo *exception)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(kernel != (KernelInfo *) NULL);
assert(kernel->signature == MagickSignature);
assert(convolve_image != (Image *) NULL);
assert(convolve_image->signature == MagickSignature);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
if ((image->storage_class != DirectClass) ||
(image->colorspace == CMYKColorspace))
return(MagickFalse);
if ((GetImageVirtualPixelMethod(image) != UndefinedVirtualPixelMethod) &&
(GetImageVirtualPixelMethod(image) != EdgeVirtualPixelMethod))
return(MagickFalse);
#if !defined(MAGICKCORE_OPENCL_SUPPORT)
return(MagickFalse);
#else
{
const void
*pixels;
float
*filter;
ConvolveInfo
*convolve_info;
MagickBooleanType
status;
MagickSizeType
length;
register ssize_t
i;
void
*convolve_pixels;
convolve_info=GetConvolveInfo(image,"Convolve",ConvolveKernel,exception);
if (convolve_info == (ConvolveInfo *) NULL)
return(MagickFalse);
pixels=AcquirePixelCachePixels(image,&length,exception);
if (pixels == (const void *) NULL)
{
convolve_info=DestroyConvolveInfo(convolve_info);
(void) ThrowMagickException(exception,GetMagickModule(),CacheError,
"UnableToReadPixelCache","`%s'",image->filename);
return(MagickFalse);
}
convolve_pixels=GetPixelCachePixels(convolve_image,&length,exception);
if (convolve_pixels == (void *) NULL)
{
convolve_info=DestroyConvolveInfo(convolve_info);
(void) ThrowMagickException(exception,GetMagickModule(),CacheError,
"UnableToReadPixelCache","`%s'",image->filename);
return(MagickFalse);
}
filter=(float *) AcquireQuantumMemory(kernel->width,kernel->height*
sizeof(*filter));
if (filter == (float *) NULL)
{
DestroyConvolveBuffers(convolve_info);
convolve_info=DestroyConvolveInfo(convolve_info);
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(MagickFalse);
}
for (i=0; i < (ssize_t) (kernel->width*kernel->height); i++)
filter[i]=(float) kernel->values[i];
status=BindConvolveParameters(convolve_info,image,pixels,filter,
kernel->width,kernel->height,convolve_pixels);
if (status == MagickFalse)
{
filter=(float *) RelinquishMagickMemory(filter);
DestroyConvolveBuffers(convolve_info);
convolve_info=DestroyConvolveInfo(convolve_info);
return(MagickFalse);
}
status=EnqueueConvolveKernel(convolve_info,image,pixels,filter,
kernel->width,kernel->height,convolve_pixels);
filter=(float *) RelinquishMagickMemory(filter);
if (status == MagickFalse)
{
DestroyConvolveBuffers(convolve_info);
convolve_info=DestroyConvolveInfo(convolve_info);
return(MagickFalse);
}
DestroyConvolveBuffers(convolve_info);
convolve_info=DestroyConvolveInfo(convolve_info);
return(MagickTrue);
}
#endif
}
示例14: StatisticsComponentsStatistics
//.........这里部分代码省略.........
object=(CCObject *) AcquireQuantumMemory(number_objects,sizeof(*object));
if (object == (CCObject *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(MagickFalse);
}
(void) ResetMagickMemory(object,0,number_objects*sizeof(*object));
for (i=0; i < (ssize_t) number_objects; i++)
{
object[i].id=i;
object[i].bounding_box.x=(ssize_t) component_image->columns;
object[i].bounding_box.y=(ssize_t) component_image->rows;
GetPixelInfo(image,&object[i].color);
}
status=MagickTrue;
image_view=AcquireVirtualCacheView(image,exception);
component_view=AcquireVirtualCacheView(component_image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
register const Quantum
*magick_restrict p,
*magick_restrict q;
register ssize_t
x;
if (status == MagickFalse)
continue;
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
q=GetCacheViewVirtualPixels(component_view,0,y,component_image->columns,1,
exception);
if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL))
{
status=MagickFalse;
continue;
}
for (x=0; x < (ssize_t) image->columns; x++)
{
i=(ssize_t) GetPixelIntensity(image,q);
if (x < object[i].bounding_box.x)
object[i].bounding_box.x=x;
if (x > (ssize_t) object[i].bounding_box.width)
object[i].bounding_box.width=(size_t) x;
if (y < object[i].bounding_box.y)
object[i].bounding_box.y=y;
if (y > (ssize_t) object[i].bounding_box.height)
object[i].bounding_box.height=(size_t) y;
object[i].color.red+=GetPixelRed(image,p);
object[i].color.green+=GetPixelGreen(image,p);
object[i].color.blue+=GetPixelBlue(image,p);
object[i].color.alpha+=GetPixelAlpha(image,p);
object[i].color.black+=GetPixelBlack(image,p);
object[i].centroid.x+=x;
object[i].centroid.y+=y;
object[i].area++;
p+=GetPixelChannels(image);
q+=GetPixelChannels(component_image);
}
}
for (i=0; i < (ssize_t) number_objects; i++)
{
object[i].bounding_box.width-=(object[i].bounding_box.x-1);
object[i].bounding_box.height-=(object[i].bounding_box.y-1);
object[i].color.red=object[i].color.red/object[i].area;
object[i].color.green=object[i].color.green/object[i].area;
object[i].color.blue=object[i].color.blue/object[i].area;
object[i].color.alpha=object[i].color.alpha/object[i].area;
object[i].color.black=object[i].color.black/object[i].area;
object[i].centroid.x=object[i].centroid.x/object[i].area;
object[i].centroid.y=object[i].centroid.y/object[i].area;
}
component_view=DestroyCacheView(component_view);
image_view=DestroyCacheView(image_view);
/*
Report statistics on unique objects.
*/
qsort((void *) object,number_objects,sizeof(*object),CCObjectCompare);
(void) fprintf(stdout,
"Objects (id: bounding-box centroid area mean-color):\n");
for (i=0; i < (ssize_t) number_objects; i++)
{
char
mean_color[MagickPathExtent];
if (status == MagickFalse)
break;
if (object[i].area < MagickEpsilon)
continue;
GetColorTuple(&object[i].color,MagickFalse,mean_color);
(void) fprintf(stdout,
" %.20g: %.20gx%.20g%+.20g%+.20g %.1f,%.1f %.20g %s\n",(double)
object[i].id,(double) object[i].bounding_box.width,(double)
object[i].bounding_box.height,(double) object[i].bounding_box.x,
(double) object[i].bounding_box.y,object[i].centroid.x,
object[i].centroid.y,(double) object[i].area,mean_color);
}
object=(CCObject *) RelinquishMagickMemory(object);
return(status);
}
示例15: assert
//.........这里部分代码省略.........
number_images=GetImageListLength(images);
master_list=ImageListToArray(images,exception);
image_list=master_list;
image=image_list[0];
if (master_list == (Image **) NULL)
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
thumbnail=NewImageList();
for (i=0; i < (long) number_images; i++)
{
image=CloneImage(image_list[i],0,0,MagickTrue,exception);
if (image == (Image *) NULL)
break;
(void) ParseAbsoluteGeometry("0x0+0+0",&image->page);
progress_monitor=SetImageProgressMonitor(image,(MagickProgressMonitor) NULL,
image->client_data);
flags=ParseRegionGeometry(image,montage_info->geometry,&geometry,exception);
thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
if (thumbnail == (Image *) NULL)
break;
image_list[i]=thumbnail;
(void) SetImageProgressMonitor(image,progress_monitor,image->client_data);
proceed=SetImageProgress(image,TileImageTag,i,number_images);
if (proceed == MagickFalse)
break;
image=DestroyImage(image);
}
if (i < (long) number_images)
{
if (thumbnail == (Image *) NULL)
i--;
for (tile=0; (long) tile <= i; tile++)
if (image_list[tile] != (Image *) NULL)
image_list[tile]=DestroyImage(image_list[tile]);
master_list=(Image **) RelinquishMagickMemory(master_list);
return((Image *) NULL);
}
/*
Sort image list by increasing tile number.
*/
for (i=0; i < (long) number_images; i++)
if (image_list[i]->scene == 0)
break;
if (i == (long) number_images)
qsort((void *) image_list,(size_t) number_images,sizeof(*image_list),
SceneCompare);
/*
Determine tiles per row and column.
*/
tiles_per_column=(unsigned long) sqrt((double) number_images);
tiles_per_row=(unsigned long) ceil((double) number_images/tiles_per_column);
x_offset=0;
y_offset=0;
if (montage_info->tile != (char *) NULL)
GetMontageGeometry(montage_info->tile,number_images,&x_offset,&y_offset,
&tiles_per_column,&tiles_per_row);
/*
Determine tile sizes.
*/
concatenate=MagickFalse;
SetGeometry(image_list[0],&extract_info);
extract_info.x=(long) montage_info->border_width;
extract_info.y=(long) montage_info->border_width;
if (montage_info->geometry != (char *) NULL)
{
/*
Initialize tile geometry.