cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 2 | Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3 | dedicated to making software imaging solutions freely available. |
| 4 | |
| 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
| 7 | |
| 8 | http://www.imagemagick.org/script/license.php |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | MagickWand mogrify command-line private methods. |
| 17 | */ |
| 18 | #ifndef _MAGICKWAND_MOGRIFY_PRIVATE_H |
| 19 | #define _MAGICKWAND_MOGRIFY_PRIVATE_H |
| 20 | |
| 21 | #if defined(__cplusplus) || defined(c_plusplus) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | #define AppendImageStack(images) \ |
| 26 | { \ |
| 27 | (void) SyncImagesSettings(image_info,images); \ |
| 28 | AppendImageToList(&image_stack[k].image,images); \ |
| 29 | image=image_stack[k].image; \ |
| 30 | } |
| 31 | #define DegreesToRadians(x) (MagickPI*(x)/180.0) |
| 32 | #define DestroyImageStack() \ |
| 33 | { \ |
| 34 | while (k > 0) \ |
| 35 | PopImageStack(); \ |
| 36 | image_stack[k].image=DestroyImageList(image_stack[k].image); \ |
| 37 | image_stack[k].image_info=DestroyImageInfo(image_stack[k].image_info); \ |
| 38 | } |
| 39 | #define FinalizeImageSettings(image_info,image,advance) \ |
| 40 | { \ |
| 41 | ResetImageOptions(image_info); \ |
| 42 | FireImageStack(MagickTrue,advance,MagickTrue); \ |
cristy | 94f2007 | 2009-09-12 02:12:36 +0000 | [diff] [blame] | 43 | if (image != (Image *) NULL) \ |
cristy | 4ea7c28 | 2009-10-27 13:29:17 +0000 | [diff] [blame] | 44 | { \ |
| 45 | InheritException(exception,&(image)->exception); \ |
| 46 | (void) SyncImagesSettings(image_info,image); \ |
| 47 | } \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 48 | } |
| 49 | #define FireImageStack(postfix,advance,fire) \ |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 50 | if ((j <= i) && (i < (ssize_t) argc)) \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 51 | { \ |
| 52 | if (image_stack[k].image == (Image *) NULL) \ |
| 53 | status&=MogrifyImageInfo(image_stack[k].image_info,(int) (i-j+1), \ |
| 54 | (const char **) (argv+j),exception); \ |
| 55 | else \ |
| 56 | if ((fire) != MagickFalse) \ |
| 57 | { \ |
| 58 | status&=MogrifyImages(image_stack[k].image_info,postfix,(int) \ |
| 59 | (i-j+1),(const char **) (argv+j),&image_stack[k].image, \ |
| 60 | exception); \ |
| 61 | image=image_stack[k].image; \ |
| 62 | if ((advance) != MagickFalse) \ |
| 63 | j=i+1; \ |
| 64 | pend=MagickFalse; \ |
| 65 | } \ |
| 66 | } |
| 67 | #define MagickPI 3.14159265358979323846264338327950288419716939937510 |
| 68 | #define MaxImageStackDepth 32 |
| 69 | #define NewImageStack() \ |
| 70 | { \ |
| 71 | image_stack[0].image_info=CloneImageInfo(image_info); \ |
| 72 | image_stack[0].image=NewImageList(); \ |
| 73 | image_info=image_stack[0].image_info; \ |
| 74 | image=image_stack[0].image; \ |
| 75 | } |
| 76 | #define PushImageStack() \ |
| 77 | { \ |
| 78 | k++; \ |
| 79 | image_stack[k].image_info=CloneImageInfo(image_stack[k-1].image_info); \ |
| 80 | image_stack[k].image=NewImageList(); \ |
| 81 | image_info=image_stack[k].image_info; \ |
| 82 | image=image_stack[k].image; \ |
| 83 | } |
| 84 | #define PopImageStack() \ |
| 85 | { \ |
| 86 | if (respect_parenthesis == MagickFalse) \ |
| 87 | { \ |
| 88 | image_stack[k-1].image_info=DestroyImageInfo(image_stack[k-1].image_info); \ |
| 89 | image_stack[k-1].image_info=CloneImageInfo(image_stack[k].image_info); \ |
| 90 | } \ |
| 91 | image_stack[k].image_info=DestroyImageInfo(image_stack[k].image_info); \ |
| 92 | AppendImageToList(&image_stack[k-1].image,image_stack[k].image); \ |
| 93 | k--; \ |
| 94 | image_info=image_stack[k].image_info; \ |
| 95 | image=image_stack[k].image; \ |
| 96 | } |
| 97 | #define QuantumScale ((MagickRealType) 1.0/(MagickRealType) QuantumRange) |
| 98 | #define QuantumTick(i,span) ((MagickBooleanType) ((((i) & ((i)-1)) == 0) || \ |
| 99 | (((i) & 0xfff) == 0) || \ |
| 100 | ((MagickOffsetType) (i) == ((MagickOffsetType) (span)-1)))) |
| 101 | #define RadiansToDegrees(x) (180.0*(x)/MagickPI) |
| 102 | #define RemoveImageStack(images) \ |
| 103 | { \ |
| 104 | images=RemoveFirstImageFromList(&image_stack[k].image); \ |
| 105 | image=image_stack[k].image; \ |
| 106 | } |
| 107 | #define RemoveAllImageStack() \ |
| 108 | { \ |
| 109 | if (image_stack[k].image != (Image *) NULL) \ |
| 110 | image_stack[k].image=DestroyImageList(image_stack[k].image); \ |
| 111 | } |
| 112 | #define SetImageStack(image) \ |
| 113 | { \ |
| 114 | image_stack[k].image=(image); \ |
| 115 | } |
| 116 | |
| 117 | typedef struct _ImageStack |
| 118 | { |
| 119 | ImageInfo |
| 120 | *image_info; |
| 121 | |
| 122 | Image |
| 123 | *image; |
| 124 | } ImageStack; |
| 125 | |
| 126 | static MagickBooleanType |
| 127 | respect_parenthesis = MagickFalse; |
| 128 | |
| 129 | static inline MagickRealType MagickPixelIntensity( |
| 130 | const MagickPixelPacket *pixel) |
| 131 | { |
| 132 | MagickRealType |
| 133 | intensity; |
| 134 | |
| 135 | intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue; |
| 136 | return(intensity); |
| 137 | } |
| 138 | |
| 139 | static inline Quantum MagickPixelIntensityToQuantum( |
| 140 | const MagickPixelPacket *pixel) |
| 141 | { |
| 142 | MagickRealType |
| 143 | intensity; |
| 144 | |
| 145 | intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue; |
| 146 | return((Quantum) (intensity+0.5)); |
| 147 | } |
| 148 | |
| 149 | static inline MagickRealType PixelIntensity(const PixelPacket *pixel) |
| 150 | { |
| 151 | MagickRealType |
| 152 | intensity; |
| 153 | |
| 154 | intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+ |
| 155 | 0.114*pixel->blue); |
| 156 | return(intensity); |
| 157 | } |
| 158 | |
| 159 | static inline Quantum PixelIntensityToQuantum(const PixelPacket *pixel) |
| 160 | { |
| 161 | MagickRealType |
| 162 | intensity; |
| 163 | |
| 164 | intensity=(MagickRealType) (0.299*pixel->red+0.587*pixel->green+ |
| 165 | 0.114*pixel->blue); |
| 166 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 167 | return((Quantum) (intensity+0.5)); |
| 168 | #else |
| 169 | return((Quantum) intensity); |
| 170 | #endif |
| 171 | } |
| 172 | |
| 173 | static inline void SetMagickPixelPacket(const Image *image, |
| 174 | const PixelPacket *color,const IndexPacket *index,MagickPixelPacket *pixel) |
| 175 | { |
| 176 | pixel->red=(MagickRealType) color->red; |
| 177 | pixel->green=(MagickRealType) color->green; |
| 178 | pixel->blue=(MagickRealType) color->blue; |
| 179 | if (image->matte != MagickFalse) |
| 180 | pixel->opacity=(MagickRealType) color->opacity; |
| 181 | if (((image->colorspace == CMYKColorspace) || |
| 182 | (image->storage_class == PseudoClass)) && |
| 183 | (index != (const IndexPacket *) NULL)) |
| 184 | pixel->index=(MagickRealType) *index; |
| 185 | } |
| 186 | |
| 187 | #if defined(__cplusplus) || defined(c_plusplus) |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | #endif |