cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | /* |
| 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 | */ |
| 80 | MagickExport double GetImageTotalInkDensity(Image *image) |
| 81 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 82 | CacheView |
| 83 | *image_view; |
| 84 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | double |
| 86 | total_ink_density; |
| 87 | |
| 88 | ExceptionInfo |
| 89 | *exception; |
| 90 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | MagickBooleanType |
| 92 | status; |
| 93 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame^] | 94 | ssize_t |
| 95 | y; |
| 96 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 111 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 112 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 114 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 115 | { |
| 116 | double |
| 117 | density; |
| 118 | |
| 119 | register const IndexPacket |
| 120 | *indexes; |
| 121 | |
| 122 | register const PixelPacket |
| 123 | *p; |
| 124 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 125 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 135 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | { |
| 137 | density=(double) p->red+p->green+p->blue+indexes[x]; |
| 138 | if (density > total_ink_density) |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 139 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | } |