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(i->img.data);i->img.data = 0;
86 free(gfx->internal);gfx->internal=0;
90 void image_doc_setparameter(gfxdocument_t*gfx, const char*name, const char*value)
92 image_doc_internal_t*i= (image_doc_internal_t*)gfx->internal;
95 gfxpage_t* image_doc_getpage(gfxdocument_t*doc, int page)
97 image_doc_internal_t*di= (image_doc_internal_t*)doc->internal;
101 gfxpage_t* image_page = (gfxpage_t*)malloc(sizeof(gfxpage_t));
102 image_page_internal_t*pi= (image_page_internal_t*)malloc(sizeof(image_page_internal_t));
103 memset(pi, 0, sizeof(image_page_internal_t));
105 image_page->internal = pi;
106 image_page->destroy = imagepage_destroy;
107 image_page->render = imagepage_render;
108 image_page->rendersection = imagepage_rendersection;
109 image_page->width = di->img.width;
110 image_page->height = di->img.height;
111 image_page->parent = doc;
112 image_page->nr = page;
116 static void image_setparameter(gfxsource_t*src, const char*name, const char*value)
118 msg("<verbose> (gfxsource_image) setting parameter %s to \"%s\"", name, value);
121 static gfxdocument_t*image_open(gfxsource_t*src, const char*filename)
123 gfxdocument_t*image_doc = (gfxdocument_t*)malloc(sizeof(gfxdocument_t));
124 memset(image_doc, 0, sizeof(gfxdocument_t));
125 image_doc_internal_t*i= (image_doc_internal_t*)malloc(sizeof(image_doc_internal_t));
126 memset(i, 0, sizeof(image_doc_internal_t));
132 if(!png_load(filename, &width, &height, (unsigned char**)&data)) {
133 if(!jpeg_load(filename, (unsigned char**)&data, &width, &height)) {
134 msg("<error> Couldn't load image %s", filename);
139 i->img.width = width;
140 i->img.height = height;
142 image_doc->num_pages = 1;
143 image_doc->internal = i;
145 image_doc->destroy = image_doc_destroy;
146 image_doc->setparameter = image_doc_setparameter;
147 image_doc->getpage = image_doc_getpage;
152 gfxsource_t*gfxsource_image_create()
154 gfxsource_t*src = (gfxsource_t*)malloc(sizeof(gfxsource_t));
155 memset(src, 0, sizeof(gfxsource_t));
156 src->setparameter = image_setparameter;
157 src->open = image_open;