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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
/**
* A class to expose ImageInfo QuantizeInfo and DrawInfo
*
* Copyright: Mike Wey 2011
* License: To be determined
* Authors: Mike Wey
*/
module dmagick.Options;
import std.conv;
import core.stdc.string;
import dmagick.c.draw;
import dmagick.c.image;
import dmagick.c.magickString;
import dmagick.c.magickType;
import dmagick.c.memory;
import dmagick.c.quantize;
class Options
{
ImageInfo* imageInfo;
QuantizeInfo* quantizeInfo;
DrawInfo* drawInfo;
this()
{
imageInfo = cast(ImageInfo*)AcquireMagickMemory(ImageInfo.sizeof);
quantizeInfo = cast(QuantizeInfo*)AcquireMagickMemory(QuantizeInfo.sizeof);
drawInfo = cast(DrawInfo*)AcquireMagickMemory(DrawInfo.sizeof);
}
this(const(ImageInfo)* imageInfo, const(QuantizeInfo)* quantizeInfo, const(DrawInfo)* drawInfo)
{
this.imageInfo = CloneImageInfo(imageInfo);
this.quantizeInfo = CloneQuantizeInfo(quantizeInfo);
this.drawInfo = CloneDrawInfo(imageInfo, drawInfo);
}
~this()
{
imageInfo = DestroyImageInfo(imageInfo);
quantizeInfo = DestroyQuantizeInfo(quantizeInfo);
drawInfo = DestroyDrawInfo(drawInfo);
}
/****************************************************************
* ImageInfo fields
****************************************************************/
void adjoin(bool flag)
{
imageInfo.adjoin = flag;
}
bool adjoin()
{
return imageInfo.adjoin;
}
/**
* Set the image background color. The default is "white".
*/
//void backgroundColor(string color)
//{
//
//}
//void backgroundColor(Color color)
//{
//
//}
//Color backgroundColor()
//{
//
//}
/**
* Set a texture to tile onto the image background.
* Corresponds to the -texture option to ImageMagick's
* convert and mogrify commands.
*/
void backgroundTexture(string str)
{
copyString(imageInfo.texture, str);
}
string backgroundTexture()
{
return to!(string)(imageInfo.texture);
}
//void borderColor(Color color)
//{
//
//}
//Color borderColor()
//{
//
//}
/**
* Set the image border color. The default is "#dfdfdf".
*/
void colorspace(ColorspaceType space)
{
imageInfo.colorspace = space;
}
ColorspaceType colorspace()
{
return imageInfo.colorspace;
}
/**
* Specifies the type of compression used when writing the image.
* Only some image formats support compression. For those that do,
* only some compression types are supported. If you specify an
* compression type that is not supported, the default compression
* type (usually NoCompression) is used instead.
*/
void compression(CompressionType compress)
{
imageInfo.compression = compress;
}
CompressionType compression()
{
return imageInfo.compression;
}
//void ddebug(bool d)
//{
//
//}
//bool ddebug()
//{
//
//}
/**
* Specifies the vertical and horizontal resolution in pixels.
* The default density is "72.0x72.0". This attribute can be used
* when writing JBIG, PCL, PS, PS2, and PS3 format images.
*
* This attribute can also be used to specify the width and height
* of HISTOGRAM format images. For HISTOGRAM, the default is 256x200.
*/
void density(string str)
{
copyString(imageInfo.density, str);
}
string density()
{
return to!(string)(imageInfo.density);
}
/**
* Specifies the image depth
*
* Either 8, 16, or 32. You can specify 16 and 32
* only when ImageMagick was compiled with a QuantumDepth
* that allows these depth values.
*/
void depth(size_t d)
{
imageInfo.depth = d;
}
size_t depth()
{
return imageInfo.depth;
}
/**
* This attribute can be used when writing GIF images.
*
* Apply Floyd/Steinberg error diffusion to the image.
* The basic strategy of dithering is to trade intensity
* resolution for spatial resolution by averaging the intensities
* of several neighboring pixels. Images which suffer from severe
* contouring when reducing colors can be improved with this option.
*/
void dither(bool d)
{
imageInfo.dither = d;
}
size_t dither()
{
return imageInfo.dither;
}
/**
* Specify the endianess of the image when reading the image file.
*/
void endian(EndianType type)
{
imageInfo.endian = type;
}
EndianType endian()
{
return imageInfo.endian;
}
/**
* Image file descriptor.
*/
void file(FILE* f)
{
imageInfo.file = f;
}
FILE* file()
{
return imageInfo.file;
}
/**
* Image filename/path.
*/
void filename(string str)
{
copyString(imageInfo.filename, str);
}
string filename()
{
return imageInfo.filename[0 .. strlen(imageInfo.filename.ptr)].idup;
}
/**
* Text rendering font. If the font is a fully qualified
* X server font name, the font is obtained from an X server.
* To use a TrueType font, precede the TrueType filename with an @.
* Otherwise, specify a Postscript font name (e.g. "helvetica")
*/
void font(string str)
{
copyString(imageInfo.font, str);
copyString(drawInfo.font, str);
}
string font()
{
return to!(string)(drawInfo.font);
}
/**
* Colors within this distance are considered equal.
* A number of algorithms search for a target color.
* By default the color must be exact. Use this option to match
* colors that are close to the target color in RGB space.
*/
void fuzz(double f)
{
imageInfo.fuzz = f;
}
double fuzz()
{
return imageInfo.fuzz;
}
/**
* Specify the type of interlacing scheme for raw image formats
* such as RGB or YUV. NoInterlace means do not interlace,
* LineInterlace uses scanline interlacing, and PlaneInterlace
* uses plane interlacing. PartitionInterlace is like PlaneInterlace
* except the different planes are saved to individual files
* (e.g. image.R, image.G, and image.B). Use LineInterlace or
* PlaneInterlace to create an interlaced GIF or
* progressive JPEG image. The default is NoInterlace.
*/
void interlace(InterlaceType type)
{
imageInfo.interlace = type;
}
InterlaceType interlace()
{
return imageInfo.interlace;
}
/**
* Image format (e.g. "GIF")
*/
void magick(string str)
{
copyString(imageInfo.magick, str);
}
string magick()
{
return imageInfo.magick[0 .. strlen(imageInfo.magick.ptr)].idup;
}
//void matteColor(Color color)
//{
//
//}
//Color matteColor()
//{
//
//}
/**
* Transform the image to black and white on input.
* Only the EPT, PDF, and PS formats respect this attribute.
*/
void monochrome(bool m)
{
imageInfo.monochrome = m;
}
bool monochrome()
{
return imageInfo.monochrome;
}
/**
* Use this option to specify the dimensions and position
* of the Postscript page in dots per inch or in pixels.
* This option is typically used in concert with density.
*
* Page may also be used to position a GIF image
* (such as for a scene in an animation)
* The default is "612x792"
*/
void page(string str)
{
copyString(imageInfo.page, str);
}
string page()
{
return to!(string)(imageInfo.page);
}
/**
* Text rendering font point size
*/
void pointSize(double size)
{
imageInfo.pointsize = size;
drawInfo.pointsize = size;
}
double pointSize()
{
return drawInfo.pointsize;
}
/**
* The compression level for JPEG, MPEG, JPEG-2000,
* MIFF, MNG, and PNG image format.
* The default is 75
*/
void quality(size_t q)
{
imageInfo.quality = q;
}
size_t quality()
{
return imageInfo.quality;
}
/**
* Units of image resolution.
*/
void resolutionUnits(ResolutionType type)
{
imageInfo.units = type;
}
ResolutionType resolutionUnits()
{
return imageInfo.units;
}
/**
* sampling factors used by JPEG or MPEG-2 encoder and
* YUV decoder/encoder.
*
* This attribute specifies the sampling factors to be used
* by the JPEG encoder for chroma downsampling.
* If this attribute is omitted, the JPEG library will use its
* own default values. When reading or writing the YUV format and
* when writing the M2V (MPEG-2) format, use sampling-factor="2x1"
* to specify the 4:2:2 downsampling method.
*/
void samplingFactor(string str)
{
copyString(imageInfo.sampling_factor, str);
}
string samplingFactor()
{
return to!(string)(imageInfo.sampling_factor);
}
/**
* Set the width and height of the image when reading a
* built-in image format that does not have an inherent size,
* or when reading an image from a multi-resolution file format
* such as Photo CD, JBIG, or JPEG.
*/
void size(string str)
{
copyString(imageInfo.size, str);
}
string size()
{
return to!(string)(imageInfo.size);
}
/**
* Subimage of an image sequence
*/
void subImage(size_t num)
{
imageInfo.scene = num;
}
size_t subImage()
{
return imageInfo.scene;
}
/**
* Number of images relative to the base image
*/
void subRange(size_t num)
{
imageInfo.number_scenes = num;
}
size_t subRange()
{
return imageInfo.number_scenes;
}
/**
* Image type.
*/
void type(ImageType t)
{
imageInfo.type = t;
}
ImageType type()
{
return imageInfo.type;
}
/**
* Print detailed information about the image.
*/
void verbose(bool v)
{
imageInfo.verbose = v;
}
bool verbose()
{
return imageInfo.verbose;
}
/**
* FlashPix viewing parameters.
*/
void view(string str)
{
copyString(imageInfo.view, str);
}
string view()
{
return to!(string)(imageInfo.view);
}
/**
* Image virtual pixel method.
*/
//TODO: Delegates?
void virtualPixelMethod(VirtualPixelMethod method)
{
imageInfo.virtual_pixel_method = method;
}
VirtualPixelMethod virtualPixelMethod()
{
return imageInfo.virtual_pixel_method;
}
/**
* X11 display to display to obtain fonts from or, to capture image from.
*/
void x11Display(string str)
{
copyString(imageInfo.server_name, str);
}
string x11Display()
{
return to!(string)(imageInfo.server_name);
}
//OrientationType orientation;
//MagickBooleanType temporary,
//MagickBooleanType affirm,
//MagickBooleanType antialias;
//char* extract,
//char* scenes;
//size_t colors;
//PreviewType preview_type;
//ssize_t group;
//MagickBooleanType ping,
//char* authenticate;
//ChannelType channel;
//void* options;
//MagickProgressMonitor progress_monitor;
//void* client_data,
//void* cache;
//StreamHandler stream;
//void* blob;
//size_t length;
//char[MaxTextExtent] unique,
//char[MaxTextExtent] zero,
//size_t signature;
//PixelPacket transparent_color;
//void* profile;
//MagickBooleanType synchronize;
/**
* Copy a string into a static array used
* by ImageMagick for some atributes.
*/
private void copyString(ref char[MaxTextExtent] dest, string source)
{
if ( source.length < MaxTextExtent )
throw new Exception("text is to long"); //TODO: a proper exception.
dest[0 .. source.length] = str;
dest[source.length] = '\0';
}
/**
* Our implementation of ImageMagick's CloneString.
*
* We use this since using CloneString forces us to
* append a \0 to the end of the string, and the realocation
* whould be wastefull if we are just going to copy it
*/
private void copyString(ref char* dest, string source)
{
if ( source is null )
{
if ( dest !is null )
DestroyString(dest);
return;
}
if ( ~source.length < MaxTextExtent )
throw new Exception("UnableToAcquireString"); //TODO: a proper exception.
if ( dest is null )
dest = cast(char*)AcquireQuantumMemory(dest, source.length+MaxTextExtent, dest.sizeof);
else
dest = cast(char*)ResizeQuantumMemory(dest, source.length+MaxTextExtent, dest.sizeof);
if ( dest is null )
throw new Exception("UnableToAcquireString"); //TODO: a proper exception.
if ( source.length > 0 )
dest[0 .. source.length] = str;
dest[source.length] = '\0';
}
}
|