MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
prepress.c
Go to the documentation of this file.
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 % Cristy %
17 % October 2001 %
18 % %
19 % %
20 % Copyright 1999-2018 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 % https://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 "MagickCore/studio.h"
43 #include "MagickCore/cache-view.h"
44 #include "MagickCore/exception.h"
46 #include "MagickCore/image.h"
47 #include "MagickCore/linked-list.h"
48 #include "MagickCore/list.h"
49 #include "MagickCore/memory_.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"
58 
59 /*
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 % %
62 % %
63 % %
64 % G e t I m a g e T o t a l I n k D e n s i t y %
65 % %
66 % %
67 % %
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %
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.
73 %
74 % The format of the GetImageTotalInkDensity method is:
75 %
76 % double GetImageTotalInkDensity(const Image *image,
77 % ExceptionInfo *exception)
78 %
79 % A description of each parameter follows:
80 %
81 % o image: the image.
82 %
83 % o exception: return any errors or warnings in this structure.
84 %
85 */
87  ExceptionInfo *exception)
88 {
89  CacheView
90  *image_view;
91 
92  double
93  total_ink_density;
94 
96  status;
97 
98  ssize_t
99  y;
100 
101  assert(image != (Image *) NULL);
102  if (image->debug != MagickFalse)
103  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
104  assert(image->signature == MagickCoreSignature);
105  if (image->colorspace != CMYKColorspace)
106  {
108  "ColorSeparatedImageRequired","`%s'",image->filename);
109  return(0.0);
110  }
111  status=MagickTrue;
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_number_threads(image,image,image->rows,1)
117 #endif
118  for (y=0; y < (ssize_t) image->rows; y++)
119  {
120  double
121  density;
122 
123  register const Quantum
124  *p;
125 
126  register ssize_t
127  x;
128 
129  p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
130  if (p == (const Quantum *) NULL)
131  {
132  status=MagickFalse;
133  continue;
134  }
135  for (x=0; x < (ssize_t) image->columns; x++)
136  {
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)
142 #endif
143  {
144  if (density > total_ink_density)
145  total_ink_density=density;
146  }
147  p+=GetPixelChannels(image);
148  }
149  }
150  image_view=DestroyCacheView(image_view);
151  if (status == MagickFalse)
152  total_ink_density=0.0;
153  return(total_ink_density);
154 }
size_t rows
Definition: image.h:172
MagickExport CacheView * DestroyCacheView(CacheView *cache_view)
Definition: cache-view.c:252
MagickExport double GetImageTotalInkDensity(Image *image, ExceptionInfo *exception)
Definition: prepress.c:86
static Quantum GetPixelRed(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport const Quantum * GetCacheViewVirtualPixels(const CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:651
Definition: log.h:52
Definition: image.h:151
#define MagickCoreSignature
MagickBooleanType
Definition: magick-type.h:156
static Quantum GetPixelGreen(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static Quantum GetPixelBlack(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1058
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
static size_t GetPixelChannels(const Image *magick_restrict image)
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
MagickExport CacheView * AcquireVirtualCacheView(const Image *image, ExceptionInfo *exception)
Definition: cache-view.c:149
unsigned short Quantum
Definition: magick-type.h:82
#define MagickExport
static Quantum GetPixelBlue(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
ColorspaceType colorspace
Definition: image.h:157
MagickBooleanType debug
Definition: image.h:334