2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % PPPP RRRR EEEEE PPPP RRRR EEEEE SSSSS SSSSS %
7 % P P R R E P P R R E SS SS %
8 % PPPP RRRR EEE PPPP RRRR EEE SSS SSS %
9 % P R R E P R R E SS SS %
10 % P R R EEEEE P R R EEEEE SSSSS SSSSS %
13 % MagickCore Prepress Methods %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/cache-view.h"
44 #include "magick/exception.h"
45 #include "magick/exception-private.h"
46 #include "magick/hashmap.h"
47 #include "magick/image.h"
48 #include "magick/list.h"
49 #include "magick/memory_.h"
50 #include "magick/prepress.h"
51 #include "magick/registry.h"
52 #include "magick/semaphore.h"
53 #include "magick/splay-tree.h"
54 #include "magick/string_.h"
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 % G e t I m a g e T o t a l I n k D e n s i t y %
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % GetImageTotalInkDensity() returns the total ink density for a CMYK image.
68 % Total Ink Density (TID) is determined by adding the CMYK values in the
69 % darkest shadow area in an image.
71 % The format of the GetImageTotalInkDensity method is:
73 % double GetImageTotalInkDensity(const Image *image)
75 % A description of each parameter follows:
80 MagickExport double GetImageTotalInkDensity(Image *image)
97 assert(image != (Image *) NULL);
98 if (image->debug != MagickFalse)
99 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
100 assert(image->signature == MagickSignature);
101 if (image->colorspace != CMYKColorspace)
103 (void) ThrowMagickException(&image->exception,GetMagickModule(),
104 ImageError,"ColorSeparatedImageRequired","`%s'",image->filename);
108 total_ink_density=0.0;
109 exception=(&image->exception);
110 image_view=AcquireCacheView(image);
111 #if defined(MAGICKCORE_OPENMP_SUPPORT)
112 #pragma omp parallel for schedule(dynamic,4) shared(status)
114 for (y=0; y < (ssize_t) image->rows; y++)
119 register const IndexPacket
122 register const PixelPacket
128 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
129 if (p == (const PixelPacket *) NULL)
134 indexes=GetCacheViewVirtualIndexQueue(image_view);
135 for (x=0; x < (ssize_t) image->columns; x++)
137 density=(double) p->red+p->green+p->blue+indexes[x];
138 if (density > total_ink_density)
139 #if defined(MAGICKCORE_OPENMP_SUPPORT)
140 #pragma omp critical (MagickCore_GetImageTotalInkDensity)
143 if (density > total_ink_density)
144 total_ink_density=density;
149 image_view=DestroyCacheView(image_view);
150 if (status == MagickFalse)
151 total_ink_density=0.0;
152 return(total_ink_density);