blob: fe79d4e1eae7c493ca6899ec93eb1dd7d023b3c6 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
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 %
11% %
12% %
13% MagickCore Prepress Methods %
14% %
15% Software Design %
16% John Cristy %
17% October 2001 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
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. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#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/registry.h"
53#include "MagickCore/semaphore.h"
54#include "MagickCore/splay-tree.h"
55#include "MagickCore/string_.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59% %
60% %
61% %
62% G e t I m a g e T o t a l I n k D e n s i t y %
63% %
64% %
65% %
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67%
68% GetImageTotalInkDensity() returns the total ink density for a CMYK image.
69% Total Ink Density (TID) is determined by adding the CMYK values in the
70% darkest shadow area in an image.
71%
72% The format of the GetImageTotalInkDensity method is:
73%
cristy7c3af952011-10-20 16:04:16 +000074% double GetImageTotalInkDensity(const Image *image,
75% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000076%
77% A description of each parameter follows:
78%
79% o image: the image.
80%
cristy7c3af952011-10-20 16:04:16 +000081% o exception: return any errors or warnings in this structure.
82%
cristy3ed852e2009-09-05 21:47:34 +000083*/
cristy7c3af952011-10-20 16:04:16 +000084MagickExport double GetImageTotalInkDensity(Image *image,
85 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000086{
cristyc4c8d132010-01-07 01:58:38 +000087 CacheView
88 *image_view;
89
cristy3ed852e2009-09-05 21:47:34 +000090 double
91 total_ink_density;
92
cristy3ed852e2009-09-05 21:47:34 +000093 MagickBooleanType
94 status;
95
cristy9d314ff2011-03-09 01:30:28 +000096 ssize_t
97 y;
98
cristy3ed852e2009-09-05 21:47:34 +000099 assert(image != (Image *) NULL);
100 if (image->debug != MagickFalse)
101 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
102 assert(image->signature == MagickSignature);
103 if (image->colorspace != CMYKColorspace)
104 {
cristyc82a27b2011-10-21 01:07:16 +0000105 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
106 "ColorSeparatedImageRequired","`%s'",image->filename);
cristy3ed852e2009-09-05 21:47:34 +0000107 return(0.0);
108 }
109 status=MagickTrue;
110 total_ink_density=0.0;
cristy3ed852e2009-09-05 21:47:34 +0000111 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000112#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristye6178502011-12-23 17:02:29 +0000113 #pragma omp parallel for schedule(static,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +0000114#endif
cristybb503372010-05-27 20:51:26 +0000115 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000116 {
117 double
118 density;
119
cristy4c08aed2011-07-01 19:47:50 +0000120 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000121 *p;
122
cristybb503372010-05-27 20:51:26 +0000123 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000124 x;
125
126 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000127 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000128 {
129 status=MagickFalse;
130 continue;
131 }
cristybb503372010-05-27 20:51:26 +0000132 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000133 {
cristy4c08aed2011-07-01 19:47:50 +0000134 density=(double) GetPixelRed(image,p)+GetPixelGreen(image,p)+
135 GetPixelBlue(image,p)+GetPixelBlack(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000136 if (density > total_ink_density)
cristyb5d5f722009-11-04 03:03:49 +0000137#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000138 #pragma omp critical (MagickCore_GetImageTotalInkDensity)
139#endif
140 {
141 if (density > total_ink_density)
142 total_ink_density=density;
143 }
cristyed231572011-07-14 02:18:59 +0000144 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000145 }
146 }
147 image_view=DestroyCacheView(image_view);
148 if (status == MagickFalse)
149 total_ink_density=0.0;
150 return(total_ink_density);
151}