moved from ../swf
[swftools.git] / lib / readers / image.c
1 #include "../gfxdevice.h"
2 #include "../gfxsource.h"
3 #include "../gfxtools.h"
4 #include "../log.h"
5 #include "../mem.h"
6 #include "../rfxswf.h"
7 #include "image.h"
8
9 typedef struct _image_page_internal
10 {
11 } image_page_internal_t;
12
13 typedef struct _image_doc_internal
14 {
15 } image_doc_internal_t;
16
17 void imagepage_destroy(gfxpage_t*image_page)
18 {
19     image_page_internal_t*i= (image_page_internal_t*)image_page->internal;
20     free(image_page->internal);image_page->internal = 0;
21     free(image_page);image_page=0;
22 }
23
24 void imagepage_render(gfxpage_t*page, gfxdevice_t*output)
25 {
26     image_page_internal_t*i = (image_page_internal_t*)page->internal;
27     image_doc_internal_t*pi = (image_doc_internal_t*)page->parent->internal;
28 }
29
30 void imagepage_rendersection(gfxpage_t*page, gfxdevice_t*output, gfxcoord_t x, gfxcoord_t y, gfxcoord_t _x1, gfxcoord_t _y1, gfxcoord_t _x2, gfxcoord_t _y2)
31 {
32     image_doc_internal_t*pi = (image_doc_internal_t*)page->parent->internal;
33 }
34
35 void image_doc_destroy(gfxdocument_t*gfx)
36 {
37     image_doc_internal_t*i= (image_doc_internal_t*)gfx->internal;
38     // ...
39     free(gfx->internal);gfx->internal=0;
40     free(gfx);gfx=0;
41 }
42
43 void image_doc_set_parameter(gfxdocument_t*gfx, char*name, char*value)
44 {
45     image_doc_internal_t*i= (image_doc_internal_t*)gfx->internal;
46 }
47
48 gfxpage_t* image_doc_getpage(gfxdocument_t*doc, int page)
49 {
50     image_doc_internal_t*di= (image_doc_internal_t*)doc->internal;
51     if(page != 1)
52         return 0;
53     
54     gfxpage_t* image_page = (gfxpage_t*)malloc(sizeof(gfxpage_t));
55     image_page_internal_t*pi= (image_page_internal_t*)malloc(sizeof(image_page_internal_t));
56     memset(pi, 0, sizeof(image_page_internal_t));
57
58     image_page->internal = pi;
59     image_page->destroy = imagepage_destroy;
60     image_page->render = imagepage_render;
61     image_page->rendersection = imagepage_rendersection;
62     image_page->width = di->width;
63     image_page->height = di->height;
64     image_page->parent = doc;
65     image_page->nr = page;
66     return image_page;
67 }
68
69 static void image_set_parameter(gfxsource_t*src, char*name, char*value)
70 {
71     msg("<verbose> (gfxsource_image) setting parameter %s to \"%s\"", name, value);
72 }
73
74 static gfxdocument_t*image_open(gfxsource_t*src, char*filename)
75 {
76     gfxdocument_t*image_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t));
77     memset(image_doc, 0, sizeof(gfxdocument_t));
78     image_doc_internal_t*i= (image_doc_internal_t*)malloc(sizeof(image_doc_internal_t));
79     memset(i, 0, sizeof(image_doc_internal_t));
80
81     gfxcolor_t*data = 0;
82     int width = 0;
83     int height = 0;
84
85     if(!getPNG(filename, &width, &height, &data)) {
86     }
87
88     image_doc->num_pages = i->image.frameCount;
89     image_doc->internal = i;
90     image_doc->get = 0;
91     image_doc->destroy = image_doc_destroy;
92     image_doc->set_parameter = image_doc_set_parameter;
93     image_doc->getpage = image_doc_getpage;
94
95     return image_doc;
96 }
97
98 gfxsource_t*gfxsource_image_create()
99 {
100     gfxsource_t*src = (gfxsource_t*)malloc(sizeof(gfxsource_t));
101     memset(src, 0, sizeof(gfxsource_t));
102     src->set_parameter = image_set_parameter;
103     src->open = image_open;
104     return src;
105 }