1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include "list.h"
#include "ida.h"
#include "readers.h"
#include "filebutton.h"
#include "fileops.h"
#include <jpeglib.h>
#include "transupp.h" /* Support routines for jpegtran */
#include "jpegtools.h"
/*----------------------------------------------------------------------*/
struct jobqueue {
struct list_head list;
char *op;
char *filename;
char *args;
};
static LIST_HEAD(jobs);
static XtWorkProcId jobproc;
/*----------------------------------------------------------------------*/
static Boolean job_worker(XtPointer clientdata)
{
struct jobqueue *job;
unsigned int flags =
JFLAG_TRANSFORM_IMAGE |
JFLAG_TRANSFORM_THUMBNAIL |
JFLAG_TRANSFORM_TRIM |
JFLAG_UPDATE_ORIENTATION;
if (list_empty(&jobs)) {
/* nothing to do */
jobproc = 0;
return TRUE;
}
job = list_entry(jobs.next, struct jobqueue, list);
/* process job */
if (debug)
fprintf(stderr,"job worker: %s %s\n",job->op,job->filename);
ptr_busy();
if (0 == strcmp(job->op,"rotexif")) {
jpeg_transform_inplace(job->filename, -1/*auto*/,
NULL, NULL, 0, flags);
} else if (0 == strcmp(job->op,"rotcw")) {
jpeg_transform_inplace(job->filename, JXFORM_ROT_90,
NULL, NULL, 0, flags);
} else if (0 == strcmp(job->op,"rotccw")) {
jpeg_transform_inplace(job->filename, JXFORM_ROT_270,
NULL, NULL, 0, flags);
} else if (0 == strcmp(job->op,"comment")) {
jpeg_transform_inplace(job->filename, JXFORM_NONE, job->args,
NULL, 0,
JFLAG_UPDATE_COMMENT);
} else {
fprintf(stderr,"job: \"%s\" is *unknown*\n",job->op);
}
ptr_idle();
fileinfo_invalidate(job->filename);
/* cleanup */
list_del(&job->list);
free(job->filename);
free(job->op);
if (job->args)
free(job->args);
free(job);
return FALSE;
}
/*----------------------------------------------------------------------*/
void job_submit(char *op, char *filename, char *args)
{
struct jobqueue *job;
job = malloc(sizeof(*job));
memset(job,0,sizeof(*job));
job->op = strdup(op);
job->filename = strdup(filename);
if (args)
job->args = strdup(args);
list_add_tail(&job->list,&jobs);
if (debug)
fprintf(stderr,"job submit: %s %s\n",job->op,job->filename);
if (0 == jobproc)
jobproc = XtAppAddWorkProc(app_context,job_worker,NULL);
}
|