cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 6 | % H H IIIII SSSSS TTTTT OOO GGGG RRRR AAA M M % |
| 7 | % H H I SS T O O G R R A A MM MM % |
| 8 | % HHHHH I SSS T O O G GG RRRR AAAAA M M M % |
| 9 | % H H I SS T O O G G R R A A M M % |
| 10 | % H H IIIII SSSSS T OOO GGG R R A A M M % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 11 | % % |
| 12 | % % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 13 | % Write A Histogram Image. % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
cristy | 76ce6e1 | 2013-04-05 14:33:38 +0000 | [diff] [blame] | 43 | #include "MagickCore/artifact.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/constitute.h" |
| 50 | #include "MagickCore/exception.h" |
| 51 | #include "MagickCore/exception-private.h" |
| 52 | #include "MagickCore/geometry.h" |
| 53 | #include "MagickCore/histogram.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
| 57 | #include "MagickCore/monitor.h" |
| 58 | #include "MagickCore/monitor-private.h" |
| 59 | #include "MagickCore/option.h" |
| 60 | #include "MagickCore/pixel-accessor.h" |
cristy | 76ce6e1 | 2013-04-05 14:33:38 +0000 | [diff] [blame] | 61 | #include "MagickCore/property.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/resource_.h" |
| 64 | #include "MagickCore/static.h" |
| 65 | #include "MagickCore/statistic.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/module.h" |
cristy | e40005d | 2012-03-23 12:18:45 +0000 | [diff] [blame] | 68 | #include "MagickCore/token.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 69 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | Forward declarations. |
| 73 | */ |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 74 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 75 | WriteHISTOGRAMImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 | % % |
| 80 | % % |
| 81 | % % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 82 | % R e g i s t e r H I S T O G R A M I m a g e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | % % |
| 84 | % % |
| 85 | % % |
| 86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 87 | % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 88 | % RegisterHISTOGRAMImage() adds attributes for the Histogram image format |
| 89 | % to the list of supported formats. The attributes include the image format |
| 90 | % tag, a method to read and/or write the format, whether the format |
| 91 | % supports the saving of more than one frame to the same file or blob, |
| 92 | % whether the format supports native in-memory I/O, and a brief |
| 93 | % description of the format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 94 | % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 95 | % The format of the RegisterHISTOGRAMImage method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 97 | % size_t RegisterHISTOGRAMImage(void) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 98 | % |
| 99 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 100 | ModuleExport size_t RegisterHISTOGRAMImage(void) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 101 | { |
| 102 | MagickInfo |
| 103 | *entry; |
| 104 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 105 | entry=AcquireMagickInfo("HISTOGRAM","HISTOGRAM","Histogram of the image"); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 106 | entry->encoder=(EncodeImageHandler *) WriteHISTOGRAMImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 107 | entry->flags^=CoderAdjoinFlag; |
cristy | 009d739 | 2010-07-25 22:08:41 +0000 | [diff] [blame] | 108 | entry->format_type=ImplicitFormatType; |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 109 | (void) RegisterMagickInfo(entry); |
| 110 | return(MagickImageCoderSignature); |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | % % |
| 116 | % % |
| 117 | % % |
| 118 | % U n r e g i s t e r H I S T O G R A M I m a g e % |
| 119 | % % |
| 120 | % % |
| 121 | % % |
| 122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 123 | % |
| 124 | % UnregisterHISTOGRAMImage() removes format registrations made by the |
| 125 | % HISTOGRAM module from the list of supported formats. |
| 126 | % |
| 127 | % The format of the UnregisterHISTOGRAMImage method is: |
| 128 | % |
| 129 | % UnregisterHISTOGRAMImage(void) |
| 130 | % |
| 131 | */ |
| 132 | ModuleExport void UnregisterHISTOGRAMImage(void) |
| 133 | { |
| 134 | (void) UnregisterMagickInfo("HISTOGRAM"); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | % W r i t e H I S T O G R A M I m a g e % |
| 143 | % % |
| 144 | % % |
| 145 | % % |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % |
| 148 | % WriteHISTOGRAMImage() writes an image to a file in Histogram format. |
| 149 | % The image shows a histogram of the color (or gray) values in the image. The |
| 150 | % image consists of three overlaid histograms: a red one for the red channel, |
| 151 | % a green one for the green channel, and a blue one for the blue channel. The |
| 152 | % image comment contains a list of unique pixel values and the number of times |
| 153 | % each occurs in the image. |
| 154 | % |
| 155 | % This method is strongly based on a similar one written by |
| 156 | % muquit@warm.semcor.com which in turn is based on ppmhistmap of netpbm. |
| 157 | % |
| 158 | % The format of the WriteHISTOGRAMImage method is: |
| 159 | % |
| 160 | % MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 161 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 162 | % |
| 163 | % A description of each parameter follows. |
| 164 | % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 165 | % o image_info: the image info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 166 | % |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 167 | % o image: The image. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 168 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 169 | % o exception: return any errors or warnings in this structure. |
| 170 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | */ |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 172 | static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 173 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 174 | { |
cristy | 31ac0f0 | 2011-03-12 02:04:47 +0000 | [diff] [blame] | 175 | #define HistogramDensity "256x200" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 177 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 178 | filename[MagickPathExtent]; |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 179 | |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 180 | const char |
| 181 | *option; |
| 182 | |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 183 | Image |
| 184 | *histogram_image; |
| 185 | |
| 186 | ImageInfo |
| 187 | *write_info; |
| 188 | |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 189 | MagickBooleanType |
| 190 | status; |
| 191 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 192 | PixelInfo |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 193 | *histogram; |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 194 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 195 | double |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 196 | maximum, |
| 197 | scale; |
| 198 | |
| 199 | RectangleInfo |
| 200 | geometry; |
| 201 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 202 | register const Quantum |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 203 | *p; |
| 204 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 205 | register Quantum |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 206 | *q, |
| 207 | *r; |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 208 | |
cristy | 31ac0f0 | 2011-03-12 02:04:47 +0000 | [diff] [blame] | 209 | register ssize_t |
| 210 | x; |
| 211 | |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 212 | size_t |
| 213 | length; |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 214 | |
cristy | 31ac0f0 | 2011-03-12 02:04:47 +0000 | [diff] [blame] | 215 | ssize_t |
| 216 | y; |
| 217 | |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 218 | /* |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 219 | Allocate histogram image. |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 220 | */ |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 221 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 222 | assert(image_info->signature == MagickCoreSignature); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 223 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 224 | assert(image->signature == MagickCoreSignature); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 225 | if (image->debug != MagickFalse) |
| 226 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 227 | image_info->filename); |
| 228 | SetGeometry(image,&geometry); |
| 229 | if (image_info->density == (char *) NULL) |
| 230 | (void) ParseAbsoluteGeometry(HistogramDensity,&geometry); |
| 231 | else |
| 232 | (void) ParseAbsoluteGeometry(image_info->density,&geometry); |
| 233 | histogram_image=CloneImage(image,geometry.width,geometry.height,MagickTrue, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 234 | exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 235 | if (histogram_image == (Image *) NULL) |
| 236 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 237 | (void) SetImageStorageClass(histogram_image,DirectClass,exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 238 | /* |
| 239 | Allocate histogram count arrays. |
| 240 | */ |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 241 | length=MagickMax((size_t) ScaleQuantumToChar(QuantumRange)+1UL, |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 242 | histogram_image->columns); |
cristy | 0553bd5 | 2013-06-30 15:53:50 +0000 | [diff] [blame] | 243 | histogram=(PixelInfo *) AcquireQuantumMemory(length,sizeof(*histogram)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 244 | if (histogram == (PixelInfo *) NULL) |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 245 | { |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 246 | histogram_image=DestroyImage(histogram_image); |
| 247 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 248 | } |
| 249 | /* |
| 250 | Initialize histogram count arrays. |
| 251 | */ |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 252 | (void) ResetMagickMemory(histogram,0,length*sizeof(*histogram)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 253 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 254 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 255 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 256 | if (p == (const Quantum *) NULL) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 257 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 258 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 259 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 260 | if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 261 | histogram[ScaleQuantumToChar(GetPixelRed(image,p))].red++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 262 | if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 263 | histogram[ScaleQuantumToChar(GetPixelGreen(image,p))].green++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 264 | if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 265 | histogram[ScaleQuantumToChar(GetPixelBlue(image,p))].blue++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 266 | p+=GetPixelChannels(image); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | maximum=histogram[0].red; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 270 | for (x=0; x < (ssize_t) histogram_image->columns; x++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 271 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 272 | if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) && |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 273 | (maximum < histogram[x].red)) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 274 | maximum=histogram[x].red; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 275 | if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) && |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 276 | (maximum < histogram[x].green)) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 277 | maximum=histogram[x].green; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 278 | if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) && |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 279 | (maximum < histogram[x].blue)) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 280 | maximum=histogram[x].blue; |
| 281 | } |
cristy | e613349 | 2015-01-19 19:57:45 +0000 | [diff] [blame] | 282 | scale=0.0; |
| 283 | if (fabs(maximum) >= MagickEpsilon) |
| 284 | scale=(double) histogram_image->rows/maximum; |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 285 | /* |
| 286 | Initialize histogram image. |
| 287 | */ |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 288 | (void) QueryColorCompliance("#000000",AllCompliance, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 289 | &histogram_image->background_color,exception); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 290 | (void) SetImageBackgroundColor(histogram_image,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 291 | for (x=0; x < (ssize_t) histogram_image->columns; x++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 292 | { |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 293 | q=GetAuthenticPixels(histogram_image,x,0,1,histogram_image->rows,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 294 | if (q == (Quantum *) NULL) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 295 | break; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 296 | if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 297 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 298 | y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].red-0.5); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 299 | r=q+y*GetPixelChannels(histogram_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 300 | for ( ; y < (ssize_t) histogram_image->rows; y++) |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 301 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 302 | SetPixelRed(histogram_image,QuantumRange,r); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 303 | r+=GetPixelChannels(histogram_image); |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 304 | } |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 305 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 306 | if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 307 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 308 | y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].green-0.5); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 309 | r=q+y*GetPixelChannels(histogram_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 310 | for ( ; y < (ssize_t) histogram_image->rows; y++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 311 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 312 | SetPixelGreen(histogram_image,QuantumRange,r); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 313 | r+=GetPixelChannels(histogram_image); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 316 | if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 317 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 | y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].blue-0.5); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 319 | r=q+y*GetPixelChannels(histogram_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 320 | for ( ; y < (ssize_t) histogram_image->rows; y++) |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 321 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 322 | SetPixelBlue(histogram_image,QuantumRange,r); |
cristy | 6db52da | 2013-02-05 13:21:56 +0000 | [diff] [blame] | 323 | r+=GetPixelChannels(histogram_image); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | if (SyncAuthenticPixels(histogram_image,exception) == MagickFalse) |
| 327 | break; |
| 328 | status=SetImageProgress(image,SaveImageTag,y,histogram_image->rows); |
| 329 | if (status == MagickFalse) |
| 330 | break; |
| 331 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 332 | histogram=(PixelInfo *) RelinquishMagickMemory(histogram); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 333 | option=GetImageOption(image_info,"histogram:unique-colors"); |
cristy | d5f40a9 | 2013-02-05 14:07:59 +0000 | [diff] [blame] | 334 | if ((option == (const char *) NULL) || (IsStringTrue(option) != MagickFalse)) |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 335 | { |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 336 | FILE |
| 337 | *file; |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 338 | |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 339 | int |
| 340 | unique_file; |
| 341 | |
| 342 | /* |
| 343 | Add a unique colors as an image comment. |
| 344 | */ |
| 345 | file=(FILE *) NULL; |
| 346 | unique_file=AcquireUniqueFileResource(filename); |
| 347 | if (unique_file != -1) |
| 348 | file=fdopen(unique_file,"wb"); |
| 349 | if ((unique_file != -1) && (file != (FILE *) NULL)) |
| 350 | { |
| 351 | char |
| 352 | *property; |
| 353 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 354 | (void) GetNumberColors(image,file,exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 355 | (void) fclose(file); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 356 | property=FileToString(filename,~0UL,exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 357 | if (property != (char *) NULL) |
| 358 | { |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 359 | (void) SetImageProperty(histogram_image,"comment",property, |
| 360 | exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 361 | property=DestroyString(property); |
| 362 | } |
| 363 | } |
| 364 | (void) RelinquishUniqueFileResource(filename); |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 365 | } |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 366 | /* |
| 367 | Write Histogram image. |
| 368 | */ |
| 369 | (void) CopyMagickString(histogram_image->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 370 | MagickPathExtent); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 371 | write_info=CloneImageInfo(image_info); |
Cristy | e6fb02d | 2015-09-27 10:47:45 -0400 | [diff] [blame] | 372 | *write_info->magick='\0'; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 373 | (void) SetImageInfo(write_info,1,exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 374 | if (LocaleCompare(write_info->magick,"HISTOGRAM") == 0) |
Cristy | e6fb02d | 2015-09-27 10:47:45 -0400 | [diff] [blame] | 375 | (void) FormatLocaleString(histogram_image->filename,MagickPathExtent, |
| 376 | "miff:%s",write_info->filename); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 377 | status=WriteImage(write_info,histogram_image,exception); |
cristy | 787c09c | 2010-04-16 18:18:34 +0000 | [diff] [blame] | 378 | histogram_image=DestroyImage(histogram_image); |
| 379 | write_info=DestroyImageInfo(write_info); |
| 380 | return(status); |
cristy | 1bd4a3a | 2010-04-16 12:38:47 +0000 | [diff] [blame] | 381 | } |