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