Annotation of parser3/src/classes/image.C, revision 1.84
1.1 paf 1: /** @file
2: Parser: @b image parser class.
3:
1.67 paf 4: Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.66 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.73 paf 6: */
1.1 paf 7:
1.84 ! paf 8: static const char* IDENT_IMAGE_C="$Date: 2002/11/25 15:37:12 $";
1.31 parser 9:
10: /*
11: jpegsize: gets the width and height (in pixels) of a jpeg file
12: Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995
13: modified slightly by alex@ed.ac.uk
14: and further still by rjray@uswest.com
15: optimization and general re-write from tmetro@vl.com
16: from perl by paf@design.ru
1.1 paf 17: */
18:
19: #include "pa_config_includes.h"
20:
1.8 paf 21: #include "gif.h"
1.6 paf 22:
1.1 paf 23: #include "pa_common.h"
24: #include "pa_request.h"
25: #include "pa_vfile.h"
26: #include "pa_vimage.h"
27:
1.22 paf 28: // class
29:
30: class MImage : public Methoded {
31: public: // VStateless_class
32: Value *create_new_value(Pool& pool) { return new(pool) VImage(pool); }
33:
34: public:
35: MImage(Pool& pool);
1.24 paf 36:
37: public: // Methoded
1.22 paf 38: bool used_directly() { return true; }
39:
40: };
1.1 paf 41:
42: // helpers
43:
1.43 parser 44: #ifndef DOXYGEN
1.1 paf 45: class Measure_reader {
46: public:
1.77 paf 47: virtual size_t read(const void *&buf, size_t limit)=0;
1.79 paf 48: virtual void seek(long value, int whence)=0;
49: virtual long tell()=0;
1.77 paf 50: };
1.1 paf 51:
1.77 paf 52: class Measure_file_reader: public Measure_reader {
53: public:
54: Measure_file_reader(Pool& apool, int af, const String& afile_name, const char *afname):
55: pool(apool), file_name(afile_name), fname(afname), f(af) {
1.1 paf 56: }
57:
1.77 paf 58: /*override*/size_t read(const void *&abuf, size_t limit) {
59: if(limit==0)
1.1 paf 60: return 0;
1.77 paf 61:
62: void *lbuf=pool.malloc(limit);
63: size_t read_size=(size_t)::read(f, lbuf, limit); abuf=lbuf;
64: if(ssize_t(read_size)<0 || read_size>limit)
65: throw Exception(0,
66: &file_name,
67: "measure failed: actually read %lu bytes count not in [0..%lu] valid range",
68: read_size, limit);
69:
1.1 paf 70: return read_size;
71: }
72:
1.79 paf 73: /*override*/void seek(long value, int whence) {
74: if(lseek(f, value, whence)<0)
1.77 paf 75: throw Exception("file.seek",
76: &file_name,
1.79 paf 77: "seek(value=%ld, whence=%d) failed: %s (%d), actual filename '%s'",
78: value, whence, strerror(errno), errno, fname);
1.77 paf 79: }
80:
1.81 paf 81: /*override*/long tell() { return lseek(f, 0, SEEK_CUR); }
1.79 paf 82:
1.1 paf 83: private:
1.77 paf 84: Pool& pool;
85: const String& file_name; const char *fname;
86: int f;
87: };
88:
89: class Measure_buf_reader: public Measure_reader {
90: public:
91: Measure_buf_reader(const void *abuf, size_t asize, const String& afile_name):
92: buf(abuf), size(asize), file_name(afile_name), offset(0) {
93: }
94:
95: /*override*/size_t read(const void *&abuf, size_t limit) {
96: size_t to_read=min(limit, size-offset);
97: abuf=(const char*)buf+offset;
98: offset+=to_read;
99: return to_read;
100: }
101:
1.79 paf 102: /*override*/void seek(long value, int whence) {
103: size_t new_offset;
104: switch(whence) {
105: case SEEK_CUR: new_offset=offset+value; break;
106: case SEEK_SET: new_offset=(size_t)value; break;
107: default: throw Exception("file.seek", 0, "whence #%d not supported", 0, whence); break;
108: }
109:
1.77 paf 110: if((ssize_t)new_offset<0 || new_offset>size)
111: throw Exception("file.seek",
112: &file_name,
1.79 paf 113: "seek(value=%l, whence=%d) failed: out of buffer, new_offset>size (%l>%l) or new_offset<0",
114: value, whence, new_offset, size);
1.77 paf 115: offset=new_offset;
116: }
117:
1.79 paf 118: /*override*/long tell() { return offset; }
119:
1.77 paf 120: private:
121:
122: const void *buf; size_t size;
123: const String& file_name;
1.1 paf 124:
125: size_t offset;
126: };
1.77 paf 127:
1.43 parser 128: #endif
1.1 paf 129:
1.72 paf 130: /// PNG file header
131: struct PNG_Header {
132: char dummy[12];
133: char signature[4]; //< must be "IHDR"
1.80 paf 134: uchar high_width[2]; //< image width high bytes [we ignore for now]
135: uchar width[2]; //< image width low bytes
136: uchar high_height[2]; //< image height high bytes [we ignore for now]
137: uchar height[4]; //< image height
1.72 paf 138: };
139:
1.21 paf 140: /// GIF file header
1.1 paf 141: struct GIF_Header {
1.72 paf 142: char signature[3]; // 'GIF'
1.1 paf 143: char version[3];
1.80 paf 144: uchar width[2];
145: uchar height[2];
1.1 paf 146: char dif;
147: char fonColor;
148: char nulls;
149: };
150:
1.31 parser 151: /// JPEG record head
152: struct JPG_Segment_head {
1.80 paf 153: uchar marker;
154: uchar code;
155: uchar length[2];
1.1 paf 156: };
1.21 paf 157: /// JPEG frame header
1.31 parser 158: struct JPG_Size_segment_body {
1.27 parser 159: char data; //< data precision of bits/sample
1.80 paf 160: uchar height[2]; //< image height
161: uchar width[2]; //< image width
1.27 parser 162: char numComponents; //< number of color components
1.1 paf 163: };
164:
1.79 paf 165: /// JPEG frame header
166: struct JPG_Exif_segment_start {
167: char signature[6]; // Exif\0\0
168: };
169:
1.80 paf 170: /// JPEG Exif TIFF Header
171: struct JPG_Exif_TIFF_header {
172: uchar byte_align_identifier[2];
173: char dummy[2]; // always 000A [or 0A00]
174: uchar first_IFD_offset[4]; // Usually the first IFD starts immediately next to TIFF header, so this offset has value '0x00000008'.
175: };
176:
177: // JPEG Exif IFD start
178: struct JPG_Exif_IFD_start {
179: uchar directory_entry_count[2]; // the number of directory entry contains in this IFD
180: };
181:
182: // TTTT ffff NNNNNNNN DDDDDDDD
183: struct JPG_Exif_IFD_entry {
184: uchar tag[2]; // Tag number, this shows a kind of data
185: uchar format[2]; // data format
186: uchar components_count[4]; // number of components
187: uchar value_or_offset_to_it[4]; // data value or offset to data value
188: };
189:
190: #define JPG_IFD_TAG_EXIF_OFFSET 0x8769
191:
1.1 paf 192: //
193:
1.80 paf 194: inline ushort x_endian_to_ushort(uchar b0, uchar b1) {
195: return (ushort)((b1<<8) + b0);
1.33 parser 196: }
197:
1.80 paf 198: inline uint x_endian_to_uint(uchar b0, uchar b1, uchar b2, uchar b3) {
199: return (uint)(((((b3<<8) + b2)<<8)+b1)<<8)+b0;
1.33 parser 200: }
201:
1.80 paf 202: inline ushort endian_to_ushort(bool is_big, const uchar *b/* [2] */) {
203: return is_big?x_endian_to_ushort(b[1], b[0]):
204: x_endian_to_ushort(b[0], b[1]);
1.1 paf 205: }
206:
1.80 paf 207: inline uint endian_to_uint(bool is_big, const uchar *b /* [4] */) {
208: return is_big?x_endian_to_uint(b[3], b[2], b[1], b[0]):
209: x_endian_to_uint(b[0], b[1], b[2], b[3]);
210: }
211:
212: static void measure_gif(Pool& pool, const String *origin_string,
1.78 paf 213: Measure_reader& reader, ushort& width, ushort& height) {
1.1 paf 214:
1.83 paf 215: const void *buf;
1.1 paf 216: const int head_size=sizeof(GIF_Header);
217: if(reader.read(buf, head_size)<head_size)
1.68 paf 218: throw Exception("image.format",
1.1 paf 219: origin_string,
1.34 parser 220: "not GIF file - too small");
1.31 parser 221: GIF_Header *head=(GIF_Header *)buf;
1.1 paf 222:
1.72 paf 223: if(strncmp(head->signature, "GIF", 3)!=0)
1.68 paf 224: throw Exception("image.format",
1.1 paf 225: origin_string,
1.44 parser 226: "not GIF file - wrong signature");
1.1 paf 227:
1.80 paf 228: width=endian_to_ushort(false, head->width);
229: height=endian_to_ushort(false, head->height);
230: }
231:
232: static Value *parse_IFD_entry_formatted_one_value(Pool& pool,
233: bool is_big,
234: ushort format,
235: size_t component_size,
236: const uchar *value) {
237: switch(format) {
238: case 1: // unsigned byte
239: return new(pool) VInt(pool, (uchar)value[0]);
240: case 3: // unsigned short
241: return new(pool) VInt(pool, endian_to_ushort(is_big, value));
242: case 4: // unsigned long
243: // 'double' because parser's Int is signed
244: return new(pool) VDouble(pool, endian_to_uint(is_big, value));
245: case 5: // unsigned rational
246: {
247: uint numerator=endian_to_uint(is_big, value); value+=component_size/2;
248: uint denominator=endian_to_uint(is_big, value);
249: if(!denominator)
250: return 0;
251: return new(pool) VDouble(pool, ((double)numerator)/denominator);
252: }
253: case 6: // signed byte
254: return new(pool) VInt(pool, (signed char)value[0]);
255: case 8: // signed short
256: return new(pool) VInt(pool, (signed short)endian_to_ushort(is_big, value));
257: case 9: // signed long
258: return new(pool) VInt(pool, (signed int)endian_to_uint(is_big, value));
259: case 10: // signed rational
260: {
261: signed int numerator=(signed int)endian_to_uint(is_big, value); value+=component_size/2;
262: uint denominator=endian_to_uint(is_big, value);
263: if(!denominator)
264: return 0;
265: return new(pool) VDouble(pool, numerator/denominator);
266: }
267: /*
268: case 11: // single float
269: todo
270: case 12: // double float
271: todo
272: */
273: };
274:
275: return 0;
276: }
277:
278: static Value *parse_IFD_entry_formatted_value(Pool& pool,
279: bool is_big, ushort format,
280: size_t component_size, uint components_count,
281: const uchar *value) {
282: if(format==2) { // ascii string, exception: the only type with varying size
283: const char *cstr=(const char *)value;
284: size_t size=components_count;
285: if(const char *premature_zero_pos=(const char *)memchr(cstr, 0, size))
286: size=premature_zero_pos-cstr;
287: return new(pool) VString(*new(pool) String(pool, cstr, size, true/*tainted*/));
288: }
289:
290: if(components_count==1)
291: return parse_IFD_entry_formatted_one_value(pool, is_big, format, component_size, value);
292:
293: VHash& result=*new(pool) VHash(pool);
294: Hash& hash=result.hash(0);
295: for(uint i=0; i<components_count; i++, value+=component_size) {
296: String& skey=*new(pool) String(pool);
297: {
298: char *buf=(char *)pool.malloc(MAX_NUMBER);
299: snprintf(buf, MAX_NUMBER, "%d", i);
300: skey << buf;
301: }
302: hash.put(skey, parse_IFD_entry_formatted_one_value(pool, is_big, format, component_size, value));
303: }
304:
305: return &result;
306: }
307:
308: static Value *parse_IFD_entry_value(Pool& pool,
309: bool is_big, Measure_reader& reader, long tiff_base,
310: JPG_Exif_IFD_entry& entry) {
311: size_t format2component_size[]={
312: 0, // undefined
313: 1, // unsigned byte
314: 1, // ascii string
315: 2, // unsigned short
316: 4, // unsigned long
317: 8, // unsigned rational
318: 1, // signed byte
319: 0, // undefined
320: 2, // signed short
321: 4, // signed long
322: 8, // signed rational
323: /*
324: 4, // single float
325: 8, // double float
326: */
327: };
328:
329: ushort format=endian_to_ushort(is_big, entry.format);
330: if(format>=sizeof(format2component_size)/sizeof(format2component_size[0]))
331: return 0; // format out of range, ignoring
332:
333: size_t component_size=format2component_size[format];
334: if(component_size==0)
335: return 0; // undefined format
336:
337: // You can get the total data byte length by multiplies
338: // a 'bytes/components' value (see above chart) by number of components stored 'NNNNNNNN' area
339: uint components_count=endian_to_uint(is_big, entry.components_count);
340: size_t value_size=component_size*components_count;
341: // If its size is over 4bytes, 'DDDDDDDD' contains the offset to data stored address
342: Value *result;
343:
344: if(value_size<=4)
345: result=parse_IFD_entry_formatted_value(pool,
346: is_big, format,
347: component_size, components_count,
348: entry.value_or_offset_to_it);
349: else {
350: long remembered=reader.tell();
351: {
352: reader.seek(tiff_base+endian_to_uint(is_big, entry.value_or_offset_to_it), SEEK_SET);
353: const void *value;
354: if(reader.read(value, value_size)<sizeof(value_size))
355: return 0;
356: result=parse_IFD_entry_formatted_value(pool,
357: is_big, format,
358: component_size, components_count,
359: (const uchar*)value);
360: }
361: reader.seek(remembered, SEEK_SET);
362: }
363:
364: return result;
365: }
366:
367: static void parse_IFD(Pool& pool,
368: Hash& hash,
369: bool is_big, Measure_reader& reader, long tiff_base);
370:
371: static void parse_IFD_entry(Pool& pool, Hash& hash,
372: bool is_big, Measure_reader& reader, long tiff_base,
373: JPG_Exif_IFD_entry& entry) {
374: ushort tag=endian_to_ushort(is_big, entry.tag);
375: if(tag==JPG_IFD_TAG_EXIF_OFFSET) {
376: long remembered=reader.tell();
377: {
378: reader.seek(tiff_base+endian_to_uint(is_big, entry.value_or_offset_to_it), SEEK_SET);
379: parse_IFD(pool, hash, is_big, reader, tiff_base);
380: }
381: reader.seek(remembered, SEEK_SET);
382: return;
383: }
384:
385: if(Value *value=parse_IFD_entry_value(pool, is_big, reader, tiff_base, entry)) {
386: String& skey=*new(pool) String(pool);
387: {
388: char *buf=(char *)pool.malloc(MAX_NUMBER);
389: snprintf(buf, MAX_NUMBER, "%u", tag);
390: skey << buf;
391: }
392:
393: if(const char *name=(const char *)exif_tag_value2name->get(skey))
394: hash.put(*new(pool) String(pool, name), value);
395: else
396: hash.put(skey, value);
397: }
1.1 paf 398: }
399:
1.80 paf 400: static void parse_IFD(Pool& pool,
401: Hash& hash,
402: bool is_big, Measure_reader& reader, long tiff_base) {
403: const void *buf;
404: if(reader.read(buf, sizeof(JPG_Exif_IFD_start))<sizeof(JPG_Exif_IFD_start))
405: return;
406: JPG_Exif_IFD_start *start=(JPG_Exif_IFD_start *)buf;
407:
408: ushort directory_entry_count=endian_to_ushort(is_big, start->directory_entry_count);
409: for(int i=0; i<directory_entry_count; i++) {
410: if(reader.read(buf, sizeof(JPG_Exif_IFD_entry))<sizeof(JPG_Exif_IFD_entry))
411: return;
412:
413: parse_IFD_entry(pool, hash, is_big, reader, tiff_base, *(JPG_Exif_IFD_entry *)buf);
414: }
415: // then goes: LLLLLLLL Offset to next IFD [not going there]
416: }
417:
418: static Value *parse_exif(Pool& pool,
419: Measure_reader& reader,
420: const String *origin_string) {
421: const void *buf;
422: if(reader.read(buf, sizeof(JPG_Exif_segment_start))<sizeof(JPG_Exif_segment_start))
423: throw Exception("image.format",
424: origin_string,
425: "not JPEG file - can not fully read Exif segment start");
426:
427: JPG_Exif_segment_start *start=(JPG_Exif_segment_start *)buf;
428: if(memcmp(start->signature, "Exif\0\0", 4+2)!=0) //signature invalid?
429: return 0; // ignore invalid block
430:
431: uint tiff_base=reader.tell();
432: if(reader.read(buf, sizeof(JPG_Exif_TIFF_header))<sizeof(JPG_Exif_TIFF_header))
433: return 0;
434:
435: JPG_Exif_TIFF_header *head=(JPG_Exif_TIFF_header *)buf;
436: bool is_big=head->byte_align_identifier[0]=='M'; // [M]otorola vs [I]ntel
437:
438: uint first_IFD_offset=endian_to_uint(is_big, head->first_IFD_offset);
439: reader.seek(tiff_base+first_IFD_offset, SEEK_SET);
440:
441: VHash& vhash=*new(pool) VHash(pool);
442:
443: // IFD
444: parse_IFD(pool, vhash.hash(0), is_big, reader, tiff_base);
445:
446: return &vhash;
447: }
448:
449: static void measure_jpeg(Pool& pool, const String *origin_string,
450: Measure_reader& reader, ushort& width, ushort& height, Value ** exif) {
1.2 paf 451: // JFIF format markers
1.80 paf 452: const uchar MARKER=0xFF;
453: const uchar CODE_SIZE_A=0xC0;
454: const uchar CODE_SIZE_B=0xC1;
455: const uchar CODE_SIZE_C=0xC2;
456: const uchar CODE_SIZE_D=0xC3;
457: const uchar CODE_EXIF=0xE1;
1.2 paf 458:
1.83 paf 459: const void *buf;
1.18 paf 460: const size_t prefix_size=2;
1.31 parser 461: if(reader.read(buf, prefix_size)<prefix_size)
1.68 paf 462: throw Exception("image.format",
1.1 paf 463: origin_string,
1.34 parser 464: "not JPEG file - too small");
1.80 paf 465: uchar *signature=(uchar *)buf;
1.1 paf 466:
1.31 parser 467: if(!(signature[0]==0xFF && signature[1]==0xD8))
1.68 paf 468: throw Exception("image.format",
1.1 paf 469: origin_string,
1.44 parser 470: "not JPEG file - wrong signature");
1.31 parser 471:
472: while(true) {
1.80 paf 473: uint segment_base=reader.tell()+2/*marker,code*/;
1.31 parser 474: if(reader.read(buf, sizeof(JPG_Segment_head))<sizeof(JPG_Segment_head))
1.79 paf 475: break;
1.31 parser 476: JPG_Segment_head *head=(JPG_Segment_head *)buf;
477:
478: // Verify that it's a valid segment.
479: if(head->marker!=MARKER)
1.79 paf 480: throw Exception("image.format",
481: origin_string,
482: "not JPEG file - marker not found");
483:
484: switch(head->code) {
485: // http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
486: case CODE_EXIF:
1.80 paf 487: if(exif && !*exif) // seen .jpg with some xml under EXIF tag, after real exif block :)
488: *exif=parse_exif(pool, reader, origin_string);
1.1 paf 489: break;
1.31 parser 490:
1.79 paf 491: case CODE_SIZE_A:
492: case CODE_SIZE_B:
493: case CODE_SIZE_C:
494: case CODE_SIZE_D:
495: {
496: // Segments that contain size info
497: if(reader.read(buf, sizeof(JPG_Size_segment_body))<sizeof(JPG_Size_segment_body))
498: throw Exception("image.format",
499: origin_string,
500: "not JPEG file - can not fully read Size segment");
501: JPG_Size_segment_body *body=(JPG_Size_segment_body *)buf;
502:
1.80 paf 503: width=endian_to_ushort(true, body->width);
504: height=endian_to_ushort(true, body->height);
1.79 paf 505: }
1.80 paf 506: return;
1.79 paf 507: };
508:
1.80 paf 509: reader.seek(segment_base+endian_to_ushort(true, head->length), SEEK_SET);
1.31 parser 510: }
511:
1.79 paf 512: throw Exception("image.format",
513: origin_string,
514: "broken JPEG file - size frame not found");
1.1 paf 515: }
516:
1.80 paf 517: static void measure_png(Pool& pool, const String *origin_string,
1.78 paf 518: Measure_reader& reader, ushort& width, ushort& height) {
1.72 paf 519:
1.83 paf 520: const void *buf;
1.72 paf 521: const int head_size=sizeof(PNG_Header);
522: if(reader.read(buf, head_size)<head_size)
523: throw Exception("image.format",
524: origin_string,
525: "not PNG file - too small");
526: PNG_Header *head=(PNG_Header *)buf;
527:
528: if(strncmp(head->signature, "IHDR", 4)!=0)
529: throw Exception("image.format",
530: origin_string,
531: "not PNG file - wrong signature");
532:
1.80 paf 533: width=endian_to_ushort(true, head->width);
534: height=endian_to_ushort(true, head->height);
1.72 paf 535: }
536:
1.1 paf 537: // measure center
538:
1.80 paf 539: static void measure(Pool& pool, const String& file_name,
540: Measure_reader& reader, ushort& width, ushort& height, Value ** exif) {
1.60 paf 541: if(const char *cext=strrchr(file_name.cstr(String::UL_FILE_SPEC), '.')) {
1.1 paf 542: cext++;
543: if(strcasecmp(cext, "GIF")==0)
544: measure_gif(pool, &file_name, reader, width, height);
545: else if(strcasecmp(cext, "JPG")==0 || strcasecmp(cext, "JPEG")==0)
1.80 paf 546: measure_jpeg(pool, &file_name, reader, width, height, exif);
1.72 paf 547: else if(strcasecmp(cext, "PNG")==0)
548: measure_png(pool, &file_name, reader, width, height);
1.1 paf 549: else
1.68 paf 550: throw Exception("image.format",
1.1 paf 551: &file_name,
552: "unhandled image file name extension '%s'", cext);
553: } else
1.68 paf 554: throw Exception("image.format",
1.1 paf 555: &file_name,
556: "can not determine image type - no file name extension");
557: }
558:
1.77 paf 559: // methods
1.1 paf 560:
1.40 parser 561: #ifndef DOXYGEN
1.77 paf 562: struct File_measure_action_info {
1.78 paf 563: ushort *width;
564: ushort *height;
1.80 paf 565: Value ** exif;
1.77 paf 566: const String *file_name;
1.1 paf 567: };
1.40 parser 568: #endif
1.77 paf 569: static void file_measure_action(Pool& pool,
1.80 paf 570: struct stat& finfo, int f,
1.77 paf 571: const String& file_spec, const char *fname, bool as_text,
572: void *context) {
573: File_measure_action_info& info=*static_cast<File_measure_action_info *>(context);
1.1 paf 574:
1.77 paf 575: Measure_file_reader reader(pool, f, *info.file_name, fname);
1.80 paf 576: measure(pool, *info.file_name, reader, *info.width, *info.height, info.exif);
1.1 paf 577: }
578:
1.17 paf 579: static void _measure(Request& r, const String& method_name, MethodParams *params) {
1.1 paf 580: Pool& pool=r.pool();
581:
1.30 parser 582: Value& data=params->as_no_junction(0, "data must not be code");
1.1 paf 583:
1.78 paf 584: ushort width=0;
585: ushort height=0;
1.80 paf 586: Value *exif=0;
1.1 paf 587: const String *file_name;
1.77 paf 588: if(file_name=data.get_string()) {
1.80 paf 589: File_measure_action_info info={&width, &height, &exif, file_name};
1.77 paf 590: file_read_action_under_lock(pool, r.absolute(*file_name),
591: "measure", file_measure_action, &info);
1.1 paf 592: } else {
593: const VFile& vfile=*data.as_vfile();
594: file_name=&static_cast<Value *>(vfile.fields().get(*name_name))->as_string();
1.77 paf 595: Measure_buf_reader reader(
596: vfile.value_ptr(),
597: vfile.value_size(),
598: *file_name
599: );
1.80 paf 600: measure(pool, *file_name, reader, width, height, &exif);
1.1 paf 601: }
602:
1.80 paf 603: VImage &vimage=*static_cast<VImage *>(r.get_self());
604: vimage.set(file_name, width, height, 0, exif);
1.1 paf 605: }
606:
1.40 parser 607: #ifndef DOXYGEN
1.4 paf 608: struct Attrib_info {
1.21 paf 609: String *tag; ///< html tag being constructed
610: Hash *skip; ///< tag attributes not to append to tag string [to skip]
1.4 paf 611: };
1.40 parser 612: #endif
1.3 paf 613: static void append_attrib_pair(const Hash::Key& key, Hash::Val *val, void *info) {
1.4 paf 614: Attrib_info& ai=*static_cast<Attrib_info *>(info);
615:
1.49 parser 616: // skip user-specified and internal(starting with "line-") attributes
617: if(ai.skip && ai.skip->get(key) || key.pos("line-")==0)
1.4 paf 618: return;
619:
1.3 paf 620: Value& value=*static_cast<Value *>(val);
621: // src="a.gif" width=123 ismap[=-1]
1.4 paf 622: *ai.tag << " " << key;
1.26 parser 623: if(value.is_string() || value.as_int()>=0)
1.6 paf 624: *ai.tag << "=\"" << value.as_string() << "\"";
1.3 paf 625: }
1.17 paf 626: static void _html(Request& r, const String& method_name, MethodParams *params) {
1.3 paf 627: Pool& pool=r.pool();
628:
629: String tag(pool);
630: tag << "<img";
1.4 paf 631:
1.76 paf 632: const Hash& fields=static_cast<VImage *>(r.get_self())->fields();
1.5 paf 633: Hash *attribs=0;
1.4 paf 634:
1.39 parser 635: if(params->size()) {
1.69 paf 636: // for backward compatibility: someday was ^html{}
637: Value &vattribs=r.process_to_value(params->get(0),
1.70 paf 638: /*0/*no name* /,*/
1.52 parser 639: false/*don't intercept string*/);
1.82 paf 640: if(!vattribs.is_string()) // allow empty
1.59 parser 641: if(attribs=vattribs.get_hash(&method_name)) {
1.39 parser 642: Attrib_info attrib_info={&tag, 0};
643: attribs->for_each(append_attrib_pair, &attrib_info);
644: } else
1.68 paf 645: throw Exception("parser.runtime",
1.39 parser 646: &method_name,
647: "attributes must be hash");
648: }
1.4 paf 649:
1.5 paf 650: Attrib_info attrib_info={&tag, attribs};
1.4 paf 651: fields.for_each(append_attrib_pair, &attrib_info);
1.6 paf 652: tag << " />";
1.3 paf 653: r.write_pass_lang(tag);
654: }
1.8 paf 655:
1.68 paf 656: /// @test wrap FILE to auto-object
1.16 paf 657: static gdImage *load(Request& r, const String& method_name,
658: const String& file_name){
659: Pool& pool=r.pool();
660:
1.42 parser 661: const char *file_name_cstr=r.absolute(file_name).cstr(String::UL_FILE_SPEC);
1.16 paf 662: if(FILE *f=fopen(file_name_cstr, "rb")) {
663: gdImage& image=*new(pool) gdImage(pool);
1.23 paf 664: bool ok=image.CreateFromGif(f);
1.16 paf 665: fclose(f);
1.23 paf 666: if(!ok)
1.68 paf 667: throw Exception("image.format",
1.23 paf 668: &file_name,
669: "is not in GIF format");
1.16 paf 670: return ℑ
671: } else {
1.68 paf 672: throw Exception("file.missing",
1.16 paf 673: &method_name,
674: "can not open '%s'", file_name_cstr);
675: return 0;
676: }
677: }
678:
679:
1.17 paf 680: static void _load(Request& r, const String& method_name, MethodParams *params) {
1.6 paf 681: Pool& pool=r.pool();
682:
1.44 parser 683: const String& file_name=params->as_string(0, "file name must not be code");
1.6 paf 684:
1.16 paf 685: gdImage& image=*load(r, method_name, file_name);
686: int width=image.SX();
687: int height=image.SY();
1.76 paf 688: static_cast<VImage *>(r.get_self())->set(&file_name, width, height, &image);
1.6 paf 689: }
690:
1.17 paf 691: static void _create(Request& r, const String& method_name, MethodParams *params) {
1.6 paf 692: Pool& pool=r.pool();
693:
1.51 parser 694: int width=params->as_int(0, "width must be int", r);
695: int height=params->as_int(1, "height must be int", r);
1.8 paf 696: int bgcolor_value=0xffFFff;
1.6 paf 697: if(params->size()>2)
1.51 parser 698: bgcolor_value=params->as_int(2, "color must be int", r);
1.15 paf 699: gdImage& image=*new(pool) gdImage(pool);
700: image.Create(width, height);
701: image.FilledRectangle(0, 0, width-1, height-1, image.Color(bgcolor_value));
1.76 paf 702: static_cast<VImage *>(r.get_self())->set(0, width, height, &image);
1.6 paf 703: }
704:
1.17 paf 705: static void _gif(Request& r, const String& method_name, MethodParams *params) {
1.6 paf 706: Pool& pool=r.pool();
707:
1.76 paf 708: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.8 paf 709: if(!image)
1.68 paf 710: throw Exception(0,
1.16 paf 711: &method_name,
1.12 paf 712: "does not contain an image");
1.6 paf 713:
714: // could _ but don't thing it's wise to use $image.src for vfile.name
1.10 paf 715:
1.16 paf 716: String out(pool); image->Gif(out);
1.6 paf 717:
718: VFile& vfile=*new(pool) VFile(pool);
1.41 parser 719: Value *content_type=new(pool) VString(*new(pool) String(pool, "image/gif"));
1.20 paf 720: vfile.set(false/*not tainted*/,
1.61 paf 721: out.cstr(), out.size(), 0, content_type);
1.6 paf 722:
723: r.write_no_lang(vfile);
724: }
725:
1.17 paf 726: static void _line(Request& r, const String& method_name, MethodParams *params) {
1.12 paf 727: Pool& pool=r.pool();
728:
1.76 paf 729: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.12 paf 730: if(!image)
1.68 paf 731: throw Exception(0,
1.16 paf 732: &method_name,
1.12 paf 733: "does not contain an image");
734:
735: image->Line(
1.51 parser 736: params->as_int(0, "x0 must be int", r),
737: params->as_int(1, "y0 must be int", r),
738: params->as_int(2, "x1 must be int", r),
739: params->as_int(3, "y1 must be int", r),
740: image->Color(params->as_int(4, "color must be int", r)));
1.13 paf 741: }
742:
1.17 paf 743: static void _fill(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 744: Pool& pool=r.pool();
745:
1.76 paf 746: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 747: if(!image)
1.68 paf 748: throw Exception(0,
1.16 paf 749: &method_name,
1.13 paf 750: "does not contain an image");
1.12 paf 751:
1.13 paf 752: image->Fill(
1.51 parser 753: params->as_int(0, "x must be int", r),
754: params->as_int(1, "y must be int", r),
755: image->Color(params->as_int(2, "color must be int", r)));
1.13 paf 756: }
757:
1.17 paf 758: static void _rectangle(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 759: Pool& pool=r.pool();
760:
1.76 paf 761: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 762: if(!image)
1.68 paf 763: throw Exception(0,
1.16 paf 764: &method_name,
1.13 paf 765: "does not contain an image");
766:
767: image->Rectangle(
1.51 parser 768: params->as_int(0, "x0 must be int", r),
769: params->as_int(1, "y0 must be int", r),
770: params->as_int(2, "x1 must be int", r),
771: params->as_int(3, "y1 must be int", r),
772: image->Color(params->as_int(4, "color must be int", r)));
1.13 paf 773: }
774:
1.17 paf 775: static void _bar(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 776: Pool& pool=r.pool();
777:
1.76 paf 778: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 779: if(!image)
1.68 paf 780: throw Exception(0,
1.16 paf 781: &method_name,
1.13 paf 782: "does not contain an image");
783:
784: image->FilledRectangle(
1.51 parser 785: params->as_int(0, "x0 must be int", r),
786: params->as_int(1, "y0 must be int", r),
787: params->as_int(2, "x1 must be int", r),
788: params->as_int(3, "y1 must be int", r),
789: image->Color(params->as_int(4, "color must be int", r)));
1.13 paf 790: }
791:
1.44 parser 792: #ifndef DOXYGEN
793: static void add_point(Array::Item *value, void *info) {
794: Array& row=*static_cast<Array *>(value);
795: gdImage::Point **p=static_cast<gdImage::Point **>(info);
796:
797: (**p).x=row.get_string(0)->as_int();
798: (**p).y=row.get_string(1)->as_int();
799: (*p)++;
800: }
801: #endif
1.17 paf 802: static void _replace(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 803: Pool& pool=r.pool();
804:
1.76 paf 805: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 806: if(!image)
1.68 paf 807: throw Exception(0,
1.16 paf 808: &method_name,
1.13 paf 809: "does not contain an image");
810:
1.44 parser 811: Table *table=params->as_no_junction(2, "coordinates must not be code").get_table();
812: if(!table)
1.68 paf 813: throw Exception(0,
1.44 parser 814: &method_name,
815: "coordinates must be table");
1.13 paf 816:
1.44 parser 817: gdImage::Point *all_p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*table->size());
818: gdImage::Point *add_p=all_p;
819: table->for_each(add_point, &add_p);
820: image->FilledPolygonReplaceColor(all_p, table->size(),
1.51 parser 821: image->Color(params->as_int(0, "src color must be int", r)),
822: image->Color(params->as_int(1, "dest color must be int", r)));
1.13 paf 823: }
824:
1.44 parser 825: static void _polyline(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 826: Pool& pool=r.pool();
827:
1.76 paf 828: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 829: if(!image)
1.68 paf 830: throw Exception(0,
1.16 paf 831: &method_name,
1.13 paf 832: "does not contain an image");
833:
1.44 parser 834: Table *table=params->as_no_junction(1, "coordinates must not be code").get_table();
835: if(!table)
1.68 paf 836: throw Exception(0,
1.44 parser 837: &method_name,
838: "coordinates must be table");
839:
840: gdImage::Point *all_p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*table->size());
841: gdImage::Point *add_p=all_p;
842: table->for_each(add_point, &add_p);
843: image->Polygon(all_p, table->size(),
1.51 parser 844: image->Color(params->as_int(0, "color must be int", r)),
1.44 parser 845: false/*not closed*/);
846: }
847:
848: static void _polygon(Request& r, const String& method_name, MethodParams *params) {
849: Pool& pool=r.pool();
850:
1.76 paf 851: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.44 parser 852: if(!image)
1.68 paf 853: throw Exception(0,
1.16 paf 854: &method_name,
1.44 parser 855: "does not contain an image");
1.13 paf 856:
1.44 parser 857: Table *table=params->as_no_junction(1, "coordinates must not be code").get_table();
858: if(!table)
1.68 paf 859: throw Exception(0,
1.44 parser 860: &method_name,
861: "coordinates must be table");
862:
863: gdImage::Point *all_p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*table->size());
864: gdImage::Point *add_p=all_p;
865: table->for_each(add_point, &add_p);
866: image->Polygon(all_p, table->size(),
1.51 parser 867: image->Color(params->as_int(0, "color must be int", r)));
1.13 paf 868: }
869:
1.17 paf 870: static void _polybar(Request& r, const String& method_name, MethodParams *params) {
1.13 paf 871: Pool& pool=r.pool();
872:
1.76 paf 873: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.13 paf 874: if(!image)
1.68 paf 875: throw Exception(0,
1.16 paf 876: &method_name,
1.13 paf 877: "does not contain an image");
878:
1.44 parser 879: Table *table=params->as_no_junction(1, "coordinates must not be code").get_table();
880: if(!table)
1.68 paf 881: throw Exception("parser.runtime",
1.44 parser 882: &method_name,
883: "coordinates must be table");
1.13 paf 884:
1.44 parser 885: gdImage::Point *all_p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*table->size());
886: gdImage::Point *add_p=all_p;
887: table->for_each(add_point, &add_p);
888: image->FilledPolygon(all_p, table->size(),
1.51 parser 889: image->Color(params->as_int(0, "color must be int", r)));
1.12 paf 890: }
891:
1.16 paf 892: // font
893:
894: #define Y(y)(y+index*height+1)
1.21 paf 895:
896: /// simple gdImage-based font storage & text output
1.16 paf 897: class Font : public Pooled {
898: public:
899:
1.38 parser 900: const static int letter_spacing;
1.35 parser 901: int height; ///< Font heigth
902: int monospace; ///< Default char width
903: int spacebarspace; ///< spacebar width
1.16 paf 904: gdImage& ifont;
905: const String& alphabet;
906:
907: Font(Pool& pool,
908: const String& aalphabet,
1.35 parser 909: gdImage& aifont, int aheight, int amonospace, int aspacebarspace) : Pooled(pool),
1.16 paf 910: alphabet(aalphabet),
1.35 parser 911: height(aheight), monospace(amonospace), spacebarspace(aspacebarspace),
1.16 paf 912: ifont(aifont) {
913: }
914:
915: /* ******************************** char ********************************** */
916:
917: int index_of(char ch) {
918: if(ch==' ') return -1;
919: return alphabet.pos(&ch, 1);
920: }
921:
922: int index_width(int index) {
923: if(index<0)
1.35 parser 924: return spacebarspace;
1.16 paf 925: int tr=ifont.GetTransparent();
1.35 parser 926: for(int x=ifont.SX()-1; x>=0; x--) {
1.16 paf 927: for(int y=0; y<height-1; y++)
928: if(ifont.GetPixel(x, Y(y))!=tr)
1.35 parser 929: return x+1;
1.16 paf 930: }
931: return 0;
932: }
933:
934: void index_display(gdImage& image, int x, int y, int index){
935: if(index>=0)
936: ifont.Copy(image, x, y, 0, Y(0), index_width(index), height-1);
937: }
938:
939: /* ******************************** string ********************************** */
1.47 parser 940:
941: int string_width(const String& s){
1.61 paf 942: const char *cstr=s.cstr();
1.16 paf 943: int result=0;
944: for(; *cstr; cstr++)
945: result+=index_width(index_of(*cstr));
946: return result;
947: }
948:
949: void string_display(gdImage& image, int x, int y, const String& s){
1.61 paf 950: const char *cstr=s.cstr();
1.16 paf 951: if(cstr) for(; *cstr; cstr++) {
952: int index=index_of(*cstr);
953: index_display(image, x, y, index);
1.38 parser 954: x+=letter_spacing + (monospace ? monospace : index_width(index));
1.16 paf 955: }
956: }
957:
958: };
1.38 parser 959: const int Font::letter_spacing=1;
1.35 parser 960:
1.17 paf 961: static void _font(Request& r, const String& method_name, MethodParams *params) {
1.16 paf 962: Pool& pool=r.pool();
963:
1.37 parser 964: const String& alphabet=params->as_string(0, "alphabet must not be code");
965: gdImage& image=*load(r, method_name, params->as_string(1, "file_name must not be code"));
1.51 parser 966: int spacebar_width=params->as_int(2, "spacebar_width must be int", r);
1.37 parser 967: int monospace_width;
968: if(params->size()>3) {
1.51 parser 969: monospace_width=params->as_int(3, "monospace_width must be int", r);
1.37 parser 970: if(!monospace_width)
971: monospace_width=image.SX();
972: } else
973: monospace_width=0;
1.16 paf 974:
1.37 parser 975: if(!alphabet.size())
1.68 paf 976: throw Exception("parser.runtime",
1.37 parser 977: &method_name,
978: "alphabet must not be empty");
1.84 ! paf 979:
! 980: if(int remainder=image.SY() % alphabet.size())
! 981: throw Exception("parser.runtime",
! 982: &method_name,
! 983: "font-file height(%d) not divisable by alphabet size(%d), remainder=%d",
! 984: image.SY(), alphabet.size(), remainder);
1.37 parser 985:
1.76 paf 986: static_cast<VImage *>(r.get_self())->font=new(pool) Font(pool,
1.37 parser 987: alphabet,
1.36 parser 988: image,
1.37 parser 989: image.SY() / alphabet.size(), monospace_width, spacebar_width);
1.16 paf 990: }
991:
1.17 paf 992: static void _text(Request& r, const String& method_name, MethodParams *params) {
1.16 paf 993: Pool& pool=r.pool();
994:
1.51 parser 995: int x=params->as_int(0, "x must be int", r);
996: int y=params->as_int(1, "y must be int", r);
1.36 parser 997: const String& s=params->as_string(2, "text must not be code");
1.16 paf 998:
1.76 paf 999: VImage& vimage=*static_cast<VImage *>(r.get_self());
1.16 paf 1000: if(vimage.image)
1001: if(vimage.font)
1002: vimage.font->string_display(*vimage.image, x, y, s);
1003: else
1.68 paf 1004: throw Exception("parser.runtime",
1.16 paf 1005: &method_name,
1006: "set the font first");
1007: else
1.68 paf 1008: throw Exception(0,
1.16 paf 1009: &method_name,
1010: "does not contain an image");
1011: }
1012:
1.47 parser 1013: static void _length(Request& r, const String& method_name, MethodParams *params) {
1014: Pool& pool=r.pool();
1015:
1016: const String& s=params->as_string(0, "text must not be code");
1017:
1.76 paf 1018: VImage& vimage=*static_cast<VImage *>(r.get_self());
1.47 parser 1019: if(vimage.image)
1020: if(vimage.font) {
1.71 paf 1021: r.write_no_lang(*new(pool) VInt(pool, vimage.font->string_width(s)));
1.47 parser 1022: } else
1.68 paf 1023: throw Exception("parser.runtime",
1.47 parser 1024: &method_name,
1025: "set the font first");
1026: else
1.68 paf 1027: throw Exception(0,
1.47 parser 1028: &method_name,
1029: "does not contain an image");
1030: }
1031:
1.48 parser 1032: static void _arc(Request& r, const String& method_name, MethodParams *params) {
1033: Pool& pool=r.pool();
1034:
1.76 paf 1035: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.48 parser 1036: if(!image)
1.68 paf 1037: throw Exception(0,
1.48 parser 1038: &method_name,
1039: "does not contain an image");
1040:
1041: image->Arc(
1.51 parser 1042: params->as_int(0, "center_x must be int", r),
1043: params->as_int(1, "center_y must be int", r),
1044: params->as_int(2, "width must be int", r),
1045: params->as_int(3, "height must be int", r),
1046: params->as_int(4, "start degrees must be int", r),
1047: params->as_int(5, "end degrees must be int", r),
1048: image->Color(params->as_int(6, "cx must be int", r)));
1.48 parser 1049: }
1050:
1.49 parser 1051: static void _sector(Request& r, const String& method_name, MethodParams *params) {
1052: Pool& pool=r.pool();
1053:
1.76 paf 1054: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.49 parser 1055: if(!image)
1.68 paf 1056: throw Exception(0,
1.49 parser 1057: &method_name,
1058: "does not contain an image");
1059:
1060: image->Sector(
1.51 parser 1061: params->as_int(0, "center_x must be int", r),
1062: params->as_int(1, "center_y must be int", r),
1063: params->as_int(2, "width must be int", r),
1064: params->as_int(3, "height must be int", r),
1065: params->as_int(4, "start degrees must be int", r),
1066: params->as_int(5, "end degrees must be int", r),
1067: image->Color(params->as_int(6, "color must be int", r)));
1.49 parser 1068: }
1069:
1.48 parser 1070: static void _circle(Request& r, const String& method_name, MethodParams *params) {
1071: Pool& pool=r.pool();
1072:
1.76 paf 1073: gdImage *image=static_cast<VImage *>(r.get_self())->image;
1.48 parser 1074: if(!image)
1.68 paf 1075: throw Exception(0,
1.48 parser 1076: &method_name,
1077: "does not contain an image");
1078:
1.51 parser 1079: int size=params->as_int(2, "radius must be int", r)*2;
1.48 parser 1080: image->Arc(
1.51 parser 1081: params->as_int(0, "center_x must be int", r),
1082: params->as_int(1, "center_y must be int", r),
1.50 parser 1083: size, //w
1084: size, //h
1.48 parser 1085: 0, //s
1086: 360, //e
1.51 parser 1087: image->Color(params->as_int(3, "color must be int", r)));
1.48 parser 1088: }
1089:
1.53 parser 1090: gdImage& as_image(Pool& pool, const String& method_name, MethodParams *params,
1091: int index, const char *msg) {
1.75 paf 1092: gdImage *src=0;
1093:
1.53 parser 1094: Value& value=params->as_no_junction(index, msg);
1095:
1.75 paf 1096: if(Value *vimage=value.as(VIMAGE_TYPE, false)) {
1097: src=static_cast<VImage *>(vimage)->image;
1098: if(!src)
1099: throw Exception("parser.runtime",
1100: &method_name,
1101: msg);
1102: } else
1.68 paf 1103: throw Exception("parser.runtime",
1.53 parser 1104: &method_name,
1105: msg);
1106:
1107: return *src;
1108: }
1109:
1110: static void _copy(Request& r, const String& method_name, MethodParams *params) {
1111: Pool& pool=r.pool();
1112:
1.76 paf 1113: gdImage *dest=static_cast<VImage *>(r.get_self())->image;
1.53 parser 1114: if(!dest)
1.68 paf 1115: throw Exception(0,
1.53 parser 1116: &method_name,
1117: "self does not contain an image");
1118:
1119: gdImage& src=as_image(pool, method_name, params, 0, "src must be image");
1120:
1121: int sx=params->as_int(1, "src_x must be int", r);
1122: int sy=params->as_int(2, "src_y must be int", r);
1123: int sw=params->as_int(3, "src_w must be int", r);
1124: int sh=params->as_int(4, "src_h must be int", r);
1125: int dx=params->as_int(5, "dest_x must be int", r);
1126: int dy=params->as_int(6, "dest_y must be int", r);
1127: if(params->size()>1+2+2+2) {
1128: int dw=params->as_int(1+2+2+2, "dest_w must be int", r);
1.56 parser 1129: int dh=(int)(params->size()>1+2+2+2+1?
1130: params->as_int(1+2+2+2+1, "dest_h must be int", r):sh*(((double)dw)/((double)sw)));
1131: int tolerance=params->size()>1+2+2+2+2?
1132: params->as_int(1+2+2+2+2, "tolerance must be int", r):150;
1.53 parser 1133:
1.56 parser 1134: src.CopyResampled(*dest, dx, dy, sx, sy, dw, dh, sw, sh, tolerance);
1.53 parser 1135: } else
1.54 parser 1136: src.Copy(*dest, dx, dy, sx, sy, sw, sh);
1.53 parser 1137: }
1138:
1139:
1.22 paf 1140: // constructor
1141:
1.71 paf 1142: MImage::MImage(Pool& apool) : Methoded(apool, "image") {
1.1 paf 1143: // ^image:measure[DATA]
1.22 paf 1144: add_native_method("measure", Method::CT_DYNAMIC, _measure, 1, 1);
1.3 paf 1145:
1.25 paf 1146: // ^image.html[]
1147: // ^image.html[hash]
1.22 paf 1148: add_native_method("html", Method::CT_DYNAMIC, _html, 0, 1);
1.6 paf 1149:
1.25 paf 1150: // ^image.load[background.gif]
1.22 paf 1151: add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1);
1.6 paf 1152:
1.25 paf 1153: // ^image.create[width;height] bgcolor=white
1154: // ^image.create[width;height;bgcolor]
1.22 paf 1155: add_native_method("create", Method::CT_DYNAMIC, _create, 2, 3);
1.6 paf 1156:
1.25 paf 1157: // ^image.gif[]
1.22 paf 1158: add_native_method("gif", Method::CT_DYNAMIC, _gif, 0, 0);
1.12 paf 1159:
1.25 paf 1160: // ^image.line(x0;y0;x1;y1;color)
1.22 paf 1161: add_native_method("line", Method::CT_DYNAMIC, _line, 5, 5);
1.13 paf 1162:
1.25 paf 1163: // ^image.fill(x;y;color)
1.22 paf 1164: add_native_method("fill", Method::CT_DYNAMIC, _fill, 3, 3);
1.13 paf 1165:
1.25 paf 1166: // ^image.rectangle(x0;y0;x1;y1;color)
1.22 paf 1167: add_native_method("rectangle", Method::CT_DYNAMIC, _rectangle, 5, 5);
1.13 paf 1168:
1.25 paf 1169: // ^image.bar(x0;y0;x1;y1;color)
1.22 paf 1170: add_native_method("bar", Method::CT_DYNAMIC, _bar, 5, 5);
1.13 paf 1171:
1.44 parser 1172: // ^image.replace(color-source;color-dest)[table x:y]
1173: add_native_method("replace", Method::CT_DYNAMIC, _replace, 3, 3);
1174:
1175: // ^image.polyline(color)[table x:y]
1176: add_native_method("polyline", Method::CT_DYNAMIC, _polyline, 2, 2);
1.13 paf 1177:
1.44 parser 1178: // ^image.polygon(color)[table x:y]
1179: add_native_method("polygon", Method::CT_DYNAMIC, _polygon, 2, 2);
1.13 paf 1180:
1.44 parser 1181: // ^image.polybar(color)[table x:y]
1182: add_native_method("polybar", Method::CT_DYNAMIC, _polybar, 2, 2);
1.13 paf 1183:
1.36 parser 1184: // ^image.font[alPHAbet;font-file-name.gif](spacebar_width)
1185: // ^image.font[alPHAbet;font-file-name.gif](spacebar_width;width)
1186: add_native_method("font", Method::CT_DYNAMIC, _font, 3, 4);
1.16 paf 1187:
1.25 paf 1188: // ^image.text(x;y)[text]
1.22 paf 1189: add_native_method("text", Method::CT_DYNAMIC, _text, 3, 3);
1.47 parser 1190:
1191: // ^image.ngth[text]
1192: add_native_method("length", Method::CT_DYNAMIC, _length, 1, 1);
1.16 paf 1193:
1.48 parser 1194: // ^image.arc(center x;center y;width;height;start in degrees;end in degrees;color)
1195: add_native_method("arc", Method::CT_DYNAMIC, _arc, 7, 7);
1.49 parser 1196:
1197: // ^image.sector(center x;center y;width;height;start in degrees;end in degrees;color)
1198: add_native_method("sector", Method::CT_DYNAMIC, _sector, 7, 7);
1.48 parser 1199:
1200: // ^image.circle(center x;center y;r;color)
1201: add_native_method("circle", Method::CT_DYNAMIC, _circle, 4, 4);
1202:
1.56 parser 1203: // ^image.copy[source](src x;src y;src w;src h;dst x;dst y[;dest w[;dest h[;tolerance]]])
1204: add_native_method("copy", Method::CT_DYNAMIC, _copy, 1+2+2+2, (1+2+2+2)+2+1);
1.22 paf 1205: }
1206:
1207: // global variable
1208:
1209: Methoded *image_class;
1210:
1211: // creator
1212:
1213: Methoded *MImage_create(Pool& pool) {
1214: return image_class=new(pool) MImage(pool);
1.1 paf 1215: }
E-mail: