/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(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 ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MaxTextExtent], disk_limit[MaxTextExtent], map_limit[MaxTextExtent], memory_limit[MaxTextExtent]; if (file == (const FILE *) NULL) file=stdout; AcquireSemaphoreInfo(&resource_semaphore); (void) FormatMagickSize(MegabytesToBytes(resource_info.area_limit), area_limit); (void) FormatMagickSize(GigabytesToBytes(resource_info.disk_limit), disk_limit); (void) FormatMagickSize(MegabytesToBytes(resource_info.map_limit),map_limit); (void) FormatMagickSize(MegabytesToBytes(resource_info.memory_limit), memory_limit); (void) fprintf(file,"File Area Memory Map Disk\n"); (void) fprintf(file,"------------------------------------------------\n"); (void) fprintf(file,"%4lu %9s %9s %9s %9s\n",resource_info.file_limit, area_limit,memory_limit,map_limit,disk_limit); (void) fflush(file); RelinquishSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(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 ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MaxTextExtent], disk_limit[MaxTextExtent], map_limit[MaxTextExtent], memory_limit[MaxTextExtent], time_limit[MaxTextExtent]; if (file == (const FILE *) NULL) file=stdout; if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,area_limit); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,memory_limit); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,map_limit); (void) CopyMagickString(disk_limit,"unlimited",MaxTextExtent); if (resource_info.disk_limit != MagickResourceInfinity) (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,disk_limit); (void) CopyMagickString(time_limit,"unlimited",MaxTextExtent); if (resource_info.time_limit != MagickResourceInfinity) (void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double) ((MagickOffsetType) resource_info.time_limit)); (void) FormatLocaleFile(file," File Area Memory Map" " Disk Thread Throttle Time\n"); (void) FormatLocaleFile(file, "--------------------------------------------------------" "------------------------\n"); (void) FormatLocaleFile(file,"%6g %10s %10s %10s %10s %8g %8g %10s\n", (double) ((MagickOffsetType) resource_info.file_limit),area_limit, memory_limit,map_limit,disk_limit,(double) ((MagickOffsetType) resource_info.thread_limit),(double) ((MagickOffsetType) resource_info.throttle_limit),time_limit); (void) fflush(file); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(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 ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MagickFormatExtent], disk_limit[MagickFormatExtent], height_limit[MagickFormatExtent], map_limit[MagickFormatExtent], memory_limit[MagickFormatExtent], time_limit[MagickFormatExtent], width_limit[MagickFormatExtent]; magick_unreferenced(exception); if (file == (const FILE *) NULL) file=stdout; if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); (void) FormatMagickSize(resource_info.width_limit,MagickFalse,"P", MagickFormatExtent,width_limit); (void) FormatMagickSize(resource_info.height_limit,MagickFalse,"P", MagickFormatExtent,height_limit); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,"B", MagickFormatExtent,area_limit); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,"B", MagickFormatExtent,memory_limit); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,"B", MagickFormatExtent,map_limit); (void) CopyMagickString(disk_limit,"unlimited",MagickFormatExtent); if (resource_info.disk_limit != MagickResourceInfinity) (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,"B", MagickFormatExtent,disk_limit); (void) CopyMagickString(time_limit,"unlimited",MagickFormatExtent); if (resource_info.time_limit != MagickResourceInfinity) (void) FormatLocaleString(time_limit,MagickFormatExtent,"%.20g",(double) ((MagickOffsetType) resource_info.time_limit)); (void) FormatLocaleFile(file,"Resource limits:\n"); (void) FormatLocaleFile(file," Width: %s\n",width_limit); (void) FormatLocaleFile(file," Height: %s\n",height_limit); (void) FormatLocaleFile(file," Area: %s\n",area_limit); (void) FormatLocaleFile(file," Memory: %s\n",memory_limit); (void) FormatLocaleFile(file," Map: %s\n",map_limit); (void) FormatLocaleFile(file," Disk: %s\n",disk_limit); (void) FormatLocaleFile(file," File: %.20g\n",(double) ((MagickOffsetType) resource_info.file_limit)); (void) FormatLocaleFile(file," Thread: %.20g\n",(double) ((MagickOffsetType) resource_info.thread_limit)); (void) FormatLocaleFile(file," Throttle: %.20g\n",(double) ((MagickOffsetType) resource_info.throttle_limit)); (void) FormatLocaleFile(file," Time: %s\n",time_limit); (void) fflush(file); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickResource() relinquishes resources of the specified type. % % The format of the RelinquishMagickResource() method is: % % void RelinquishMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the size of the resource. % */ MagickExport void RelinquishMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; (void) FormatMagickSize(size,MagickFalse,resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse, resource_limit); break; } case MemoryResource: { resource_info.memory-=size; (void) FormatMagickSize((MagickSizeType) resource_info.memory, MagickTrue,resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue, resource_limit); break; } case MapResource: { resource_info.map-=size; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue, resource_limit); break; } case DiskResource: { resource_info.disk-=size; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue, resource_limit); break; } case FileResource: { resource_info.file-=size; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,resource_limit); break; } case ThreadResource: { (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,resource_limit); break; } case TimeResource: { resource_info.time-=size; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickResource() acquires resources of the specified type. % MagickFalse is returned if the specified resource is exhausted otherwise % MagickTrue. % % The format of the AcquireMagickResource() method is: % % MagickBooleanType AcquireMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the number of bytes needed from for this resource. % */ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; MagickBooleanType status; MagickSizeType limit; status=MagickFalse; (void) FormatMagickSize(size,MagickFalse,resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; limit=resource_info.area_limit; status=(resource_info.area_limit == MagickResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse, resource_limit); break; } case MemoryResource: { resource_info.memory+=size; limit=resource_info.memory_limit; status=(resource_info.memory_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.memory < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue, resource_limit); break; } case MapResource: { resource_info.map+=size; limit=resource_info.map_limit; status=(resource_info.map_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue, resource_limit); break; } case DiskResource: { resource_info.disk+=size; limit=resource_info.disk_limit; status=(resource_info.disk_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.disk < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue, resource_limit); break; } case FileResource: { resource_info.file+=size; limit=resource_info.file_limit; status=(resource_info.file_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.file < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,resource_limit); break; } case ThreadResource: { limit=resource_info.thread_limit; status=(resource_info.thread_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.thread < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,resource_limit); break; } case TimeResource: { resource_info.time+=size; limit=resource_info.time_limit; status=(resource_info.time_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.time < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); return(status); }
MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, const MagickBooleanType verbose,ExceptionInfo *exception) { char color[MaxTextExtent], format[MaxTextExtent], key[MaxTextExtent]; ChannelFeatures *channel_features; ChannelStatistics *channel_statistics; ColorspaceType colorspace; const char *artifact, *name, *property, *registry, *value; const MagickInfo *magick_info; double elapsed_time, user_time; ImageType type; MagickBooleanType ping; register const Quantum *p; register ssize_t i, x; size_t distance, scale; ssize_t y; assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (file == (FILE *) NULL) file=stdout; *format='\0'; elapsed_time=GetElapsedTime(&image->timer); user_time=GetUserTime(&image->timer); GetTimerInfo(&image->timer); if (verbose == MagickFalse) { /* Display summary info about the image. */ if (*image->magick_filename != '\0') if (LocaleCompare(image->magick_filename,image->filename) != 0) (void) FormatLocaleFile(file,"%s=>",image->magick_filename); if ((GetPreviousImageInList(image) == (Image *) NULL) && (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0)) (void) FormatLocaleFile(file,"%s ",image->filename); else (void) FormatLocaleFile(file,"%s[%.20g] ",image->filename,(double) image->scene); (void) FormatLocaleFile(file,"%s ",image->magick); if ((image->magick_columns != 0) || (image->magick_rows != 0)) if ((image->magick_columns != image->columns) || (image->magick_rows != image->rows)) (void) FormatLocaleFile(file,"%.20gx%.20g=>",(double) image->magick_columns,(double) image->magick_rows); (void) FormatLocaleFile(file,"%.20gx%.20g ",(double) image->columns, (double) image->rows); if ((image->page.width != 0) || (image->page.height != 0) || (image->page.x != 0) || (image->page.y != 0)) (void) FormatLocaleFile(file,"%.20gx%.20g%+.20g%+.20g ",(double) image->page.width,(double) image->page.height,(double) image->page.x, (double) image->page.y); (void) FormatLocaleFile(file,"%.20g-bit ",(double) image->depth); if (image->type != UndefinedType) (void) FormatLocaleFile(file,"%s ",CommandOptionToMnemonic( MagickTypeOptions,(ssize_t) image->type)); if (image->storage_class == DirectClass) { (void) FormatLocaleFile(file,"DirectClass "); if (image->total_colors != 0) { (void) FormatMagickSize(image->total_colors,MagickFalse,format); (void) FormatLocaleFile(file,"%s ",format); } } else if (image->total_colors <= image->colors) (void) FormatLocaleFile(file,"PseudoClass %.20gc ",(double) image->colors); else (void) FormatLocaleFile(file,"PseudoClass %.20g=>%.20gc ",(double) image->total_colors,(double) image->colors); if (image->error.mean_error_per_pixel != 0.0) (void) FormatLocaleFile(file,"%.20g/%f/%fdb ",(double) (image->error.mean_error_per_pixel+0.5), image->error.normalized_mean_error, image->error.normalized_maximum_error); if (GetBlobSize(image) != 0) { (void) FormatMagickSize(GetBlobSize(image),MagickFalse,format); (void) FormatLocaleFile(file,"%s ",format); } (void) FormatLocaleFile(file,"%0.3fu %lu:%02lu.%03lu",user_time, (unsigned long) (elapsed_time/60.0),(unsigned long) floor(fmod( elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time- floor(elapsed_time)))); (void) FormatLocaleFile(file,"\n"); (void) fflush(file); return(ferror(file) != 0 ? MagickFalse : MagickTrue); } /* Display verbose info about the image. */ p=GetVirtualPixels(image,0,0,1,1,exception); ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse; type=GetImageType(image,exception); (void) SignatureImage(image,exception); (void) FormatLocaleFile(file,"Image: %s\n",image->filename); if (*image->magick_filename != '\0') if (LocaleCompare(image->magick_filename,image->filename) != 0) { char filename[MaxTextExtent]; GetPathComponent(image->magick_filename,TailPath,filename); (void) FormatLocaleFile(file," Base filename: %s\n",filename); } magick_info=GetMagickInfo(image->magick,exception); if ((magick_info == (const MagickInfo *) NULL) || (*GetMagickDescription(magick_info) == '\0')) (void) FormatLocaleFile(file," Format: %s\n",image->magick); else (void) FormatLocaleFile(file," Format: %s (%s)\n",image->magick, GetMagickDescription(magick_info)); (void) FormatLocaleFile(file," Class: %s\n",CommandOptionToMnemonic( MagickClassOptions,(ssize_t) image->storage_class)); (void) FormatLocaleFile(file," Geometry: %.20gx%.20g%+.20g%+.20g\n",(double) image->columns,(double) image->rows,(double) image->tile_offset.x,(double) image->tile_offset.y); if ((image->magick_columns != 0) || (image->magick_rows != 0)) if ((image->magick_columns != image->columns) || (image->magick_rows != image->rows)) (void) FormatLocaleFile(file," Base geometry: %.20gx%.20g\n",(double) image->magick_columns,(double) image->magick_rows); if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0)) { (void) FormatLocaleFile(file," Resolution: %gx%g\n",image->resolution.x, image->resolution.y); (void) FormatLocaleFile(file," Print size: %gx%g\n",(double) image->columns/image->resolution.x,(double) image->rows/ image->resolution.y); } (void) FormatLocaleFile(file," Units: %s\n",CommandOptionToMnemonic( MagickResolutionOptions,(ssize_t) image->units)); (void) FormatLocaleFile(file," Type: %s\n",CommandOptionToMnemonic( MagickTypeOptions,(ssize_t) type)); if (image->type != UndefinedType) (void) FormatLocaleFile(file," Base type: %s\n",CommandOptionToMnemonic( MagickTypeOptions,(ssize_t) image->type)); (void) FormatLocaleFile(file," Endianess: %s\n",CommandOptionToMnemonic( MagickEndianOptions,(ssize_t) image->endian)); /* Detail channel depth and extrema. */ (void) FormatLocaleFile(file," Colorspace: %s\n",CommandOptionToMnemonic( MagickColorspaceOptions,(ssize_t) image->colorspace)); channel_statistics=(ChannelStatistics *) NULL; channel_features=(ChannelFeatures *) NULL; colorspace=image->colorspace; scale=1; if (ping == MagickFalse) { size_t depth; channel_statistics=GetImageStatistics(image,exception); artifact=GetImageArtifact(image,"identify:features"); if (artifact != (const char *) NULL) { distance=StringToUnsignedLong(artifact); channel_features=GetImageFeatures(image,distance,exception); } depth=GetImageDepth(image,exception); if (image->depth == depth) (void) FormatLocaleFile(file," Depth: %.20g-bit\n",(double) image->depth); else (void) FormatLocaleFile(file," Depth: %.20g/%.20g-bit\n",(double) image->depth,(double) depth); (void) FormatLocaleFile(file," Channel depth:\n"); if (IsImageGray(image,exception) != MagickFalse) colorspace=GRAYColorspace; switch (colorspace) { case RGBColorspace: default: { (void) FormatLocaleFile(file," red: %.20g-bit\n",(double) channel_statistics[RedPixelChannel].depth); (void) FormatLocaleFile(file," green: %.20g-bit\n",(double) channel_statistics[GreenPixelChannel].depth); (void) FormatLocaleFile(file," blue: %.20g-bit\n",(double) channel_statistics[BluePixelChannel].depth); break; } case CMYKColorspace: { (void) FormatLocaleFile(file," cyan: %.20g-bit\n",(double) channel_statistics[CyanPixelChannel].depth); (void) FormatLocaleFile(file," magenta: %.20g-bit\n",(double) channel_statistics[MagentaPixelChannel].depth); (void) FormatLocaleFile(file," yellow: %.20g-bit\n",(double) channel_statistics[YellowPixelChannel].depth); (void) FormatLocaleFile(file," black: %.20g-bit\n",(double) channel_statistics[BlackPixelChannel].depth); break; } case GRAYColorspace: { (void) FormatLocaleFile(file," gray: %.20g-bit\n",(double) channel_statistics[GrayPixelChannel].depth); break; } } if (image->matte != MagickFalse) (void) FormatLocaleFile(file," alpha: %.20g-bit\n",(double) channel_statistics[AlphaPixelChannel].depth); scale=1; if (image->depth <= MAGICKCORE_QUANTUM_DEPTH) scale=QuantumRange/((size_t) QuantumRange >> ((size_t) MAGICKCORE_QUANTUM_DEPTH-image->depth)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickResource() relinquishes resources of the specified type. % % The format of the RelinquishMagickResource() method is: % % void RelinquishMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the size of the resource. % */ MagickExport void RelinquishMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; (void) FormatMagickSize(size,resource_request); AcquireSemaphoreInfo(&resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.area, resource_current); (void) FormatMagickSize(resource_info.area_limit,resource_limit); break; } case MemoryResource: { resource_info.memory-=size; (void) FormatMagickSize((MagickSizeType) resource_info.memory, resource_current); (void) FormatMagickSize(resource_info.memory_limit,resource_limit); break; } case MapResource: { resource_info.map-=size; (void) FormatMagickSize((MagickSizeType) resource_info.map, resource_current); (void) FormatMagickSize(resource_info.map_limit,resource_limit); break; } case DiskResource: { resource_info.disk-=size; (void) FormatMagickSize((MagickSizeType) resource_info.disk, resource_current); (void) FormatMagickSize(resource_info.disk_limit,resource_limit); break; } case FileResource: { resource_info.file-=size; (void) FormatMagickSize((MagickSizeType) resource_info.file, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, resource_limit); break; } default: break; } RelinquishSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", MagickOptionToMnemonic(MagickResourceOptions,(long) type),resource_request, resource_current,resource_limit); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickResource() acquires resources of the specified type. % MagickFalse is returned if the specified resource is exhausted otherwise % MagickTrue. % % The format of the AcquireMagickResource() method is: % % MagickBooleanType AcquireMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: The type of resource. % % o size: The number of bytes needed from for this resource. % */ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; MagickBooleanType status; MagickSizeType limit; status=MagickFalse; (void) FormatMagickSize(size,resource_request); AcquireSemaphoreInfo(&resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; limit=MegabytesToBytes(resource_info.area_limit); status=(resource_info.area_limit == ResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.area, resource_current); (void) FormatMagickSize(MegabytesToBytes(resource_info.area_limit), resource_limit); break; } case MemoryResource: { resource_info.memory+=size; limit=MegabytesToBytes(resource_info.memory_limit); status=(resource_info.memory_limit == ResourceInfinity) || ((MagickSizeType) resource_info.memory < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.memory, resource_current); (void) FormatMagickSize(MegabytesToBytes(resource_info.memory_limit), resource_limit); break; } case MapResource: { resource_info.map+=size; limit=MegabytesToBytes(resource_info.map_limit); status=(resource_info.map_limit == ResourceInfinity) || ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.map, resource_current); (void) FormatMagickSize(MegabytesToBytes(resource_info.map_limit), resource_limit); break; } case DiskResource: { resource_info.disk+=size; limit=GigabytesToBytes(resource_info.disk_limit); status=(resource_info.disk_limit == ResourceInfinity) || ((MagickSizeType) resource_info.disk < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.disk, resource_current); (void) FormatMagickSize(GigabytesToBytes(resource_info.disk_limit), resource_limit); break; } case FileResource: { resource_info.file+=size; limit=resource_info.file_limit; status=(resource_info.file_limit == ResourceInfinity) || ((MagickSizeType) resource_info.file < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.file, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, resource_limit); break; } default: break; } RelinquishSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", MagickOptionToMnemonic(MagickResourceOptions,(long) type),resource_request, resource_current,resource_limit); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I d e n t i f y I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IdentifyImage() identifies an image by printing its attributes to the file. % Attributes include the image width, height, size, and others. % % The format of the IdentifyImage method is: % % MagickBooleanType IdentifyImage(Image *image,FILE *file, % const MagickBooleanType verbose) % % A description of each parameter follows: % % o image: The image. % % o file: The file, typically stdout. % % o verbose: A value other than zero prints more detailed information % about the image. % */ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, const MagickBooleanType verbose) { #define IdentifyFormat " %s:\n Min: " QuantumFormat \ " (%g)\n Max: " QuantumFormat " (%g)\n" \ " Mean: %g (%g)\n Standard deviation: %g (%g)\n" char color[MaxTextExtent], format[MaxTextExtent], key[MaxTextExtent]; ColorspaceType colorspace; const char *property, *value; const MagickInfo *magick_info; const PixelPacket *pixels; double elapsed_time, user_time; ExceptionInfo *exception; Image *p; ImageType type; long y; MagickBooleanType ping; register long i, x; unsigned long scale; assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (file == (FILE *) NULL) file=stdout; *format='\0'; elapsed_time=GetElapsedTime(&image->timer); user_time=GetUserTime(&image->timer); GetTimerInfo(&image->timer); if (verbose == MagickFalse) { /* Display summary info about the image. */ if (*image->magick_filename != '\0') if (LocaleCompare(image->magick_filename,image->filename) != 0) (void) fprintf(file,"%s=>",image->magick_filename); if ((GetPreviousImageInList(image) == (Image *) NULL) && (GetNextImageInList(image) == (Image *) NULL) && (image->scene == 0)) (void) fprintf(file,"%s ",image->filename); else (void) fprintf(file,"%s[%lu] ",image->filename,image->scene); (void) fprintf(file,"%s ",image->magick); if ((image->magick_columns != 0) || (image->magick_rows != 0)) if ((image->magick_columns != image->columns) || (image->magick_rows != image->rows)) (void) fprintf(file,"%lux%lu=>",image->magick_columns, image->magick_rows); (void) fprintf(file,"%lux%lu ",image->columns,image->rows); if ((image->page.width != 0) || (image->page.height != 0) || (image->page.x != 0) || (image->page.y != 0)) (void) fprintf(file,"%lux%lu%+ld%+ld ",image->page.width, image->page.height,image->page.x,image->page.y); if (image->storage_class == DirectClass) { (void) fprintf(file,"DirectClass "); if (image->total_colors != 0) { (void) FormatMagickSize(image->total_colors,format); (void) fprintf(file,"%s ",format); } } else if (image->total_colors <= image->colors) (void) fprintf(file,"PseudoClass %luc ",image->colors); else (void) fprintf(file,"PseudoClass %lu=>%luc ",image->total_colors, image->colors); (void) fprintf(file,"%lu-bit ",image->depth); if (image->error.mean_error_per_pixel != 0.0) (void) fprintf(file,"%ld/%f/%fdb ", (long) (image->error.mean_error_per_pixel+0.5), image->error.normalized_mean_error, image->error.normalized_maximum_error); if (GetBlobSize(image) != 0) { (void) FormatMagickSize(GetBlobSize(image),format); (void) fprintf(file,"%s ",format); } if (elapsed_time > 0.06) (void) fprintf(file,"%0.3fu %ld:%02ld",user_time, (long) (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time,60.0))); (void) fprintf(file,"\n"); (void) fflush(file); return(ferror(file) != 0 ? MagickFalse : MagickTrue); } /* Display verbose info about the image. */ exception=AcquireExceptionInfo(); pixels=AcquireImagePixels(image,0,0,1,1,exception); exception=DestroyExceptionInfo(exception); ping=pixels == (const PixelPacket *) NULL ? MagickTrue : MagickFalse; type=GetImageType(image,&image->exception); (void) SignatureImage(image); (void) fprintf(file,"Image: %s\n",image->filename); if (*image->magick_filename != '\0') if (LocaleCompare(image->magick_filename,image->filename) != 0) { char filename[MaxTextExtent]; GetPathComponent(image->magick_filename,TailPath,filename); (void) fprintf(file," Base filename: %s\n",filename); } magick_info=GetMagickInfo(image->magick,&image->exception); if ((magick_info == (const MagickInfo *) NULL) || (*GetMagickDescription(magick_info) == '\0')) (void) fprintf(file," Format: %s\n",image->magick); else (void) fprintf(file," Format: %s (%s)\n",image->magick, GetMagickDescription(magick_info)); (void) fprintf(file," Class: %s\n", MagickOptionToMnemonic(MagickClassOptions,(long) image->storage_class)); (void) fprintf(file," Geometry: %lux%lu%+ld%+ld\n",image->columns, image->rows,image->tile_offset.x,image->tile_offset.y); if ((image->magick_columns != 0) || (image->magick_rows != 0)) if ((image->magick_columns != image->columns) || (image->magick_rows != image->rows)) (void) fprintf(file," Base geometry: %lux%lu\n",image->magick_columns, image->magick_rows); (void) fprintf(file," Type: %s\n",MagickOptionToMnemonic(MagickTypeOptions, (long) type)); (void) fprintf(file," Endianess: %s\n",MagickOptionToMnemonic( MagickEndianOptions,(long) image->endian)); /* Detail channel depth and extrema. */ colorspace=image->colorspace; if (IsGrayImage(image,&image->exception) != MagickFalse) colorspace=GRAYColorspace; (void) fprintf(file," Colorspace: %s\n", MagickOptionToMnemonic(MagickColorspaceOptions,(long) colorspace)); if (ping == MagickFalse) { ChannelStatistics *channel_statistics; (void) fprintf(file," Depth: %lu-bit\n",GetImageDepth(image, &image->exception)); channel_statistics=GetImageChannelStatistics(image,&image->exception); (void) fprintf(file," Channel depth:\n"); switch (colorspace) { case RGBColorspace: default: { (void) fprintf(file," Red: %lu-bit\n", channel_statistics[RedChannel].depth); (void) fprintf(file," Green: %lu-bit\n", channel_statistics[GreenChannel].depth); (void) fprintf(file," Blue: %lu-bit\n", channel_statistics[BlueChannel].depth); if (image->matte != MagickFalse) (void) fprintf(file," Alpha: %lu-bit\n", channel_statistics[OpacityChannel].depth); break; } case CMYKColorspace: { (void) fprintf(file," Cyan: %lu-bit\n", channel_statistics[CyanChannel].depth); (void) fprintf(file," Magenta: %lu-bit\n", channel_statistics[MagentaChannel].depth); (void) fprintf(file," Yellow: %lu-bit\n", channel_statistics[YellowChannel].depth); (void) fprintf(file," Black: %lu-bit\n", channel_statistics[BlackChannel].depth); if (image->matte != MagickFalse) (void) fprintf(file," Alpha: %lu-bit\n", channel_statistics[OpacityChannel].depth); break; } case GRAYColorspace: { (void) fprintf(file," Gray: %lu-bit\n", channel_statistics[GrayChannel].depth); if (image->matte != MagickFalse) (void) fprintf(file," Alpha: %lu-bit\n", channel_statistics[OpacityChannel].depth); break; } } scale=QuantumRange/((unsigned long) QuantumRange >> ((unsigned long) MAGICKCORE_QUANTUM_DEPTH-channel_statistics[AllChannels].depth)); (void) fprintf(file," Channel statistics:\n"); switch (colorspace) { case RGBColorspace: default: { (void) fprintf(file,IdentifyFormat,"Red",(Quantum) (channel_statistics[RedChannel].minima/scale),(double) channel_statistics[RedChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[RedChannel].maxima/scale),(double) channel_statistics[RedChannel].maxima/(double) QuantumRange, channel_statistics[RedChannel].mean/(double) scale, channel_statistics[RedChannel].mean/(double) QuantumRange, channel_statistics[RedChannel].standard_deviation/(double) scale, channel_statistics[RedChannel].standard_deviation/(double) QuantumRange); (void) fprintf(file,IdentifyFormat,"Green",(Quantum) (channel_statistics[GreenChannel].minima/scale),(double) channel_statistics[GreenChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[GreenChannel].maxima/scale),(double) channel_statistics[GreenChannel].maxima/(double) QuantumRange, channel_statistics[GreenChannel].mean/(double) scale, channel_statistics[GreenChannel].mean/(double) QuantumRange, channel_statistics[GreenChannel].standard_deviation/(double) scale, channel_statistics[GreenChannel].standard_deviation/(double) QuantumRange); (void) fprintf(file,IdentifyFormat,"Blue",(Quantum) (channel_statistics[BlueChannel].minima/scale),(double) channel_statistics[BlueChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[BlueChannel].maxima/scale),(double) channel_statistics[BlueChannel].maxima/(double) QuantumRange, channel_statistics[BlueChannel].mean/(double) scale, channel_statistics[BlueChannel].mean/(double) QuantumRange, channel_statistics[BlueChannel].standard_deviation/(double) scale, channel_statistics[BlueChannel].standard_deviation/(double) QuantumRange); break; } case CMYKColorspace: { (void) fprintf(file,IdentifyFormat,"Cyan",(Quantum) (channel_statistics[CyanChannel].minima/scale),(double) channel_statistics[CyanChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[CyanChannel].maxima/scale),(double) channel_statistics[CyanChannel].maxima/(double) QuantumRange, channel_statistics[CyanChannel].mean/(double) scale, channel_statistics[CyanChannel].mean/(double) QuantumRange, channel_statistics[CyanChannel].standard_deviation/(double) scale, channel_statistics[CyanChannel].standard_deviation/(double) QuantumRange); (void) fprintf(file,IdentifyFormat,"Magenta",(Quantum) (channel_statistics[MagentaChannel].minima/scale),(double) channel_statistics[MagentaChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[MagentaChannel].maxima/scale),(double) channel_statistics[MagentaChannel].maxima/(double) QuantumRange, channel_statistics[MagentaChannel].mean/(double) scale, channel_statistics[MagentaChannel].mean/(double) QuantumRange, channel_statistics[MagentaChannel].standard_deviation/(double) scale,channel_statistics[MagentaChannel].standard_deviation/(double) QuantumRange); (void) fprintf(file,IdentifyFormat,"Yellow",(Quantum) (channel_statistics[YellowChannel].minima/scale),(double) channel_statistics[YellowChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[YellowChannel].maxima/scale),(double) channel_statistics[YellowChannel].maxima/(double) QuantumRange, channel_statistics[YellowChannel].mean/(double) scale, channel_statistics[YellowChannel].mean/(double) QuantumRange, channel_statistics[YellowChannel].standard_deviation/(double) scale, channel_statistics[YellowChannel].standard_deviation/(double) QuantumRange); (void) fprintf(file,IdentifyFormat,"Black",(Quantum) (channel_statistics[BlackChannel].minima/scale),(double) channel_statistics[BlackChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[BlackChannel].maxima/scale),(double) channel_statistics[BlackChannel].maxima/(double) QuantumRange, channel_statistics[BlackChannel].mean/(double) scale, channel_statistics[BlackChannel].mean/(double) QuantumRange, channel_statistics[BlackChannel].standard_deviation/(double) scale, channel_statistics[BlackChannel].standard_deviation/(double) QuantumRange); break; } case GRAYColorspace: { (void) fprintf(file,IdentifyFormat,"Gray",(Quantum) (channel_statistics[GrayChannel].minima/scale),(double) channel_statistics[GrayChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[GrayChannel].maxima/scale),(double) channel_statistics[GrayChannel].maxima/(double) QuantumRange, channel_statistics[GrayChannel].mean/(double) scale, channel_statistics[GrayChannel].mean/(double) QuantumRange, channel_statistics[GrayChannel].standard_deviation/(double) scale, channel_statistics[GrayChannel].standard_deviation/(double) QuantumRange); break; } } if (image->matte != MagickFalse) (void) fprintf(file,IdentifyFormat,"Opacity",(Quantum) (channel_statistics[OpacityChannel].minima/scale),(double) channel_statistics[OpacityChannel].minima/(double) QuantumRange, (Quantum) (channel_statistics[OpacityChannel].maxima/scale),(double) channel_statistics[OpacityChannel].maxima/(double) QuantumRange, channel_statistics[OpacityChannel].mean/(double) scale, channel_statistics[OpacityChannel].mean/(double) QuantumRange, channel_statistics[OpacityChannel].standard_deviation/(double) scale, channel_statistics[OpacityChannel].standard_deviation/(double) QuantumRange); channel_statistics=(ChannelStatistics *) RelinquishMagickMemory( channel_statistics); if (colorspace == CMYKColorspace) (void) fprintf(file," Total ink density: %.0f%%\n",100.0* GetImageTotalInkDensity(image)/(double) QuantumRange); x=0; p=NewImageList(); if (image->matte != MagickFalse) { register const IndexPacket *indexes; register const PixelPacket *p; p=(PixelPacket *) NULL; indexes=(IndexPacket *) NULL; for (y=0; y < (long) image->rows; y++) { p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception); if (p == (const PixelPacket *) NULL) break; indexes=AcquireIndexes(image); for (x=0; x < (long) image->columns; x++) { if (p->opacity == (Quantum) TransparentOpacity) break; p++; } if (x < (long) image->columns) break; } if ((x < (long) image->columns) || (y < (long) image->rows)) { char tuple[MaxTextExtent]; MagickPixelPacket pixel; GetMagickPixelPacket(image,&pixel); SetMagickPixelPacket(image,p,indexes+x,&pixel); (void) QueryMagickColorname(image,&pixel,SVGCompliance, MagickFalse,tuple,&image->exception); (void) fprintf(file," Alpha: %s ",tuple); (void) QueryMagickColorname(image,&pixel,SVGCompliance,MagickTrue, tuple,&image->exception); (void) fprintf(file," %s\n",tuple); } } if ((ping == MagickFalse) && (IsHistogramImage(image,&image->exception) != MagickFalse)) { (void) fprintf(file," Histogram:\n"); (void) GetNumberColors(image,file,&image->exception); } }