7
#include <libspectre/spectre.h>
14
#define DATA32 unsigned int
19
#define D(fmt, args...) fprintf(stderr, fmt, ## args)
21
#define D(fmt, args...)
25
static SpectreDocument *psdoc;
28
static SpectrePage *page;
32
static void *data = NULL;
33
static double dpi = -1.0;
38
_spectre_init(const char *file, int page_nbr, int size_w, int size_h)
42
SpectreOrientation rot;
54
psdoc = spectre_document_new();
58
spectre_document_load(psdoc, file);
59
status = spectre_document_status (psdoc);
60
if (status != SPECTRE_STATUS_SUCCESS)
62
D("[ps] %s\n", spectre_status_to_string(status));
66
page_count = spectre_document_get_n_pages(psdoc);
67
status = spectre_document_status(psdoc);
68
if (status != SPECTRE_STATUS_SUCCESS)
70
D("[eps] %s\n", spectre_status_to_string (status));
74
if (page_nbr >= page_count)
79
page = spectre_document_get_page(psdoc, page_nbr);
80
status = spectre_document_status(psdoc);
81
if (status != SPECTRE_STATUS_SUCCESS)
83
D("[eps] %s\n", spectre_status_to_string (status));
87
spectre_page_get_size(page, &ww, &hh);
90
rot = spectre_page_get_orientation(page);
92
if ((rot == SPECTRE_ORIENTATION_LANDSCAPE) || (rot == SPECTRE_ORIENTATION_REVERSE_LANDSCAPE))
99
if ((size_w > 0) || (size_h > 0))
101
double w2 = w, h2 = h;
104
h2 = (size_w * h) / w;
108
w2 = (size_h * w) / h;
110
D("XXXXXXXXXXXXXXXXXXXXx %3.3fx%3.3f\n", w2, h2);
111
if (w2 > h2) dpi = (w2 * DEF_DPI) / w;
112
else dpi = (h2 * DEF_DPI) / h;
117
w = (w * dpi) / DEF_DPI;
118
h = (h * dpi) / DEF_DPI;
126
spectre_page_free(page);
128
spectre_document_free(psdoc);
138
spectre_page_free(page);
139
spectre_document_free(psdoc);
144
_pixcopy(DATA32 *dst, unsigned char *src, int size)
147
unsigned char *s, *e;
165
_spectre_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED)
167
SpectreRenderContext *rc;
168
unsigned char *psdata;
173
SpectreStatus status;
175
rc = spectre_render_context_new();
179
spectre_page_render(page, rc, &psdata, &stride);
180
spectre_render_context_set_page_size (rc, width, height);
181
status = spectre_page_status(page);
182
if (status != SPECTRE_STATUS_SUCCESS)
184
D("[eps] %s\n", spectre_status_to_string (status));
188
shm_alloc(width * height * sizeof(DATA32));
189
if (!shm_addr) return;
192
if (stride == 4 * width)
193
_pixcopy(data, psdata, height * stride);
197
dst = (DATA32 *)data;
198
for (yy = 0; yy < height; src += stride, dst += width, ++yy)
199
_pixcopy (dst, src, width * 4);
202
spectre_render_context_free(rc);
206
main(int argc, char **argv)
210
int size_w = 0, size_h = 0;
214
if (argc < 2) return -1;
217
for (i = 2; i < argc; i++)
219
if (!strcmp(argv[i], "-head"))
222
else if (!strcmp(argv[i], "-key"))
225
page_nbr = atoi(argv[i]);
228
else if (!strcmp(argv[i], "-opt-scale-down-by"))
233
else if (!strcmp(argv[i], "-opt-dpi"))
236
dpi = ((double)atoi(argv[i])) / 1000.0;
239
else if (!strcmp(argv[i], "-opt-size"))
242
size_w = atoi(argv[i]);
244
size_h = atoi(argv[i]);
248
D("_spectre_init_file\n");
249
D("dpi....: %f\n", dpi);
250
D("page...: %d\n", page_nbr);
254
if (!_spectre_init(file, page_nbr, size_w, size_h))
256
D("_spectre_init done\n");
258
D("dpi2...: %f\n", dpi);
261
_spectre_load_image(size_w, size_h);
264
D("size...: %ix%i\n", width, height);
267
printf("size %i %i\n", width, height);
273
if (shm_fd) printf("shmfile %s\n", shmfile);
275
if (shm_fd >= 0) printf("shmfile %s\n", shmfile);
282
if (fwrite(data, width * height * sizeof(DATA32), 1, stdout) != 1)
286
D("fwrite failed (%llu bytes): %m\n",
287
(unsigned long long)(width * height * sizeof(DATA32)));