4 #include "../gfxdevice.h"
5 #include "../gfxsource.h"
6 #include "../gfxtools.h"
13 typedef struct _image_page_internal
15 } image_page_internal_t;
17 typedef struct _image_doc_internal
20 } image_doc_internal_t;
22 void imagepage_destroy(gfxpage_t*image_page)
24 image_page_internal_t*i= (image_page_internal_t*)image_page->internal;
25 free(image_page->internal);image_page->internal = 0;
26 free(image_page);image_page=0;
29 void imagepage_render(gfxpage_t*page, gfxdevice_t*output)
31 image_page_internal_t*i = (image_page_internal_t*)page->internal;
32 image_doc_internal_t*pi = (image_doc_internal_t*)page->parent->internal;
35 memset(&cxform, 0, sizeof(cxform));
42 memset(&m, 0, sizeof(m));
46 gfxline_t* rect = gfxline_makerectangle(0, 0, pi->img.width, pi->img.height);
47 output->fillbitmap(output, rect, &pi->img, &m, &cxform);
51 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)
53 image_page_internal_t*i = (image_page_internal_t*)page->internal;
54 image_doc_internal_t*pi = (image_doc_internal_t*)page->parent->internal;
57 memset(&cxform, 0, sizeof(cxform));
64 memset(&m, 0, sizeof(m));
70 gfxline_t* rect = gfxline_makerectangle(0, 0, pi->img.width, pi->img.height);
71 gfxline_t* rect2 = gfxline_makerectangle(_x1, _y1, _x2, _y2);
73 output->startclip(output, rect2);
74 output->fillbitmap(output, rect, &pi->img, &m, &cxform);
75 output->endclip(output);
80 void image_doc_destroy(gfxdocument_t*gfx)
82 image_doc_internal_t*i= (image_doc_internal_t*)gfx->internal;
84 free(gfx->internal);gfx->internal=0;
88 void image_doc_set_parameter(gfxdocument_t*gfx, const char*name, const char*value)
90 image_doc_internal_t*i= (image_doc_internal_t*)gfx->internal;
93 gfxpage_t* image_doc_getpage(gfxdocument_t*doc, int page)
95 image_doc_internal_t*di= (image_doc_internal_t*)doc->internal;
99 gfxpage_t* image_page = (gfxpage_t*)malloc(sizeof(gfxpage_t));
100 image_page_internal_t*pi= (image_page_internal_t*)malloc(sizeof(image_page_internal_t));
101 memset(pi, 0, sizeof(image_page_internal_t));
103 image_page->internal = pi;
104 image_page->destroy = imagepage_destroy;
105 image_page->render = imagepage_render;
106 image_page->rendersection = imagepage_rendersection;
107 image_page->width = di->img.width;
108 image_page->height = di->img.height;
109 image_page->parent = doc;
110 image_page->nr = page;
114 static void image_set_parameter(gfxsource_t*src, const char*name, const char*value)
116 msg("<verbose> (gfxsource_image) setting parameter %s to \"%s\"", name, value);
119 static gfxdocument_t*image_open(gfxsource_t*src, const char*filename)
121 gfxdocument_t*image_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t));
122 memset(image_doc, 0, sizeof(gfxdocument_t));
123 image_doc_internal_t*i= (image_doc_internal_t*)malloc(sizeof(image_doc_internal_t));
124 memset(i, 0, sizeof(image_doc_internal_t));
130 if(!getPNG(filename, &width, &height, (unsigned char**)&data)) {
131 if(!jpeg_load(filename, (unsigned char**)&data, &width, &height)) {
132 msg("<error> Couldn't load image %s", filename);
137 i->img.width = width;
138 i->img.height = height;
140 image_doc->num_pages = 1;
141 image_doc->internal = i;
143 image_doc->destroy = image_doc_destroy;
144 image_doc->set_parameter = image_doc_set_parameter;
145 image_doc->getpage = image_doc_getpage;
150 gfxsource_t*gfxsource_image_create()
152 gfxsource_t*src = (gfxsource_t*)malloc(sizeof(gfxsource_t));
153 memset(src, 0, sizeof(gfxsource_t));
154 src->set_parameter = image_set_parameter;
155 src->open = image_open;