| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #include "magick/studio.h" |
|---|
| 41 | #include "magick/blob.h" |
|---|
| 42 | #include "magick/blob-private.h" |
|---|
| 43 | #include "magick/color-private.h" |
|---|
| 44 | #include "magick/colorspace.h" |
|---|
| 45 | #include "magick/constitute.h" |
|---|
| 46 | #include "magick/exception.h" |
|---|
| 47 | #include "magick/exception-private.h" |
|---|
| 48 | #include "magick/image.h" |
|---|
| 49 | #include "magick/image-private.h" |
|---|
| 50 | #include "magick/list.h" |
|---|
| 51 | #include "magick/magick.h" |
|---|
| 52 | #include "magick/memory_.h" |
|---|
| 53 | #include "magick/module.h" |
|---|
| 54 | #include "magick/monitor.h" |
|---|
| 55 | #include "magick/monitor-private.h" |
|---|
| 56 | #include "magick/property.h" |
|---|
| 57 | #include "magick/quantize.h" |
|---|
| 58 | #include "magick/static.h" |
|---|
| 59 | #include "magick/string_.h" |
|---|
| 60 | #include "magick/utility.h" |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | static MagickBooleanType |
|---|
| 66 | WriteBRAILLEImage(const ImageInfo *,Image *); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | ModuleExport unsigned long RegisterBRAILLEImage(void) |
|---|
| 92 | { |
|---|
| 93 | MagickInfo |
|---|
| 94 | *entry; |
|---|
| 95 | |
|---|
| 96 | entry=SetMagickInfo("BRF"); |
|---|
| 97 | entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage; |
|---|
| 98 | entry->adjoin=MagickFalse; |
|---|
| 99 | entry->description=AcquireString("BRF ASCII Braille format"); |
|---|
| 100 | entry->module=AcquireString("BRAILLE"); |
|---|
| 101 | (void) RegisterMagickInfo(entry); |
|---|
| 102 | entry=SetMagickInfo("UBRL"); |
|---|
| 103 | entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage; |
|---|
| 104 | entry->adjoin=MagickFalse; |
|---|
| 105 | entry->description=AcquireString("Unicode Text format"); |
|---|
| 106 | entry->module=AcquireString("BRAILLE"); |
|---|
| 107 | (void) RegisterMagickInfo(entry); |
|---|
| 108 | entry=SetMagickInfo("ISOBRL"); |
|---|
| 109 | entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage; |
|---|
| 110 | entry->adjoin=MagickFalse; |
|---|
| 111 | entry->description=AcquireString("ISO/TR 11548-1 format"); |
|---|
| 112 | entry->module=AcquireString("BRAILLE"); |
|---|
| 113 | (void) RegisterMagickInfo(entry); |
|---|
| 114 | return(MagickImageCoderSignature); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | ModuleExport void UnregisterBRAILLEImage(void) |
|---|
| 137 | { |
|---|
| 138 | (void) UnregisterMagickInfo("BRF"); |
|---|
| 139 | (void) UnregisterMagickInfo("UBRL"); |
|---|
| 140 | (void) UnregisterMagickInfo("ISOBRL"); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | static MagickBooleanType WriteBRAILLEImage(const ImageInfo *image_info, |
|---|
| 169 | Image *image) |
|---|
| 170 | { |
|---|
| 171 | char |
|---|
| 172 | buffer[MaxTextExtent]; |
|---|
| 173 | |
|---|
| 174 | const char |
|---|
| 175 | *value; |
|---|
| 176 | |
|---|
| 177 | long |
|---|
| 178 | y; |
|---|
| 179 | |
|---|
| 180 | MagickBooleanType |
|---|
| 181 | status; |
|---|
| 182 | |
|---|
| 183 | register const PixelPacket |
|---|
| 184 | *p; |
|---|
| 185 | |
|---|
| 186 | IndexPacket |
|---|
| 187 | polarity, *indexes; |
|---|
| 188 | |
|---|
| 189 | register long |
|---|
| 190 | x; |
|---|
| 191 | |
|---|
| 192 | unsigned long |
|---|
| 193 | cell_height = 4; |
|---|
| 194 | int |
|---|
| 195 | unicode = 0, iso_11548_1 = 0; |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 201 | assert(image_info->signature == MagickSignature); |
|---|
| 202 | assert(image != (Image *) NULL); |
|---|
| 203 | assert(image->signature == MagickSignature); |
|---|
| 204 | |
|---|
| 205 | if (LocaleCompare(image_info->magick, "UBRL") == 0) |
|---|
| 206 | unicode = 1; |
|---|
| 207 | else |
|---|
| 208 | if (LocaleCompare(image_info->magick, "ISOBRL") == 0) |
|---|
| 209 | iso_11548_1 = 1; |
|---|
| 210 | else |
|---|
| 211 | cell_height = 3; |
|---|
| 212 | |
|---|
| 213 | if (image->debug != MagickFalse) |
|---|
| 214 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 215 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
|---|
| 216 | if (status == MagickFalse) |
|---|
| 217 | return(status); |
|---|
| 218 | |
|---|
| 219 | if (!iso_11548_1) |
|---|
| 220 | { |
|---|
| 221 | value=GetImageProperty(image,"Label"); |
|---|
| 222 | if (value != (const char *) NULL) { |
|---|
| 223 | (void) FormatMagickString(buffer,MaxTextExtent,"Title: %s\n", value); |
|---|
| 224 | (void) WriteBlobString(image,buffer); |
|---|
| 225 | } |
|---|
| 226 | if (image->page.x) |
|---|
| 227 | { |
|---|
| 228 | (void) FormatMagickString(buffer,MaxTextExtent,"X: %ld\n", image->page.x); |
|---|
| 229 | (void) WriteBlobString(image,buffer); |
|---|
| 230 | } |
|---|
| 231 | if (image->page.y) |
|---|
| 232 | { |
|---|
| 233 | (void) FormatMagickString(buffer,MaxTextExtent,"Y: %ld\n", image->page.y); |
|---|
| 234 | (void) WriteBlobString(image,buffer); |
|---|
| 235 | } |
|---|
| 236 | (void) FormatMagickString(buffer,MaxTextExtent,"Width: %lu\n", |
|---|
| 237 | image->columns+(image->columns % 2)); |
|---|
| 238 | (void) WriteBlobString(image,buffer); |
|---|
| 239 | (void) FormatMagickString(buffer,MaxTextExtent,"Height: %lu\n", image->rows); |
|---|
| 240 | (void) WriteBlobString(image,buffer); |
|---|
| 241 | |
|---|
| 242 | (void) WriteBlobString(image,"\n"); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | (void) SetImageType(image,BilevelType); |
|---|
| 246 | polarity=(IndexPacket) (PixelIntensityToQuantum(&image->colormap[0]) >= |
|---|
| 247 | (Quantum) (QuantumRange/2)); |
|---|
| 248 | if (image->colors == 2) |
|---|
| 249 | polarity=(IndexPacket) |
|---|
| 250 | (PixelIntensityToQuantum(&image->colormap[0]) >= |
|---|
| 251 | PixelIntensityToQuantum(&image->colormap[1])); |
|---|
| 252 | for (y=0; y < (long) image->rows; y+=cell_height) |
|---|
| 253 | { |
|---|
| 254 | if ((y+cell_height) > image->rows) |
|---|
| 255 | cell_height = (unsigned long) (image->rows-y); |
|---|
| 256 | |
|---|
| 257 | p=AcquireImagePixels(image,0,y,image->columns,cell_height,&image->exception); |
|---|
| 258 | if (p == (const PixelPacket *) NULL) |
|---|
| 259 | break; |
|---|
| 260 | indexes=GetIndexes(image); |
|---|
| 261 | |
|---|
| 262 | for (x=0; x < (long) image->columns; x+=2) |
|---|
| 263 | { |
|---|
| 264 | unsigned char cell = 0; |
|---|
| 265 | int two_columns = x+1 < (long) image->columns; |
|---|
| 266 | |
|---|
| 267 | do |
|---|
| 268 | { |
|---|
| 269 | #define do_cell(dx,dy,bit) \ |
|---|
| 270 | cell |= (indexes[x+dx+dy*image->columns]==polarity)<<bit; |
|---|
| 271 | |
|---|
| 272 | do_cell(0,0,0); |
|---|
| 273 | if (two_columns) |
|---|
| 274 | do_cell(1,0,3); |
|---|
| 275 | if (cell_height < 2) |
|---|
| 276 | break; |
|---|
| 277 | |
|---|
| 278 | do_cell(0,1,1); |
|---|
| 279 | if (two_columns) |
|---|
| 280 | do_cell(1,1,4); |
|---|
| 281 | if (cell_height < 3) |
|---|
| 282 | break; |
|---|
| 283 | |
|---|
| 284 | do_cell(0,2,2); |
|---|
| 285 | if (two_columns) |
|---|
| 286 | do_cell(1,2,5); |
|---|
| 287 | if (cell_height < 4) |
|---|
| 288 | break; |
|---|
| 289 | |
|---|
| 290 | do_cell(0,3,6); |
|---|
| 291 | if (two_columns) |
|---|
| 292 | do_cell(1,3,7); |
|---|
| 293 | } while(0); |
|---|
| 294 | |
|---|
| 295 | if (unicode) |
|---|
| 296 | { |
|---|
| 297 | unsigned char utf8[3]; |
|---|
| 298 | |
|---|
| 299 | utf8[0] = (unsigned char) (0xe0|((0x28>>4)&0x0f)); |
|---|
| 300 | utf8[1] = 0x80|((0x28<<2)&0x3f)|(cell>>6); |
|---|
| 301 | utf8[2] = 0x80|(cell&0x3f); |
|---|
| 302 | (void) WriteBlob(image,3,utf8); |
|---|
| 303 | } |
|---|
| 304 | else if (iso_11548_1) |
|---|
| 305 | { |
|---|
| 306 | |
|---|
| 307 | (void) WriteBlobByte(image,cell); |
|---|
| 308 | } |
|---|
| 309 | else |
|---|
| 310 | { |
|---|
| 311 | |
|---|
| 312 | static const unsigned char iso_to_brf[64] = { |
|---|
| 313 | ' ', 'A', '1', 'B', '\'', 'K', '2', 'L', |
|---|
| 314 | '@', 'C', 'I', 'F', '/', 'M', 'S', 'P', |
|---|
| 315 | '"', 'E', '3', 'H', '9', 'O', '6', 'R', |
|---|
| 316 | '^', 'D', 'J', 'G', '>', 'N', 'T', 'Q', |
|---|
| 317 | ',', '*', '5', '<', '-', 'U', '8', 'V', |
|---|
| 318 | '.', '%', '[', '$', '+', 'X', '!', '&', |
|---|
| 319 | ';', ':', '4', '\\', '0', 'Z', '7', '(', |
|---|
| 320 | '_', '?', 'W', ']', '#', 'Y', ')', '=' |
|---|
| 321 | }; |
|---|
| 322 | (void) WriteBlobByte(image,iso_to_brf[cell]); |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | if (!iso_11548_1) |
|---|
| 326 | (void) WriteBlobByte(image,'\n'); |
|---|
| 327 | image=SyncNextImageInList(image); |
|---|
| 328 | status=SetImageProgress(image,SaveImageTag,y,image->rows); |
|---|
| 329 | if (status == MagickFalse) |
|---|
| 330 | break; |
|---|
| 331 | } |
|---|
| 332 | (void) CloseBlob(image); |
|---|
| 333 | return(MagickTrue); |
|---|
| 334 | } |
|---|