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-2016 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 39 /* 41 Include declarations. 42 */ 43 #include "MagickCore/studio.h" 44 #include "MagickCore/cache-view.h" 45 #include "MagickCore/exception.h" 46 #include "MagickCore/exception-private.h" 47 #include "MagickCore/image.h" 48 #include "MagickCore/linked-list.h" 49 #include "MagickCore/list.h" 50 #include "MagickCore/memory_.h" 51 #include "MagickCore/pixel-accessor.h" 52 #include "MagickCore/prepress.h" 53 #include "MagickCore/resource_.h" 54 #include "MagickCore/registry.h" 55 #include "MagickCore/semaphore.h" 56 #include "MagickCore/splay-tree.h" 57 #include "MagickCore/string_.h" 58 #include "MagickCore/thread-private.h" 59 60 /* 62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 63 % % 64 % % 65 % % 66 % G e t I m a g e T o t a l I n k D e n s i t y % 67 % % 68 % % 69 % % 70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71 % 72 % GetImageTotalInkDensity() returns the total ink density for a CMYK image. 73 % Total Ink Density (TID) is determined by adding the CMYK values in the 74 % darkest shadow area in an image. 75 % 76 % The format of the GetImageTotalInkDensity method is: 77 % 78 % double GetImageTotalInkDensity(const Image *image, 79 % ExceptionInfo *exception) 80 % 81 % A description of each parameter follows: 82 % 83 % o image: the image. 84 % 85 % o exception: return any errors or warnings in this structure. 86 % 87 */ 88 MagickExport double GetImageTotalInkDensity(Image *image, 89 ExceptionInfo *exception) 90 { 91 CacheView 92 *image_view; 93 94 double 95 total_ink_density; 96 97 MagickBooleanType 98 status; 99 100 ssize_t 101 y; 102 103 assert(image != (Image *) NULL); 104 if (image->debug != MagickFalse) 105 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); 106 assert(image->signature == MagickCoreSignature); 107 if (image->colorspace != CMYKColorspace) 108 { 109 (void) ThrowMagickException(exception,GetMagickModule(),ImageError, 110 "ColorSeparatedImageRequired","`%s'",image->filename); 111 return(0.0); 112 } 113 status=MagickTrue; 114 total_ink_density=0.0; 115 image_view=AcquireVirtualCacheView(image,exception); 116 #if defined(MAGICKCORE_OPENMP_SUPPORT) 117 #pragma omp parallel for schedule(static,4) shared(status) \ 118 magick_threads(image,image,image->rows,1) 119 #endif 120 for (y=0; y < (ssize_t) image->rows; y++) 121 { 122 double 123 density; 124 125 register const Quantum 126 *p; 127 128 register ssize_t 129 x; 130 131 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); 132 if (p == (const Quantum *) NULL) 133 { 134 status=MagickFalse; 135 continue; 136 } 137 for (x=0; x < (ssize_t) image->columns; x++) 138 { 139 density=(double) GetPixelRed(image,p)+GetPixelGreen(image,p)+ 140 GetPixelBlue(image,p)+GetPixelBlack(image,p); 141 if (density > total_ink_density) 142 #if defined(MAGICKCORE_OPENMP_SUPPORT) 143 #pragma omp critical (MagickCore_GetImageTotalInkDensity) 144 #endif 145 { 146 if (density > total_ink_density) 147 total_ink_density=density; 148 } 149 p+=GetPixelChannels(image); 150 } 151 } 152 image_view=DestroyCacheView(image_view); 153 if (status == MagickFalse) 154 total_ink_density=0.0; 155 return(total_ink_density); 156 } 157