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-2014 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 "MagickCore/studio.h"
43 #include "MagickCore/cache-view.h"
44 #include "MagickCore/exception.h"
45 #include "MagickCore/exception-private.h"
46 #include "MagickCore/hashmap.h"
47 #include "MagickCore/image.h"
48 #include "MagickCore/list.h"
49 #include "MagickCore/memory_.h"
50 #include "MagickCore/pixel-accessor.h"
51 #include "MagickCore/prepress.h"
52 #include "MagickCore/resource_.h"
53 #include "MagickCore/registry.h"
54 #include "MagickCore/semaphore.h"
55 #include "MagickCore/splay-tree.h"
56 #include "MagickCore/string_.h"
57 #include "MagickCore/thread-private.h"
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 % G e t I m a g e T o t a l I n k D e n s i t y %
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % GetImageTotalInkDensity() returns the total ink density for a CMYK image.
71 % Total Ink Density (TID) is determined by adding the CMYK values in the
72 % darkest shadow area in an image.
74 % The format of the GetImageTotalInkDensity method is:
76 % double GetImageTotalInkDensity(const Image *image,
77 % ExceptionInfo *exception)
79 % A description of each parameter follows:
83 % o exception: return any errors or warnings in this structure.
86 MagickExport double GetImageTotalInkDensity(Image *image,
87 ExceptionInfo *exception)
101 assert(image != (Image *) NULL);
102 if (image->debug != MagickFalse)
103 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
104 assert(image->signature == MagickSignature);
105 if (image->colorspace != CMYKColorspace)
107 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
108 "ColorSeparatedImageRequired","`%s'",image->filename);
112 total_ink_density=0.0;
113 image_view=AcquireVirtualCacheView(image,exception);
114 #if defined(MAGICKCORE_OPENMP_SUPPORT)
115 #pragma omp parallel for schedule(static,4) shared(status) \
116 magick_threads(image,image,image->rows,1)
118 for (y=0; y < (ssize_t) image->rows; y++)
123 register const Quantum
129 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
130 if (p == (const Quantum *) NULL)
135 for (x=0; x < (ssize_t) image->columns; x++)
137 density=(double) GetPixelRed(image,p)+GetPixelGreen(image,p)+
138 GetPixelBlue(image,p)+GetPixelBlack(image,p);
139 if (density > total_ink_density)
140 #if defined(MAGICKCORE_OPENMP_SUPPORT)
141 #pragma omp critical (MagickCore_GetImageTotalInkDensity)
144 if (density > total_ink_density)
145 total_ink_density=density;
147 p+=GetPixelChannels(image);
150 image_view=DestroyCacheView(image_view);
151 if (status == MagickFalse)
152 total_ink_density=0.0;
153 return(total_ink_density);