1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <string.h>
5 #include <errno.h>
6 #include "pcd.h"
7
8 #include "readers.h"
9
10 extern int pcd_res;
11
12 /* ---------------------------------------------------------------------- */
13 /* load */
14
15 struct pcd_state {
16 struct PCD_IMAGE img;
17 int left,top,width,height;
18 };
19
20 static void*
pcd_init(FILE * fp,char * filename,unsigned int page,struct ida_image_info * i,int thumbnail)21 pcd_init(FILE *fp, char *filename, unsigned int page,
22 struct ida_image_info *i, int thumbnail)
23 {
24 struct pcd_state *h;
25
26 fclose(fp);
27 h = malloc(sizeof(*h));
28 memset(h,0,sizeof(*h));
29
30 if (0 != pcd_open(&h->img, filename))
31 goto oops;
32 if (-1 == pcd_select(&h->img, thumbnail ? 1 : pcd_res,
33 0,0,0, pcd_get_rot(&h->img, 0),
34 &h->left, &h->top, &h->width, &h->height))
35 goto oops;
36 if (-1 == pcd_decode(&h->img))
37 goto oops;
38
39 i->width = h->width;
40 i->height = h->height;
41 i->npages = 1;
42 return h;
43
44 oops:
45 free(h);
46 return NULL;
47 }
48
49 static void
pcd_read(unsigned char * dst,unsigned int line,void * data)50 pcd_read(unsigned char *dst, unsigned int line, void *data)
51 {
52 struct pcd_state *h = data;
53
54 pcd_get_image_line(&h->img, line, dst, PCD_TYPE_RGB, 0);
55 }
56
57 static void
pcd_done(void * data)58 pcd_done(void *data)
59 {
60 struct pcd_state *h = data;
61
62 pcd_close(&h->img);
63 free(h);
64 }
65
66 static struct ida_loader pcd_loader = {
67 magic: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
68 moff: 0,
69 mlen: 16,
70 name: "libpcd",
71 init: pcd_init,
72 read: pcd_read,
73 done: pcd_done,
74 };
75
init_rd(void)76 static void __init init_rd(void)
77 {
78 load_register(&pcd_loader);
79 }
80