1 |
vapier 09/08/23 00:33:54 |
2 |
|
3 |
Added: Makefile Makefile.in exifautotran exifautotran.1 |
4 |
jpegexiforient.1 jpegexiforient.c |
5 |
Log: |
6 |
rewrite extra makefile to use build env of parent jpeg configure |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 src/patchsets/jpeg/7/extra/Makefile |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/Makefile?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/Makefile?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: Makefile |
15 |
=================================================================== |
16 |
all %: |
17 |
../config.status --file=Makefile:Makefile.in |
18 |
$(MAKE) $@ |
19 |
|
20 |
|
21 |
|
22 |
1.1 src/patchsets/jpeg/7/extra/Makefile.in |
23 |
|
24 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/Makefile.in?rev=1.1&view=markup |
25 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/Makefile.in?rev=1.1&content-type=text/plain |
26 |
|
27 |
Index: Makefile.in |
28 |
=================================================================== |
29 |
CC = @CC@ |
30 |
EXEEXT = @EXEEXT@ |
31 |
CFLAGS = @CFLAGS@ |
32 |
CPPFLAGS = @CPPFLAGS@ |
33 |
LDFLAGS = @LDFLAGS@ |
34 |
|
35 |
prefix = @prefix@ |
36 |
exec_prefix = @exec_prefix@ |
37 |
bindir = @bindir@ |
38 |
datarootdir = @datarootdir@ |
39 |
mandir = @mandir@ |
40 |
man1dir = $(mandir)/man1 |
41 |
|
42 |
MKDIR_P = @MKDIR_P@ |
43 |
INSTALL = @INSTALL@ |
44 |
INSTALL_DATA = @INSTALL_DATA@ |
45 |
INSTALL_PROGRAM = @INSTALL_PROGRAM@ |
46 |
INSTALL_SCRIPT = @INSTALL_SCRIPT@ |
47 |
|
48 |
SCRIPTS = exifautotran |
49 |
PROGRAMS = jpegexiforient$(EXEEXT) |
50 |
|
51 |
all: $(SCRIPTS) $(PROGRAMS) |
52 |
|
53 |
jpegexiforient$(EXEEXT): jpegexiforient.c |
54 |
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $< |
55 |
|
56 |
clean: |
57 |
rm -f $(PROGRAMS) *.o |
58 |
|
59 |
install: all |
60 |
$(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) |
61 |
$(INSTALL_PROGRAM) $(PROGRAMS) $(DESTDIR)$(bindir) |
62 |
$(INSTALL_SCRIPT) $(SCRIPTS) $(DESTDIR)$(bindir) |
63 |
$(INSTALL_DATA) *.1 $(DESTDIR)$(man1dir) |
64 |
|
65 |
.PHONY: all clean install |
66 |
|
67 |
|
68 |
|
69 |
1.1 src/patchsets/jpeg/7/extra/exifautotran |
70 |
|
71 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/exifautotran?rev=1.1&view=markup |
72 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/exifautotran?rev=1.1&content-type=text/plain |
73 |
|
74 |
Index: exifautotran |
75 |
=================================================================== |
76 |
#!/bin/sh |
77 |
# exifautotran [list of files] |
78 |
# |
79 |
# Transforms Exif files so that Orientation becomes 1 |
80 |
# |
81 |
for i |
82 |
do |
83 |
case $i in |
84 |
-v|--version) echo "exifautotran"; exit 0;; |
85 |
-h|--help) |
86 |
cat <<EOF |
87 |
exifautotran [list of files] |
88 |
|
89 |
Transforms Exif files so that Orientation becomes 1 |
90 |
EOF |
91 |
exit 0;; |
92 |
esac |
93 |
|
94 |
case `jpegexiforient -n "$i"` in |
95 |
1) transform="";; |
96 |
2) transform="-flip horizontal";; |
97 |
3) transform="-rotate 180";; |
98 |
4) transform="-flip vertical";; |
99 |
5) transform="-transpose";; |
100 |
6) transform="-rotate 90";; |
101 |
7) transform="-transverse";; |
102 |
8) transform="-rotate 270";; |
103 |
*) transform="";; |
104 |
esac |
105 |
if test -n "$transform"; then |
106 |
echo Executing: jpegtran -copy all $transform $i >&2 |
107 |
if type mktemp >/dev/null 2>&1; then |
108 |
tempfile=`mktemp` |
109 |
else |
110 |
set -C |
111 |
tempfile=${TMPDIR-/tmp}/exifautotran.$$ |
112 |
fi |
113 |
if test $? -ne 0; then |
114 |
echo Error while creating temp file for $i - skipped. >&2 |
115 |
continue |
116 |
fi |
117 |
jpegtran -copy all $transform "$i" > "$tempfile" |
118 |
if test $? -ne 0; then |
119 |
echo Error while transforming $i - skipped. >&2 |
120 |
else |
121 |
if mv "$tempfile" "$i"; then |
122 |
jpegexiforient -1 "$i" > /dev/null |
123 |
fi |
124 |
fi |
125 |
fi |
126 |
done |
127 |
|
128 |
|
129 |
|
130 |
1.1 src/patchsets/jpeg/7/extra/exifautotran.1 |
131 |
|
132 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/exifautotran.1?rev=1.1&view=markup |
133 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/exifautotran.1?rev=1.1&content-type=text/plain |
134 |
|
135 |
Index: exifautotran.1 |
136 |
=================================================================== |
137 |
.TH EXIFAUTOTRAN "1" "February 2005" "exifautotran" "User Commands" |
138 |
.SH NAME |
139 |
exifautotran \- Transforms Exif files so that Orientation becomes 1 |
140 |
.SH DESCRIPTION |
141 |
exifautotran [list of files] |
142 |
.PP |
143 |
Take a list of files as input and transform then in place so that the |
144 |
Orientation becomes 1. |
145 |
.SH "AUTHOR" |
146 |
Guido Vollbeding <guido@××××××××.org> |
147 |
.SH "SEE ALSO" |
148 |
.BR jpegtran (1), |
149 |
.BR jpegexiforient (1) |
150 |
|
151 |
|
152 |
|
153 |
1.1 src/patchsets/jpeg/7/extra/jpegexiforient.1 |
154 |
|
155 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/jpegexiforient.1?rev=1.1&view=markup |
156 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/jpegexiforient.1?rev=1.1&content-type=text/plain |
157 |
|
158 |
Index: jpegexiforient.1 |
159 |
=================================================================== |
160 |
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.35. |
161 |
.TH JPEGEXIFORIENT "1" "February 2005" "jpegexiforient" "User Commands" |
162 |
.SH NAME |
163 |
jpegexiforient \- reads or writes the Exif Orientation Tag |
164 |
.SH SYNOPSIS |
165 |
.B jpegexiforient |
166 |
[\fIswitches\fR] \fIjpegfile\fR |
167 |
.SH DESCRIPTION |
168 |
|
169 |
This is a utility program to get and set the Exif Orientation Tag. |
170 |
It can be used together with jpegtran in scripts for automatic |
171 |
orientation correction of digital camera pictures. |
172 |
|
173 |
The Exif orientation value gives the orientation of the camera |
174 |
relative to the scene when the image was captured. The relation |
175 |
of the '0th row' and '0th column' to visual position is shown as |
176 |
below. |
177 |
|
178 |
Value | 0th Row | 0th Column |
179 |
------+-------------+----------- |
180 |
1 | top | left side |
181 |
2 | top | rigth side |
182 |
3 | bottom | rigth side |
183 |
4 | bottom | left side |
184 |
5 | left side | top |
185 |
6 | right side | top |
186 |
7 | right side | bottom |
187 |
8 | left side | bottom |
188 |
|
189 |
For convenience, here is what the letter F would look like if it were |
190 |
tagged correctly and displayed by a program that ignores the orientation |
191 |
tag: |
192 |
|
193 |
1 2 3 4 |
194 |
|
195 |
888888 888888 88 88 |
196 |
88 88 88 88 |
197 |
8888 8888 8888 8888 |
198 |
88 88 88 88 |
199 |
88 88 888888 888888 |
200 |
|
201 |
5 6 7 8 |
202 |
|
203 |
8888888888 88 88 8888888888 |
204 |
88 88 88 88 88 88 88 88 |
205 |
88 8888888888 8888888888 88 |
206 |
|
207 |
jpegexiforient output the Exif Orientation Tag in a JPEG Exif file. |
208 |
With the options -1 .. -8, it can also be used to set the tag. |
209 |
|
210 |
.SS "OPTIONS" |
211 |
.TP |
212 |
\fB\-\-help\fR |
213 |
display this help and exit |
214 |
.TP |
215 |
\fB\-\-version\fR |
216 |
output version information and exit |
217 |
.TP |
218 |
\fB\-n\fR |
219 |
Do not output the trailing newline |
220 |
.TP |
221 |
\fB\-1\fR .. \fB\-8\fR |
222 |
Set orientation value 1 .. 8 |
223 |
.SH "AUTHOR" |
224 |
Guido Vollbeding <guido@××××××××.org> |
225 |
.SH "SEE ALSO" |
226 |
.BR jpegtran (1), |
227 |
.BR exifautotran (1) |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
1.1 src/patchsets/jpeg/7/extra/jpegexiforient.c |
233 |
|
234 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/jpegexiforient.c?rev=1.1&view=markup |
235 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/jpeg/7/extra/jpegexiforient.c?rev=1.1&content-type=text/plain |
236 |
|
237 |
Index: jpegexiforient.c |
238 |
=================================================================== |
239 |
/* |
240 |
* jpegexiforient.c |
241 |
* |
242 |
* This is a utility program to get and set the Exif Orientation Tag. |
243 |
* It can be used together with jpegtran in scripts for automatic |
244 |
* orientation correction of digital camera pictures. |
245 |
* |
246 |
* The Exif orientation value gives the orientation of the camera |
247 |
* relative to the scene when the image was captured. The relation |
248 |
* of the '0th row' and '0th column' to visual position is shown as |
249 |
* below. |
250 |
* |
251 |
* Value | 0th Row | 0th Column |
252 |
* ------+-------------+----------- |
253 |
* 1 | top | left side |
254 |
* 2 | top | rigth side |
255 |
* 3 | bottom | rigth side |
256 |
* 4 | bottom | left side |
257 |
* 5 | left side | top |
258 |
* 6 | right side | top |
259 |
* 7 | right side | bottom |
260 |
* 8 | left side | bottom |
261 |
* |
262 |
* For convenience, here is what the letter F would look like if it were |
263 |
* tagged correctly and displayed by a program that ignores the orientation |
264 |
* tag: |
265 |
* |
266 |
* 1 2 3 4 5 6 7 8 |
267 |
* |
268 |
* 888888 888888 88 88 8888888888 88 88 8888888888 |
269 |
* 88 88 88 88 88 88 88 88 88 88 88 88 |
270 |
* 8888 8888 8888 8888 88 8888888888 8888888888 88 |
271 |
* 88 88 88 88 |
272 |
* 88 88 888888 888888 |
273 |
* |
274 |
*/ |
275 |
|
276 |
#include <stdio.h> |
277 |
#include <stdlib.h> |
278 |
|
279 |
static FILE * myfile; /* My JPEG file */ |
280 |
|
281 |
static unsigned char exif_data[65536L]; |
282 |
|
283 |
/* Return next input byte, or EOF if no more */ |
284 |
#define NEXTBYTE() getc(myfile) |
285 |
|
286 |
/* Error exit handler */ |
287 |
#define ERREXIT(msg) (exit(0)) |
288 |
|
289 |
/* Read one byte, testing for EOF */ |
290 |
static int |
291 |
read_1_byte (void) |
292 |
{ |
293 |
int c; |
294 |
|
295 |
c = NEXTBYTE(); |
296 |
if (c == EOF) |
297 |
ERREXIT("Premature EOF in JPEG file"); |
298 |
return c; |
299 |
} |
300 |
|
301 |
/* Read 2 bytes, convert to unsigned int */ |
302 |
/* All 2-byte quantities in JPEG markers are MSB first */ |
303 |
static unsigned int |
304 |
read_2_bytes (void) |
305 |
{ |
306 |
int c1, c2; |
307 |
|
308 |
c1 = NEXTBYTE(); |
309 |
if (c1 == EOF) |
310 |
ERREXIT("Premature EOF in JPEG file"); |
311 |
c2 = NEXTBYTE(); |
312 |
if (c2 == EOF) |
313 |
ERREXIT("Premature EOF in JPEG file"); |
314 |
return (((unsigned int) c1) << 8) + ((unsigned int) c2); |
315 |
} |
316 |
|
317 |
static const char * progname; /* program name for error messages */ |
318 |
|
319 |
static void |
320 |
usage (FILE *out) |
321 |
/* complain about bad command line */ |
322 |
{ |
323 |
fprintf(out, "jpegexiforient reads or writes the Exif Orientation Tag "); |
324 |
fprintf(out, "in a JPEG Exif file.\n"); |
325 |
|
326 |
fprintf(out, "Usage: %s [switches] jpegfile\n", progname); |
327 |
|
328 |
fprintf(out, "Switches:\n"); |
329 |
fprintf(out, " --help display this help and exit\n"); |
330 |
fprintf(out, " --version output version information and exit\n"); |
331 |
fprintf(out, " -n Do not output the trailing newline\n"); |
332 |
fprintf(out, " -1 .. -8 Set orientation value 1 .. 8\n"); |
333 |
} |
334 |
|
335 |
/* |
336 |
* The main program. |
337 |
*/ |
338 |
|
339 |
int |
340 |
main (int argc, char **argv) |
341 |
{ |
342 |
int n_flag, set_flag; |
343 |
unsigned int length, i; |
344 |
int is_motorola; /* Flag for byte order */ |
345 |
unsigned int offset, number_of_tags, tagnum; |
346 |
|
347 |
progname = argv[0]; |
348 |
if (progname == NULL || progname[0] == 0) |
349 |
progname = "jpegexiforient"; /* in case C library doesn't provide it */ |
350 |
|
351 |
if (argc < 2) { usage(stderr); return 1; } |
352 |
|
353 |
n_flag = 0; set_flag = 0; |
354 |
|
355 |
i = 1; |
356 |
while (argv[i][0] == '-') { |
357 |
switch (argv[i][1]) { |
358 |
case '-': |
359 |
switch (argv[i][2]) { |
360 |
case 'h': usage(stdout); return 0; |
361 |
case 'v': fprintf(stdout,"jpegexiforient\n"); return 0; |
362 |
} |
363 |
case 'n': |
364 |
n_flag = 1; |
365 |
break; |
366 |
case '1': |
367 |
case '2': |
368 |
case '3': |
369 |
case '4': |
370 |
case '5': |
371 |
case '6': |
372 |
case '7': |
373 |
case '8': |
374 |
set_flag = argv[i][1] - '0'; |
375 |
break; |
376 |
default: |
377 |
usage(stderr); return 1; |
378 |
} |
379 |
if (++i >= argc) { usage(stderr); return 1; } |
380 |
} |
381 |
|
382 |
if (set_flag) { |
383 |
if ((myfile = fopen(argv[i], "rb+")) == NULL) { |
384 |
fprintf(stderr, "%s: can't open %s\n", progname, argv[i]); |
385 |
return 0; |
386 |
} |
387 |
} else { |
388 |
if ((myfile = fopen(argv[i], "rb")) == NULL) { |
389 |
fprintf(stderr, "%s: can't open %s\n", progname, argv[i]); |
390 |
return 0; |
391 |
} |
392 |
} |
393 |
|
394 |
/* Read File head, check for JPEG SOI + Exif APP1 */ |
395 |
for (i = 0; i < 4; i++) |
396 |
exif_data[i] = (unsigned char) read_1_byte(); |
397 |
if (exif_data[0] != 0xFF || |
398 |
exif_data[1] != 0xD8 || |
399 |
exif_data[2] != 0xFF || |
400 |
exif_data[3] != 0xE1) |
401 |
return 0; |
402 |
|
403 |
/* Get the marker parameter length count */ |
404 |
length = read_2_bytes(); |
405 |
/* Length includes itself, so must be at least 2 */ |
406 |
/* Following Exif data length must be at least 6 */ |
407 |
if (length < 8) |
408 |
return 0; |
409 |
length -= 8; |
410 |
/* Read Exif head, check for "Exif" */ |
411 |
for (i = 0; i < 6; i++) |
412 |
exif_data[i] = (unsigned char) read_1_byte(); |
413 |
if (exif_data[0] != 0x45 || |
414 |
exif_data[1] != 0x78 || |
415 |
exif_data[2] != 0x69 || |
416 |
exif_data[3] != 0x66 || |
417 |
exif_data[4] != 0 || |
418 |
exif_data[5] != 0) |
419 |
return 0; |
420 |
/* Read Exif body */ |
421 |
for (i = 0; i < length; i++) |
422 |
exif_data[i] = (unsigned char) read_1_byte(); |
423 |
|
424 |
if (length < 12) return 0; /* Length of an IFD entry */ |
425 |
|
426 |
/* Discover byte order */ |
427 |
if (exif_data[0] == 0x49 && exif_data[1] == 0x49) |
428 |
is_motorola = 0; |
429 |
else if (exif_data[0] == 0x4D && exif_data[1] == 0x4D) |
430 |
is_motorola = 1; |
431 |
else |
432 |
return 0; |
433 |
|
434 |
/* Check Tag Mark */ |
435 |
if (is_motorola) { |
436 |
if (exif_data[2] != 0) return 0; |
437 |
if (exif_data[3] != 0x2A) return 0; |
438 |
} else { |
439 |
if (exif_data[3] != 0) return 0; |
440 |
if (exif_data[2] != 0x2A) return 0; |
441 |
} |
442 |
|
443 |
/* Get first IFD offset (offset to IFD0) */ |
444 |
if (is_motorola) { |
445 |
if (exif_data[4] != 0) return 0; |
446 |
if (exif_data[5] != 0) return 0; |
447 |
offset = exif_data[6]; |
448 |
offset <<= 8; |
449 |
offset += exif_data[7]; |
450 |
} else { |
451 |
if (exif_data[7] != 0) return 0; |
452 |
if (exif_data[6] != 0) return 0; |
453 |
offset = exif_data[5]; |
454 |
offset <<= 8; |
455 |
offset += exif_data[4]; |
456 |
} |
457 |
if (offset > length - 2) return 0; /* check end of data segment */ |
458 |
|
459 |
/* Get the number of directory entries contained in this IFD */ |
460 |
if (is_motorola) { |
461 |
number_of_tags = exif_data[offset]; |
462 |
number_of_tags <<= 8; |
463 |
number_of_tags += exif_data[offset+1]; |
464 |
} else { |
465 |
number_of_tags = exif_data[offset+1]; |
466 |
number_of_tags <<= 8; |
467 |
number_of_tags += exif_data[offset]; |
468 |
} |
469 |
if (number_of_tags == 0) return 0; |
470 |
offset += 2; |
471 |
|
472 |
/* Search for Orientation Tag in IFD0 */ |
473 |
for (;;) { |
474 |
if (offset > length - 12) return 0; /* check end of data segment */ |
475 |
/* Get Tag number */ |
476 |
if (is_motorola) { |
477 |
tagnum = exif_data[offset]; |
478 |
tagnum <<= 8; |
479 |
tagnum += exif_data[offset+1]; |
480 |
} else { |
481 |
tagnum = exif_data[offset+1]; |
482 |
tagnum <<= 8; |
483 |
tagnum += exif_data[offset]; |
484 |
} |
485 |
if (tagnum == 0x0112) break; /* found Orientation Tag */ |
486 |
if (--number_of_tags == 0) return 0; |
487 |
offset += 12; |
488 |
} |
489 |
|
490 |
if (set_flag) { |
491 |
/* Set the Orientation value */ |
492 |
if (is_motorola) { |
493 |
exif_data[offset+2] = 0; /* Format = unsigned short (2 octets) */ |
494 |
exif_data[offset+3] = 3; |
495 |
exif_data[offset+4] = 0; /* Number Of Components = 1 */ |
496 |
exif_data[offset+5] = 0; |
497 |
exif_data[offset+6] = 0; |
498 |
exif_data[offset+7] = 1; |
499 |
exif_data[offset+8] = 0; |
500 |
exif_data[offset+9] = (unsigned char)set_flag; |
501 |
exif_data[offset+10] = 0; |
502 |
exif_data[offset+11] = 0; |
503 |
} else { |
504 |
exif_data[offset+2] = 3; /* Format = unsigned short (2 octets) */ |
505 |
exif_data[offset+3] = 0; |
506 |
exif_data[offset+4] = 1; /* Number Of Components = 1 */ |
507 |
exif_data[offset+5] = 0; |
508 |
exif_data[offset+6] = 0; |
509 |
exif_data[offset+7] = 0; |
510 |
exif_data[offset+8] = (unsigned char)set_flag; |
511 |
exif_data[offset+9] = 0; |
512 |
exif_data[offset+10] = 0; |
513 |
exif_data[offset+11] = 0; |
514 |
} |
515 |
fseek(myfile, (4 + 2 + 6 + 2) + offset, SEEK_SET); |
516 |
fwrite(exif_data + 2 + offset, 1, 10, myfile); |
517 |
} else { |
518 |
/* Get the Orientation value */ |
519 |
if (is_motorola) { |
520 |
if (exif_data[offset+8] != 0) return 0; |
521 |
set_flag = exif_data[offset+9]; |
522 |
} else { |
523 |
if (exif_data[offset+9] != 0) return 0; |
524 |
set_flag = exif_data[offset+8]; |
525 |
} |
526 |
if (set_flag > 8) return 0; |
527 |
} |
528 |
|
529 |
/* Write out Orientation value */ |
530 |
if (n_flag) |
531 |
printf("%c", '0' + set_flag); |
532 |
else |
533 |
printf("%c\n", '0' + set_flag); |
534 |
|
535 |
/* All done. */ |
536 |
return 0; |
537 |
} |