blob: 64c39cf2a97103c636faa7ec9d102768211b656e [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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*/
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"
55
56/*
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58% %
59% %
60% %
61% G e t I m a g e T o t a l I n k D e n s i t y %
62% %
63% %
64% %
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66%
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.
70%
71% The format of the GetImageTotalInkDensity method is:
72%
73% double GetImageTotalInkDensity(const Image *image)
74%
75% A description of each parameter follows:
76%
77% o image: the image.
78%
79*/
80MagickExport double GetImageTotalInkDensity(Image *image)
81{
cristyc4c8d132010-01-07 01:58:38 +000082 CacheView
83 *image_view;
84
cristy3ed852e2009-09-05 21:47:34 +000085 double
86 total_ink_density;
87
88 ExceptionInfo
89 *exception;
90
cristy3ed852e2009-09-05 21:47:34 +000091 MagickBooleanType
92 status;
93
cristy9d314ff2011-03-09 01:30:28 +000094 ssize_t
95 y;
96
cristy3ed852e2009-09-05 21:47:34 +000097 assert(image != (Image *) NULL);
98 if (image->debug != MagickFalse)
99 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
100 assert(image->signature == MagickSignature);
101 if (image->colorspace != CMYKColorspace)
102 {
103 (void) ThrowMagickException(&image->exception,GetMagickModule(),
104 ImageError,"ColorSeparatedImageRequired","`%s'",image->filename);
105 return(0.0);
106 }
107 status=MagickTrue;
108 total_ink_density=0.0;
109 exception=(&image->exception);
110 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000111#if defined(MAGICKCORE_OPENMP_SUPPORT)
112 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +0000113#endif
cristybb503372010-05-27 20:51:26 +0000114 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000115 {
116 double
117 density;
118
119 register const IndexPacket
120 *indexes;
121
122 register const PixelPacket
123 *p;
124
cristybb503372010-05-27 20:51:26 +0000125 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000126 x;
127
128 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
129 if (p == (const PixelPacket *) NULL)
130 {
131 status=MagickFalse;
132 continue;
133 }
134 indexes=GetCacheViewVirtualIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +0000135 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000136 {
137 density=(double) p->red+p->green+p->blue+indexes[x];
138 if (density > total_ink_density)
cristyb5d5f722009-11-04 03:03:49 +0000139#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000140 #pragma omp critical (MagickCore_GetImageTotalInkDensity)
141#endif
142 {
143 if (density > total_ink_density)
144 total_ink_density=density;
145 }
146 p++;
147 }
148 }
149 image_view=DestroyCacheView(image_view);
150 if (status == MagickFalse)
151 total_ink_density=0.0;
152 return(total_ink_density);
153}