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