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
|
/**
* 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;
}
void compression(CompressionType compress)
{
imageInfo.compression = compress;
}
CompressionType compression()
{
return imageInfo.compression;
}
//void ddebug(bool d)
//{
//
//}
//bool ddebug()
//{
//
//}
void density(string str)
{
copyString(imageInfo.density, str);
}
string density()
{
return to!(string)(imageInfo.density);
}
void depth(size_t d)
{
imageInfo.depth = d;
}
size_t depth()
{
return imageInfo.depth;
}
void dither(bool d)
{
imageInfo.dither = d;
}
size_t dither()
{
return imageInfo.dither;
}
void endian(EndianType type)
{
imageInfo.endian = type;
}
EndianType endian()
{
return imageInfo.endian;
}
void file(FILE* f)
{
imageInfo.file = f;
}
FILE* file()
{
return imageInfo.file;
}
void filename(string str)
{
copyString(imageInfo.filename, str);
}
string filename()
{
return imageInfo.filename[0 .. strlen(imageInfo.filename.ptr)].idup;
}
void font(string str)
{
copyString(imageInfo.font, str);
copyString(drawInfo.font, str);
}
string font()
{
return to!(string)(drawInfo.font);
}
void fuzz(double f)
{
imageInfo.fuzz = f;
}
double fuzz()
{
return imageInfo.fuzz;
}
void interlace(InterlaceType type)
{
imageInfo.interlace = type;
}
InterlaceType interlace()
{
return imageInfo.interlace;
}
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()
//{
//
//}
void monochrome(bool m)
{
imageInfo.monochrome = m;
}
bool monochrome()
{
return imageInfo.monochrome;
}
void numberOfScenes(size_t num)
{
imageInfo.number_scenes = num;
}
size_t numberOfScenes()
{
return imageInfo.number_scenes;
}
void page(string str)
{
copyString(imageInfo.page, str);
}
string page()
{
return to!(string)(imageInfo.page);
}
void pointSize(double size)
{
imageInfo.pointsize = size;
drawInfo.pointsize = size;
}
double pointSize()
{
return drawInfo.pointsize;
}
void quality(size_t q)
{
imageInfo.quality = q;
}
size_t quality()
{
return imageInfo.quality;
}
void resolutionUnits(ResolutionType type)
{
imageInfo.units = type;
}
ResolutionType resolutionUnits()
{
return imageInfo.units;
}
void samplingFactor(string str)
{
copyString(imageInfo.sampling_factor, str);
}
string samplingFactor()
{
return to!(string)(imageInfo.sampling_factor);
}
void scene(size_t num)
{
imageInfo.scene = num;
}
size_t scene()
{
return imageInfo.scene;
}
void size(string str)
{
copyString(imageInfo.size, str);
}
string size()
{
return to!(string)(imageInfo.size);
}
void type(ImageType t)
{
imageInfo.type = t;
}
ImageType type()
{
return imageInfo.type;
}
void verbose(bool v)
{
imageInfo.verbose = v;
}
bool verbose()
{
return imageInfo.verbose;
}
void view(string str)
{
copyString(imageInfo.view, str);
}
string view()
{
return to!(string)(imageInfo.view);
}
//TODO: Delegates?
void virtualPixelMethod(VirtualPixelMethod method)
{
imageInfo.virtual_pixel_method = method;
}
VirtualPixelMethod virtualPixelMethod()
{
return imageInfo.virtual_pixel_method;
}
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;
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';
}
/**
* Using CloneString whould force us to append a \0
* to the end of the string which might relocate the sting,
* and that is 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';
}
}
|