]> granicus.if.org Git - imagemagick/blob - magick/prepress.c
(no commit message)
[imagemagick] / magick / prepress.c
1 /*
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 %                                                                             %
20 %  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
21 %  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 \f
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 \f
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 */
80 MagickExport double GetImageTotalInkDensity(Image *image)
81 {
82   CacheView
83     *image_view;
84
85   double
86     total_ink_density;
87
88   ExceptionInfo
89     *exception;
90
91   ssize_t
92     y;
93
94   MagickBooleanType
95     status;
96
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)
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);
111 #if defined(MAGICKCORE_OPENMP_SUPPORT)
112   #pragma omp parallel for schedule(dynamic,4) shared(status)
113 #endif
114   for (y=0; y < (ssize_t) image->rows; y++)
115   {
116     double
117       density;
118
119     register const IndexPacket
120       *indexes;
121
122     register const PixelPacket
123       *p;
124
125     register ssize_t
126       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);
135     for (x=0; x < (ssize_t) image->columns; x++)
136     {
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)
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 }