-rw-r--r-- | noncore/graphics/opie-eye/slave/jpeg_slave.cpp | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/noncore/graphics/opie-eye/slave/jpeg_slave.cpp b/noncore/graphics/opie-eye/slave/jpeg_slave.cpp index fb7d5de..1bb81d9 100644 --- a/noncore/graphics/opie-eye/slave/jpeg_slave.cpp +++ b/noncore/graphics/opie-eye/slave/jpeg_slave.cpp | |||
@@ -1,64 +1,64 @@ | |||
1 | #include "jpeg_slave.h" | 1 | #include "jpeg_slave.h" |
2 | #include "thumbnailtool.h" | 2 | #include "thumbnailtool.h" |
3 | 3 | ||
4 | PHUNK_VIEW_INTERFACE( "JPEG", JpegSlave ) | 4 | PHUNK_VIEW_INTERFACE( "JPEG", JpegSlave ) |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | #include <qpe/timestring.h> | 8 | #include <qpe/timestring.h> |
9 | using namespace Opie::Core; | 9 | using namespace Opie::Core; |
10 | 10 | ||
11 | /* QT */ | 11 | /* QT */ |
12 | #include <qobject.h> | 12 | #include <qobject.h> |
13 | #include <qimage.h> | 13 | #include <qimage.h> |
14 | 14 | ||
15 | /** | 15 | /** |
16 | exif.h | 16 | exif.h |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <stdio.h> | 19 | #include <stdio.h> |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <math.h> | 21 | #include <math.h> |
22 | #include <time.h> | 22 | #include <time.h> |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qimage.h> | 26 | #include <qimage.h> |
27 | 27 | ||
28 | typedef enum { | 28 | typedef enum { |
29 | READ_EXIF = 1, | 29 | READ_EXIF = 1, |
30 | READ_IMAGE = 2, | 30 | READ_IMAGE = 2, |
31 | READ_ALL = 3 | 31 | READ_ALL = 3 |
32 | }ReadMode_t; | 32 | }ReadMode_t; |
33 | 33 | ||
34 | //-------------------------------------------------------------------------- | 34 | //-------------------------------------------------------------------------- |
35 | // This structure is used to store jpeg file sections in memory. | 35 | // This structure is used to store jpeg file sections in memory. |
36 | typedef struct { | 36 | typedef struct { |
37 | uchar * Data; | 37 | uchar * Data; |
38 | int Type; | 38 | int Type; |
39 | unsigned Size; | 39 | unsigned Size; |
40 | }Section_t; | 40 | }Section_t; |
41 | 41 | ||
42 | typedef unsigned char uchar; | 42 | typedef unsigned char uchar; |
43 | 43 | ||
44 | typedef struct { | 44 | typedef struct { |
45 | unsigned short Tag; | 45 | unsigned short Tag; |
46 | const char*const Desc; | 46 | const char*const Desc; |
47 | }TagTable_t; | 47 | }TagTable_t; |
48 | 48 | ||
49 | #define MAX_SECTIONS 20 | 49 | #define MAX_SECTIONS 20 |
50 | #define PSEUDO_IMAGE_MARKER 0x123; // Extra value. | 50 | #define PSEUDO_IMAGE_MARKER 0x123; // Extra value. |
51 | 51 | ||
52 | class ExifData { | 52 | class ExifData { |
53 | Section_t Sections[MAX_SECTIONS]; | 53 | Section_t Sections[MAX_SECTIONS]; |
54 | 54 | ||
55 | QString CameraMake; | 55 | QString CameraMake; |
56 | QString CameraModel; | 56 | QString CameraModel; |
57 | QString DateTime; | 57 | QString DateTime; |
58 | int Orientation; | 58 | int Orientation; |
59 | int Height, Width; | 59 | int Height, Width; |
60 | int ExifImageLength, ExifImageWidth; | 60 | int ExifImageLength, ExifImageWidth; |
61 | int IsColor; | 61 | int IsColor; |
62 | int Process; | 62 | int Process; |
63 | int FlashUsed; | 63 | int FlashUsed; |
64 | float FocalLength; | 64 | float FocalLength; |
@@ -221,169 +221,169 @@ static int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; | |||
221 | #define TAG_SUBJECT_DISTANCE 0x9206 | 221 | #define TAG_SUBJECT_DISTANCE 0x9206 |
222 | #define TAG_FLASH 0x9209 | 222 | #define TAG_FLASH 0x9209 |
223 | 223 | ||
224 | #define TAG_FOCALPLANEXRES 0xa20E | 224 | #define TAG_FOCALPLANEXRES 0xa20E |
225 | #define TAG_FOCALPLANEUNITS 0xa210 | 225 | #define TAG_FOCALPLANEUNITS 0xa210 |
226 | #define TAG_EXIF_IMAGEWIDTH 0xA002 | 226 | #define TAG_EXIF_IMAGEWIDTH 0xA002 |
227 | #define TAG_EXIF_IMAGELENGTH 0xA003 | 227 | #define TAG_EXIF_IMAGELENGTH 0xA003 |
228 | 228 | ||
229 | // the following is added 05-jan-2001 vcs | 229 | // the following is added 05-jan-2001 vcs |
230 | #define TAG_EXPOSURE_BIAS 0x9204 | 230 | #define TAG_EXPOSURE_BIAS 0x9204 |
231 | #define TAG_WHITEBALANCE 0x9208 | 231 | #define TAG_WHITEBALANCE 0x9208 |
232 | #define TAG_METERING_MODE 0x9207 | 232 | #define TAG_METERING_MODE 0x9207 |
233 | #define TAG_EXPOSURE_PROGRAM 0x8822 | 233 | #define TAG_EXPOSURE_PROGRAM 0x8822 |
234 | #define TAG_ISO_EQUIVALENT 0x8827 | 234 | #define TAG_ISO_EQUIVALENT 0x8827 |
235 | #define TAG_COMPRESSION_LEVEL 0x9102 | 235 | #define TAG_COMPRESSION_LEVEL 0x9102 |
236 | 236 | ||
237 | #define TAG_THUMBNAIL_OFFSET 0x0201 | 237 | #define TAG_THUMBNAIL_OFFSET 0x0201 |
238 | #define TAG_THUMBNAIL_LENGTH 0x0202 | 238 | #define TAG_THUMBNAIL_LENGTH 0x0202 |
239 | 239 | ||
240 | 240 | ||
241 | 241 | ||
242 | 242 | ||
243 | //-------------------------------------------------------------------------- | 243 | //-------------------------------------------------------------------------- |
244 | // Parse the marker stream until SOS or EOI is seen; | 244 | // Parse the marker stream until SOS or EOI is seen; |
245 | //-------------------------------------------------------------------------- | 245 | //-------------------------------------------------------------------------- |
246 | int ExifData::ReadJpegSections (QFile & infile, ReadMode_t ReadMode) | 246 | int ExifData::ReadJpegSections (QFile & infile, ReadMode_t ReadMode) |
247 | { | 247 | { |
248 | int a; | 248 | int a; |
249 | 249 | ||
250 | a = infile.getch(); | 250 | a = infile.getch(); |
251 | 251 | ||
252 | if (a != 0xff || infile.getch() != M_SOI) { | 252 | if (a != 0xff || infile.getch() != M_SOI) { |
253 | SectionsRead = 0; | 253 | SectionsRead = 0; |
254 | return false; | 254 | return false; |
255 | } | 255 | } |
256 | for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ){ | 256 | for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ){ |
257 | int marker = 0; | 257 | int marker = 0; |
258 | int got; | 258 | int got; |
259 | unsigned int ll,lh; | 259 | unsigned int ll,lh; |
260 | unsigned int itemlen; | 260 | unsigned int itemlen; |
261 | uchar * Data; | 261 | uchar * Data; |
262 | 262 | ||
263 | for (a=0;a<7;a++){ | 263 | for (a=0;a<7;a++){ |
264 | marker = infile.getch(); | 264 | marker = infile.getch(); |
265 | if (marker != 0xff) break; | 265 | if (marker != 0xff) break; |
266 | 266 | ||
267 | if (a >= 6){ | 267 | if (a >= 6){ |
268 | 268 | ||
269 | owarn << "too many padding bytes" << oendl; | 269 | owarn << "too many padding bytes" << oendl; |
270 | return false; | 270 | return false; |
271 | 271 | ||
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
275 | if (marker == 0xff){ | 275 | if (marker == 0xff){ |
276 | // 0xff is legal padding, but if we get that many, something's wrong. | 276 | // 0xff is legal padding, but if we get that many, something's wrong. |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | 279 | ||
280 | Sections[SectionsRead].Type = marker; | 280 | Sections[SectionsRead].Type = marker; |
281 | 281 | ||
282 | // Read the length of the section. | 282 | // Read the length of the section. |
283 | lh = (uchar) infile.getch(); | 283 | lh = (uchar) infile.getch(); |
284 | ll = (uchar) infile.getch(); | 284 | ll = (uchar) infile.getch(); |
285 | 285 | ||
286 | itemlen = (lh << 8) | ll; | 286 | itemlen = (lh << 8) | ll; |
287 | 287 | ||
288 | if (itemlen < 2) { | 288 | if (itemlen < 2) { |
289 | return false;; | 289 | return false;; |
290 | } | 290 | } |
291 | 291 | ||
292 | Sections[SectionsRead].Size = itemlen; | 292 | Sections[SectionsRead].Size = itemlen; |
293 | 293 | ||
294 | Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end. | 294 | Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end. |
295 | Sections[SectionsRead].Data = Data; | 295 | Sections[SectionsRead].Data = Data; |
296 | 296 | ||
297 | // Store first two pre-read bytes. | 297 | // Store first two pre-read bytes. |
298 | Data[0] = (uchar)lh; | 298 | Data[0] = (uchar)lh; |
299 | Data[1] = (uchar)ll; | 299 | Data[1] = (uchar)ll; |
300 | 300 | ||
301 | got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section. | 301 | got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section. |
302 | if (( unsigned ) got != itemlen-2){ | 302 | if (( unsigned ) got != itemlen-2){ |
303 | return false; | 303 | return false; |
304 | } | 304 | } |
305 | SectionsRead++; | 305 | SectionsRead++; |
306 | 306 | ||
307 | switch(marker){ | 307 | switch(marker){ |
308 | 308 | ||
309 | case M_SOS: // stop before hitting compressed data | 309 | case M_SOS: // stop before hitting compressed data |
310 | // If reading entire image is requested, read the rest of the data. | 310 | // If reading entire image is requested, read the rest of the data. |
311 | if (ReadMode & READ_IMAGE){ | 311 | if (ReadMode & READ_IMAGE){ |
312 | unsigned long size; | 312 | unsigned long size; |
313 | 313 | ||
314 | size = QMAX( 0ul, infile.size()-infile.at() ); | 314 | size = QMAX( 0ul, infile.size()-infile.at() ); |
315 | Data = (uchar *)malloc(size); | 315 | Data = (uchar *)malloc(size); |
316 | if (Data == NULL){ | 316 | if (Data == NULL){ |
317 | return false; | 317 | return false; |
318 | } | 318 | } |
319 | 319 | ||
320 | got = infile.readBlock((char*)Data, size); | 320 | got = infile.readBlock((char*)Data, size); |
321 | if (( unsigned ) got != size){ | 321 | if (( unsigned ) got != size){ |
322 | return false; | 322 | return false; |
323 | } | 323 | } |
324 | 324 | ||
325 | Sections[SectionsRead].Data = Data; | 325 | Sections[SectionsRead].Data = Data; |
326 | Sections[SectionsRead].Size = size; | 326 | Sections[SectionsRead].Size = size; |
327 | Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; | 327 | Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; |
328 | SectionsRead ++; | 328 | SectionsRead ++; |
329 | //HaveAll = 1; | 329 | //HaveAll = 1; |
330 | } | 330 | } |
331 | return true; | 331 | return true; |
332 | 332 | ||
333 | case M_EOI: // in case it's a tables-only JPEG stream | 333 | case M_EOI: // in case it's a tables-only JPEG stream |
334 | owarn << "No image in jpeg!" << oendl; | 334 | owarn << "No image in jpeg!" << oendl; |
335 | return false; | 335 | return false; |
336 | 336 | ||
337 | case M_COM: // Comment section | 337 | case M_COM: // Comment section |
338 | // pieczy 2002-02-12 | 338 | // pieczy 2002-02-12 |
339 | // now the User comment goes to UserComment | 339 | // now the User comment goes to UserComment |
340 | // so we can store a Comment section also in READ_EXIF mode | 340 | // so we can store a Comment section also in READ_EXIF mode |
341 | process_COM(Data, itemlen); | 341 | process_COM(Data, itemlen); |
342 | break; | 342 | break; |
343 | 343 | ||
344 | case M_JFIF: | 344 | case M_JFIF: |
345 | // Regular jpegs always have this tag, exif images have the exif | 345 | // Regular jpegs always have this tag, exif images have the exif |
346 | // marker instead, althogh ACDsee will write images with both markers. | 346 | // marker instead, althogh ACDsee will write images with both markers. |
347 | // this program will re-create this marker on absence of exif marker. | 347 | // this program will re-create this marker on absence of exif marker. |
348 | // hence no need to keep the copy from the file. | 348 | // hence no need to keep the copy from the file. |
349 | free(Sections[--SectionsRead].Data); | 349 | free(Sections[--SectionsRead].Data); |
350 | break; | 350 | break; |
351 | 351 | ||
352 | case M_EXIF: | 352 | case M_EXIF: |
353 | // Seen files from some 'U-lead' software with Vivitar scanner | 353 | // Seen files from some 'U-lead' software with Vivitar scanner |
354 | // that uses marker 31 for non exif stuff. Thus make sure | 354 | // that uses marker 31 for non exif stuff. Thus make sure |
355 | // it says 'Exif' in the section before treating it as exif. | 355 | // it says 'Exif' in the section before treating it as exif. |
356 | if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ | 356 | if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ |
357 | process_EXIF((uchar *)Data, itemlen); | 357 | process_EXIF((uchar *)Data, itemlen); |
358 | }else{ | 358 | }else{ |
359 | // Discard this section. | 359 | // Discard this section. |
360 | free(Sections[--SectionsRead].Data); | 360 | free(Sections[--SectionsRead].Data); |
361 | } | 361 | } |
362 | break; | 362 | break; |
363 | 363 | ||
364 | case M_SOF0: | 364 | case M_SOF0: |
365 | case M_SOF1: | 365 | case M_SOF1: |
366 | case M_SOF2: | 366 | case M_SOF2: |
367 | case M_SOF3: | 367 | case M_SOF3: |
368 | case M_SOF5: | 368 | case M_SOF5: |
369 | case M_SOF6: | 369 | case M_SOF6: |
370 | case M_SOF7: | 370 | case M_SOF7: |
371 | case M_SOF9: | 371 | case M_SOF9: |
372 | case M_SOF10: | 372 | case M_SOF10: |
373 | case M_SOF11: | 373 | case M_SOF11: |
374 | case M_SOF13: | 374 | case M_SOF13: |
375 | case M_SOF14: | 375 | case M_SOF14: |
376 | case M_SOF15: | 376 | case M_SOF15: |
377 | process_SOFn(Data, marker); | 377 | process_SOFn(Data, marker); |
378 | default: | 378 | default: |
379 | break; | 379 | break; |
380 | break; | 380 | break; |
381 | } | 381 | } |
382 | } | 382 | } |
383 | return true; | 383 | return true; |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | //-------------------------------------------------------------------------- | 387 | //-------------------------------------------------------------------------- |
388 | // Discard read data. | 388 | // Discard read data. |
389 | //-------------------------------------------------------------------------- | 389 | //-------------------------------------------------------------------------- |
@@ -502,298 +502,298 @@ void ExifData::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBa | |||
502 | int Tag, Format, Components; | 502 | int Tag, Format, Components; |
503 | unsigned char * ValuePtr; | 503 | unsigned char * ValuePtr; |
504 | int ByteCount; | 504 | int ByteCount; |
505 | char * DirEntry; | 505 | char * DirEntry; |
506 | DirEntry = (char *)DIR_ENTRY_ADDR(DirStart, de); | 506 | DirEntry = (char *)DIR_ENTRY_ADDR(DirStart, de); |
507 | 507 | ||
508 | Tag = Get16u(DirEntry); | 508 | Tag = Get16u(DirEntry); |
509 | Format = Get16u(DirEntry+2); | 509 | Format = Get16u(DirEntry+2); |
510 | Components = Get32u(DirEntry+4); | 510 | Components = Get32u(DirEntry+4); |
511 | 511 | ||
512 | if ((Format-1) >= NUM_FORMATS) { | 512 | if ((Format-1) >= NUM_FORMATS) { |
513 | // (-1) catches illegal zero case as unsigned underflows to positive large. | 513 | // (-1) catches illegal zero case as unsigned underflows to positive large. |
514 | return; | 514 | return; |
515 | } | 515 | } |
516 | 516 | ||
517 | ByteCount = Components * BytesPerFormat[Format]; | 517 | ByteCount = Components * BytesPerFormat[Format]; |
518 | 518 | ||
519 | if (ByteCount > 4){ | 519 | if (ByteCount > 4){ |
520 | unsigned OffsetVal; | 520 | unsigned OffsetVal; |
521 | OffsetVal = Get32u(DirEntry+8); | 521 | OffsetVal = Get32u(DirEntry+8); |
522 | // If its bigger than 4 bytes, the dir entry contains an offset. | 522 | // If its bigger than 4 bytes, the dir entry contains an offset. |
523 | if (OffsetVal+ByteCount > ExifLength){ | 523 | if (OffsetVal+ByteCount > ExifLength){ |
524 | // Bogus pointer offset and / or bytecount value | 524 | // Bogus pointer offset and / or bytecount value |
525 | //printf("Offset %d bytes %d ExifLen %d\n",OffsetVal, ByteCount, ExifLength); | 525 | //printf("Offset %d bytes %d ExifLen %d\n",OffsetVal, ByteCount, ExifLength); |
526 | 526 | ||
527 | return; | 527 | return; |
528 | } | 528 | } |
529 | ValuePtr = OffsetBase+OffsetVal; | 529 | ValuePtr = OffsetBase+OffsetVal; |
530 | }else{ | 530 | }else{ |
531 | // 4 bytes or less and value is in the dir entry itself | 531 | // 4 bytes or less and value is in the dir entry itself |
532 | ValuePtr = (unsigned char *)DirEntry+8; | 532 | ValuePtr = (unsigned char *)DirEntry+8; |
533 | } | 533 | } |
534 | 534 | ||
535 | if (LastExifRefd < ValuePtr+ByteCount){ | 535 | if (LastExifRefd < ValuePtr+ByteCount){ |
536 | // Keep track of last byte in the exif header that was actually referenced. | 536 | // Keep track of last byte in the exif header that was actually referenced. |
537 | // That way, we know where the discardable thumbnail data begins. | 537 | // That way, we know where the discardable thumbnail data begins. |
538 | LastExifRefd = ValuePtr+ByteCount; | 538 | LastExifRefd = ValuePtr+ByteCount; |
539 | } | 539 | } |
540 | 540 | ||
541 | // Extract useful components of tag | 541 | // Extract useful components of tag |
542 | switch(Tag){ | 542 | switch(Tag){ |
543 | 543 | ||
544 | case TAG_MAKE: | 544 | case TAG_MAKE: |
545 | ExifData::CameraMake = QString((char*)ValuePtr); | 545 | ExifData::CameraMake = QString((char*)ValuePtr); |
546 | break; | 546 | break; |
547 | 547 | ||
548 | case TAG_MODEL: | 548 | case TAG_MODEL: |
549 | ExifData::CameraModel = QString((char*)ValuePtr); | 549 | ExifData::CameraModel = QString((char*)ValuePtr); |
550 | break; | 550 | break; |
551 | 551 | ||
552 | case TAG_ORIENTATION: | 552 | case TAG_ORIENTATION: |
553 | Orientation = (int)ConvertAnyFormat(ValuePtr, Format); | 553 | Orientation = (int)ConvertAnyFormat(ValuePtr, Format); |
554 | break; | 554 | break; |
555 | 555 | ||
556 | case TAG_DATETIME_ORIGINAL: | 556 | case TAG_DATETIME_ORIGINAL: |
557 | DateTime = QString((char*)ValuePtr); | 557 | DateTime = QString((char*)ValuePtr); |
558 | break; | 558 | break; |
559 | 559 | ||
560 | case TAG_USERCOMMENT: | 560 | case TAG_USERCOMMENT: |
561 | // Olympus has this padded with trailing spaces. Remove these first. | 561 | // Olympus has this padded with trailing spaces. Remove these first. |
562 | for (a=ByteCount;;){ | 562 | for (a=ByteCount;;){ |
563 | a--; | 563 | a--; |
564 | if ((ValuePtr)[a] == ' '){ | 564 | if ((ValuePtr)[a] == ' '){ |
565 | (ValuePtr)[a] = '\0'; | 565 | (ValuePtr)[a] = '\0'; |
566 | }else{ | 566 | }else{ |
567 | break; | 567 | break; |
568 | } | 568 | } |
569 | if (a == 0) break; | 569 | if (a == 0) break; |
570 | } | 570 | } |
571 | 571 | ||
572 | // Copy the comment | 572 | // Copy the comment |
573 | if (memcmp(ValuePtr, "ASCII",5) == 0){ | 573 | if (memcmp(ValuePtr, "ASCII",5) == 0){ |
574 | for (a=5;a<10;a++){ | 574 | for (a=5;a<10;a++){ |
575 | int c; | 575 | int c; |
576 | c = (ValuePtr)[a]; | 576 | c = (ValuePtr)[a]; |
577 | if (c != '\0' && c != ' '){ | 577 | if (c != '\0' && c != ' '){ |
578 | //strncpy(ImageInfo.Comments, (const char*)(a+ValuePtr), 199); | 578 | //strncpy(ImageInfo.Comments, (const char*)(a+ValuePtr), 199); |
579 | UserComment.sprintf("%s", (const char*)(a+ValuePtr)); | 579 | UserComment.sprintf("%s", (const char*)(a+ValuePtr)); |
580 | break; | 580 | break; |
581 | } | 581 | } |
582 | } | 582 | } |
583 | }else{ | 583 | }else{ |
584 | //strncpy(ImageInfo.Comments, (const char*)ValuePtr, 199); | 584 | //strncpy(ImageInfo.Comments, (const char*)ValuePtr, 199); |
585 | UserComment.sprintf("%s", (const char*)ValuePtr); | 585 | UserComment.sprintf("%s", (const char*)ValuePtr); |
586 | } | 586 | } |
587 | break; | 587 | break; |
588 | 588 | ||
589 | case TAG_FNUMBER: | 589 | case TAG_FNUMBER: |
590 | // Simplest way of expressing aperture, so I trust it the most. | 590 | // Simplest way of expressing aperture, so I trust it the most. |
591 | // (overwrite previously computd value if there is one) | 591 | // (overwrite previously computd value if there is one) |
592 | ExifData::ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); | 592 | ExifData::ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); |
593 | break; | 593 | break; |
594 | 594 | ||
595 | case TAG_APERTURE: | 595 | case TAG_APERTURE: |
596 | case TAG_MAXAPERTURE: | 596 | case TAG_MAXAPERTURE: |
597 | // More relevant info always comes earlier, so only use this field if we don't | 597 | // More relevant info always comes earlier, so only use this field if we don't |
598 | // have appropriate aperture information yet. | 598 | // have appropriate aperture information yet. |
599 | if (ExifData::ApertureFNumber == 0){ | 599 | if (ExifData::ApertureFNumber == 0){ |
600 | ExifData::ApertureFNumber | 600 | ExifData::ApertureFNumber |
601 | = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2)*0.5); | 601 | = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2)*0.5); |
602 | } | 602 | } |
603 | break; | 603 | break; |
604 | 604 | ||
605 | case TAG_FOCALLENGTH: | 605 | case TAG_FOCALLENGTH: |
606 | // Nice digital cameras actually save the focal length as a function | 606 | // Nice digital cameras actually save the focal length as a function |
607 | // of how farthey are zoomed in. | 607 | // of how farthey are zoomed in. |
608 | ExifData::FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); | 608 | ExifData::FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); |
609 | break; | 609 | break; |
610 | 610 | ||
611 | case TAG_SUBJECT_DISTANCE: | 611 | case TAG_SUBJECT_DISTANCE: |
612 | // Inidcates the distacne the autofocus camera is focused to. | 612 | // Inidcates the distacne the autofocus camera is focused to. |
613 | // Tends to be less accurate as distance increases. | 613 | // Tends to be less accurate as distance increases. |
614 | ExifData::Distance = (float)ConvertAnyFormat(ValuePtr, Format); | 614 | ExifData::Distance = (float)ConvertAnyFormat(ValuePtr, Format); |
615 | break; | 615 | break; |
616 | 616 | ||
617 | case TAG_EXPOSURETIME: | 617 | case TAG_EXPOSURETIME: |
618 | // Simplest way of expressing exposure time, so I trust it most. | 618 | // Simplest way of expressing exposure time, so I trust it most. |
619 | // (overwrite previously computd value if there is one) | 619 | // (overwrite previously computd value if there is one) |
620 | ExifData::ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format); | 620 | ExifData::ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format); |
621 | break; | 621 | break; |
622 | 622 | ||
623 | case TAG_SHUTTERSPEED: | 623 | case TAG_SHUTTERSPEED: |
624 | // More complicated way of expressing exposure time, so only use | 624 | // More complicated way of expressing exposure time, so only use |
625 | // this value if we don't already have it from somewhere else. | 625 | // this value if we don't already have it from somewhere else. |
626 | if (ExifData::ExposureTime == 0){ | 626 | if (ExifData::ExposureTime == 0){ |
627 | ExifData::ExposureTime | 627 | ExifData::ExposureTime |
628 | = (float)(1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2))); | 628 | = (float)(1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2))); |
629 | } | 629 | } |
630 | break; | 630 | break; |
631 | 631 | ||
632 | case TAG_FLASH: | 632 | case TAG_FLASH: |
633 | if (ConvertAnyFormat(ValuePtr, Format)){ | 633 | if (ConvertAnyFormat(ValuePtr, Format)){ |
634 | ExifData::FlashUsed = 1; | 634 | ExifData::FlashUsed = 1; |
635 | } | 635 | } |
636 | break; | 636 | break; |
637 | 637 | ||
638 | case TAG_EXIF_IMAGELENGTH: | 638 | case TAG_EXIF_IMAGELENGTH: |
639 | ExifImageLength = (int)ConvertAnyFormat(ValuePtr, Format); | 639 | ExifImageLength = (int)ConvertAnyFormat(ValuePtr, Format); |
640 | break; | 640 | break; |
641 | 641 | ||
642 | case TAG_EXIF_IMAGEWIDTH: | 642 | case TAG_EXIF_IMAGEWIDTH: |
643 | ExifImageWidth = (int)ConvertAnyFormat(ValuePtr, Format); | 643 | ExifImageWidth = (int)ConvertAnyFormat(ValuePtr, Format); |
644 | break; | 644 | break; |
645 | 645 | ||
646 | case TAG_FOCALPLANEXRES: | 646 | case TAG_FOCALPLANEXRES: |
647 | FocalplaneXRes = ConvertAnyFormat(ValuePtr, Format); | 647 | FocalplaneXRes = ConvertAnyFormat(ValuePtr, Format); |
648 | break; | 648 | break; |
649 | 649 | ||
650 | case TAG_FOCALPLANEUNITS: | 650 | case TAG_FOCALPLANEUNITS: |
651 | switch((int)ConvertAnyFormat(ValuePtr, Format)){ | 651 | switch((int)ConvertAnyFormat(ValuePtr, Format)){ |
652 | case 1: FocalplaneUnits = 25.4; break; // inch | 652 | case 1: FocalplaneUnits = 25.4; break; // inch |
653 | case 2: | 653 | case 2: |
654 | // According to the information I was using, 2 means meters. | 654 | // According to the information I was using, 2 means meters. |
655 | // But looking at the Cannon powershot's files, inches is the only | 655 | // But looking at the Cannon powershot's files, inches is the only |
656 | // sensible value. | 656 | // sensible value. |
657 | FocalplaneUnits = 25.4; | 657 | FocalplaneUnits = 25.4; |
658 | break; | 658 | break; |
659 | 659 | ||
660 | case 3: FocalplaneUnits = 10; break; // centimeter | 660 | case 3: FocalplaneUnits = 10; break; // centimeter |
661 | case 4: FocalplaneUnits = 1; break; // milimeter | 661 | case 4: FocalplaneUnits = 1; break; // milimeter |
662 | case 5: FocalplaneUnits = .001; break; // micrometer | 662 | case 5: FocalplaneUnits = .001; break; // micrometer |
663 | } | 663 | } |
664 | break; | 664 | break; |
665 | 665 | ||
666 | // Remaining cases contributed by: Volker C. Schoech (schoech@gmx.de) | 666 | // Remaining cases contributed by: Volker C. Schoech (schoech@gmx.de) |
667 | 667 | ||
668 | case TAG_EXPOSURE_BIAS: | 668 | case TAG_EXPOSURE_BIAS: |
669 | ExifData::ExposureBias = (float)ConvertAnyFormat(ValuePtr, Format); | 669 | ExifData::ExposureBias = (float)ConvertAnyFormat(ValuePtr, Format); |
670 | break; | 670 | break; |
671 | 671 | ||
672 | case TAG_WHITEBALANCE: | 672 | case TAG_WHITEBALANCE: |
673 | ExifData::Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); | 673 | ExifData::Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); |
674 | break; | 674 | break; |
675 | 675 | ||
676 | case TAG_METERING_MODE: | 676 | case TAG_METERING_MODE: |
677 | ExifData::MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); | 677 | ExifData::MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); |
678 | break; | 678 | break; |
679 | 679 | ||
680 | case TAG_EXPOSURE_PROGRAM: | 680 | case TAG_EXPOSURE_PROGRAM: |
681 | ExifData::ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); | 681 | ExifData::ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); |
682 | break; | 682 | break; |
683 | 683 | ||
684 | case TAG_ISO_EQUIVALENT: | 684 | case TAG_ISO_EQUIVALENT: |
685 | ExifData::ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); | 685 | ExifData::ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); |
686 | if ( ExifData::ISOequivalent < 50 ) ExifData::ISOequivalent *= 200; | 686 | if ( ExifData::ISOequivalent < 50 ) ExifData::ISOequivalent *= 200; |
687 | break; | 687 | break; |
688 | 688 | ||
689 | case TAG_COMPRESSION_LEVEL: | 689 | case TAG_COMPRESSION_LEVEL: |
690 | ExifData::CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); | 690 | ExifData::CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); |
691 | break; | 691 | break; |
692 | 692 | ||
693 | case TAG_THUMBNAIL_OFFSET: | 693 | case TAG_THUMBNAIL_OFFSET: |
694 | ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); | 694 | ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); |
695 | break; | 695 | break; |
696 | 696 | ||
697 | case TAG_THUMBNAIL_LENGTH: | 697 | case TAG_THUMBNAIL_LENGTH: |
698 | ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); | 698 | ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); |
699 | break; | 699 | break; |
700 | 700 | ||
701 | } | 701 | } |
702 | 702 | ||
703 | if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ | 703 | if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ |
704 | unsigned char * SubdirStart; | 704 | unsigned char * SubdirStart; |
705 | SubdirStart = OffsetBase + Get32u(ValuePtr); | 705 | SubdirStart = OffsetBase + Get32u(ValuePtr); |
706 | if (SubdirStart < OffsetBase || SubdirStart > OffsetBase+ExifLength){ | 706 | if (SubdirStart < OffsetBase || SubdirStart > OffsetBase+ExifLength){ |
707 | return; | 707 | return; |
708 | } | 708 | } |
709 | ProcessExifDir(SubdirStart, OffsetBase, ExifLength); | 709 | ProcessExifDir(SubdirStart, OffsetBase, ExifLength); |
710 | continue; | 710 | continue; |
711 | } | 711 | } |
712 | } | 712 | } |
713 | 713 | ||
714 | { | 714 | { |
715 | // In addition to linking to subdirectories via exif tags, | 715 | // In addition to linking to subdirectories via exif tags, |
716 | // there's also a potential link to another directory at the end of each | 716 | // there's also a potential link to another directory at the end of each |
717 | // directory. this has got to be the result of a comitee! | 717 | // directory. this has got to be the result of a comitee! |
718 | unsigned char * SubdirStart; | 718 | unsigned char * SubdirStart; |
719 | unsigned Offset; | 719 | unsigned Offset; |
720 | 720 | ||
721 | if (DIR_ENTRY_ADDR(DirStart, NumDirEntries) + 4 <= OffsetBase+ExifLength){ | 721 | if (DIR_ENTRY_ADDR(DirStart, NumDirEntries) + 4 <= OffsetBase+ExifLength){ |
722 | Offset = Get32u(DIR_ENTRY_ADDR(DirStart, NumDirEntries)); | 722 | Offset = Get32u(DIR_ENTRY_ADDR(DirStart, NumDirEntries)); |
723 | // There is at least one jpeg from an HP camera having an Offset of almost MAXUINT. | 723 | // There is at least one jpeg from an HP camera having an Offset of almost MAXUINT. |
724 | // Adding OffsetBase to it produces an overflow, so compare with ExifLength here. | 724 | // Adding OffsetBase to it produces an overflow, so compare with ExifLength here. |
725 | // See http://bugs.kde.org/show_bug.cgi?id=54542 | 725 | // See http://bugs.kde.org/show_bug.cgi?id=54542 |
726 | if (Offset && Offset < ExifLength){ | 726 | if (Offset && Offset < ExifLength){ |
727 | SubdirStart = OffsetBase + Offset; | 727 | SubdirStart = OffsetBase + Offset; |
728 | if (SubdirStart > OffsetBase+ExifLength){ | 728 | if (SubdirStart > OffsetBase+ExifLength){ |
729 | if (SubdirStart < OffsetBase+ExifLength+20){ | 729 | if (SubdirStart < OffsetBase+ExifLength+20){ |
730 | // Jhead 1.3 or earlier would crop the whole directory! | 730 | // Jhead 1.3 or earlier would crop the whole directory! |
731 | // As Jhead produces this form of format incorrectness, | 731 | // As Jhead produces this form of format incorrectness, |
732 | // I'll just let it pass silently | 732 | // I'll just let it pass silently |
733 | owarn << "Thumbnail removed with Jhead 1.3 or earlier" << oendl; | 733 | owarn << "Thumbnail removed with Jhead 1.3 or earlier" << oendl; |
734 | }else{ | 734 | }else{ |
735 | return; | 735 | return; |
736 | } | 736 | } |
737 | }else{ | 737 | }else{ |
738 | if (SubdirStart <= OffsetBase+ExifLength){ | 738 | if (SubdirStart <= OffsetBase+ExifLength){ |
739 | ProcessExifDir(SubdirStart, OffsetBase, ExifLength); | 739 | ProcessExifDir(SubdirStart, OffsetBase, ExifLength); |
740 | } | 740 | } |
741 | } | 741 | } |
742 | } | 742 | } |
743 | }else{ | 743 | }else{ |
744 | // The exif header ends before the last next directory pointer. | 744 | // The exif header ends before the last next directory pointer. |
745 | } | 745 | } |
746 | } | 746 | } |
747 | 747 | ||
748 | if (ThumbnailSize && ThumbnailOffset){ | 748 | if (ThumbnailSize && ThumbnailOffset){ |
749 | if (ThumbnailSize + ThumbnailOffset <= ExifLength){ | 749 | if (ThumbnailSize + ThumbnailOffset <= ExifLength){ |
750 | // The thumbnail pointer appears to be valid. Store it. | 750 | // The thumbnail pointer appears to be valid. Store it. |
751 | Thumbnail.loadFromData(OffsetBase + ThumbnailOffset, ThumbnailSize, "JPEG"); | 751 | Thumbnail.loadFromData(OffsetBase + ThumbnailOffset, ThumbnailSize, "JPEG"); |
752 | } | 752 | } |
753 | } | 753 | } |
754 | } | 754 | } |
755 | 755 | ||
756 | //-------------------------------------------------------------------------- | 756 | //-------------------------------------------------------------------------- |
757 | // Process a COM marker. We want to leave the bytes unchanged. The | 757 | // Process a COM marker. We want to leave the bytes unchanged. The |
758 | // progam that displays this text may decide to remove blanks, convert | 758 | // progam that displays this text may decide to remove blanks, convert |
759 | // newlines, or otherwise modify the text. In particular we want to be | 759 | // newlines, or otherwise modify the text. In particular we want to be |
760 | // safe for passing utf-8 text. | 760 | // safe for passing utf-8 text. |
761 | //-------------------------------------------------------------------------- | 761 | //-------------------------------------------------------------------------- |
762 | void ExifData::process_COM (const uchar * Data, int length) | 762 | void ExifData::process_COM (const uchar * Data, int length) |
763 | { | 763 | { |
764 | QChar ch; | 764 | QChar ch; |
765 | int a; | 765 | int a; |
766 | 766 | ||
767 | for (a=2;a<length;a++){ | 767 | for (a=2;a<length;a++){ |
768 | ch = Data[a]; | 768 | ch = Data[a]; |
769 | if (ch == '\000') continue; // Remove nulls | 769 | if (ch == '\000') continue; // Remove nulls |
770 | Comment.append(ch); | 770 | Comment.append(ch); |
771 | } | 771 | } |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | //-------------------------------------------------------------------------- | 775 | //-------------------------------------------------------------------------- |
776 | // Process a SOFn marker. This is useful for the image dimensions | 776 | // Process a SOFn marker. This is useful for the image dimensions |
777 | //-------------------------------------------------------------------------- | 777 | //-------------------------------------------------------------------------- |
778 | void ExifData::process_SOFn (const uchar * Data, int marker) | 778 | void ExifData::process_SOFn (const uchar * Data, int marker) |
779 | { | 779 | { |
780 | int data_precision, num_components; | 780 | int data_precision, num_components; |
781 | 781 | ||
782 | data_precision = Data[2]; | 782 | data_precision = Data[2]; |
783 | ExifData::Height = Get16m(Data+3); | 783 | ExifData::Height = Get16m(Data+3); |
784 | ExifData::Width = Get16m(Data+5); | 784 | ExifData::Width = Get16m(Data+5); |
785 | num_components = Data[7]; | 785 | num_components = Data[7]; |
786 | 786 | ||
787 | if (num_components == 3){ | 787 | if (num_components == 3){ |
788 | ExifData::IsColor = 1; | 788 | ExifData::IsColor = 1; |
789 | }else{ | 789 | }else{ |
790 | ExifData::IsColor = 0; | 790 | ExifData::IsColor = 0; |
791 | } | 791 | } |
792 | 792 | ||
793 | ExifData::Process = marker; | 793 | ExifData::Process = marker; |
794 | 794 | ||
795 | } | 795 | } |
796 | 796 | ||
797 | //-------------------------------------------------------------------------- | 797 | //-------------------------------------------------------------------------- |
798 | // Get 16 bits motorola order (always) for jpeg header stuff. | 798 | // Get 16 bits motorola order (always) for jpeg header stuff. |
799 | //-------------------------------------------------------------------------- | 799 | //-------------------------------------------------------------------------- |
@@ -872,97 +872,97 @@ int ExifData::Exif2tm(struct tm * timeptr, char * ExifTime) | |||
872 | if (a == 6){ | 872 | if (a == 6){ |
873 | timeptr->tm_isdst = -1; | 873 | timeptr->tm_isdst = -1; |
874 | timeptr->tm_mon -= 1; // Adjust for unix zero-based months | 874 | timeptr->tm_mon -= 1; // Adjust for unix zero-based months |
875 | timeptr->tm_year -= 1900; // Adjust for year starting at 1900 | 875 | timeptr->tm_year -= 1900; // Adjust for year starting at 1900 |
876 | return true; // worked. | 876 | return true; // worked. |
877 | } | 877 | } |
878 | 878 | ||
879 | return false; // Wasn't in Exif date format. | 879 | return false; // Wasn't in Exif date format. |
880 | } | 880 | } |
881 | 881 | ||
882 | //-------------------------------------------------------------------------- | 882 | //-------------------------------------------------------------------------- |
883 | // Contructor for initialising | 883 | // Contructor for initialising |
884 | //-------------------------------------------------------------------------- | 884 | //-------------------------------------------------------------------------- |
885 | ExifData::ExifData() | 885 | ExifData::ExifData() |
886 | { | 886 | { |
887 | ExifData::Whitebalance = -1; | 887 | ExifData::Whitebalance = -1; |
888 | ExifData::MeteringMode = -1; | 888 | ExifData::MeteringMode = -1; |
889 | ExifData::FlashUsed = -1; | 889 | ExifData::FlashUsed = -1; |
890 | Orientation = 0; | 890 | Orientation = 0; |
891 | Height = 0; | 891 | Height = 0; |
892 | Width = 0; | 892 | Width = 0; |
893 | IsColor = 0; | 893 | IsColor = 0; |
894 | Process = 0; | 894 | Process = 0; |
895 | FocalLength = 0; | 895 | FocalLength = 0; |
896 | ExposureTime = 0; | 896 | ExposureTime = 0; |
897 | ApertureFNumber = 0; | 897 | ApertureFNumber = 0; |
898 | Distance = 0; | 898 | Distance = 0; |
899 | CCDWidth = 0; | 899 | CCDWidth = 0; |
900 | ExposureBias = 0; | 900 | ExposureBias = 0; |
901 | ExposureProgram = 0; | 901 | ExposureProgram = 0; |
902 | ISOequivalent = 0; | 902 | ISOequivalent = 0; |
903 | CompressionLevel = 0; | 903 | CompressionLevel = 0; |
904 | } | 904 | } |
905 | 905 | ||
906 | //-------------------------------------------------------------------------- | 906 | //-------------------------------------------------------------------------- |
907 | // process a EXIF jpeg file | 907 | // process a EXIF jpeg file |
908 | //-------------------------------------------------------------------------- | 908 | //-------------------------------------------------------------------------- |
909 | bool ExifData::scan(const QString & path) | 909 | bool ExifData::scan(const QString & path) |
910 | { | 910 | { |
911 | int ret; | 911 | int ret; |
912 | 912 | ||
913 | QFile f(path); | 913 | QFile f(path); |
914 | f.open(IO_ReadOnly); | 914 | f.open(IO_ReadOnly); |
915 | 915 | ||
916 | // Scan the JPEG headers. | 916 | // Scan the JPEG headers. |
917 | ret = ReadJpegSections(f, READ_EXIF); | 917 | ret = ReadJpegSections(f, READ_EXIF); |
918 | 918 | ||
919 | if (ret == false){ | 919 | if (ret == false){ |
920 | owarn << "Not JPEG file!" << oendl; | 920 | owarn << "Not JPEG file!" << oendl; |
921 | DiscardData(); | 921 | DiscardData(); |
922 | f.close(); | 922 | f.close(); |
923 | return false; | 923 | return false; |
924 | } | 924 | } |
925 | f.close(); | 925 | f.close(); |
926 | DiscardData(); | 926 | DiscardData(); |
927 | 927 | ||
928 | //now make the strings clean, | 928 | //now make the strings clean, |
929 | // for exmaple my Casio is a "QV-4000 " | 929 | // for exmaple my Casio is a "QV-4000 " |
930 | CameraMake = CameraMake.stripWhiteSpace(); | 930 | CameraMake = CameraMake.stripWhiteSpace(); |
931 | CameraModel = CameraModel.stripWhiteSpace(); | 931 | CameraModel = CameraModel.stripWhiteSpace(); |
932 | UserComment = UserComment.stripWhiteSpace(); | 932 | UserComment = UserComment.stripWhiteSpace(); |
933 | Comment = Comment.stripWhiteSpace(); | 933 | Comment = Comment.stripWhiteSpace(); |
934 | return true; | 934 | return true; |
935 | } | 935 | } |
936 | 936 | ||
937 | //-------------------------------------------------------------------------- | 937 | //-------------------------------------------------------------------------- |
938 | // Does the embedded thumbnail match the jpeg image? | 938 | // Does the embedded thumbnail match the jpeg image? |
939 | //-------------------------------------------------------------------------- | 939 | //-------------------------------------------------------------------------- |
940 | #ifndef JPEG_TOL | 940 | #ifndef JPEG_TOL |
941 | #define JPEG_TOL 0.02 | 941 | #define JPEG_TOL 0.02 |
942 | #endif | 942 | #endif |
943 | bool ExifData::isThumbnailSane() { | 943 | bool ExifData::isThumbnailSane() { |
944 | if (Thumbnail.isNull()) return false; | 944 | if (Thumbnail.isNull()) return false; |
945 | 945 | ||
946 | // check whether thumbnail dimensions match the image | 946 | // check whether thumbnail dimensions match the image |
947 | // not foolproof, but catches some altered images (jpegtran -rotate) | 947 | // not foolproof, but catches some altered images (jpegtran -rotate) |
948 | if (ExifImageLength != 0 && ExifImageLength != Height) return false; | 948 | if (ExifImageLength != 0 && ExifImageLength != Height) return false; |
949 | if (ExifImageWidth != 0 && ExifImageWidth != Width) return false; | 949 | if (ExifImageWidth != 0 && ExifImageWidth != Width) return false; |
950 | if (Thumbnail.width() == 0 || Thumbnail.height() == 0) return false; | 950 | if (Thumbnail.width() == 0 || Thumbnail.height() == 0) return false; |
951 | if (Height == 0 || Width == 0) return false; | 951 | if (Height == 0 || Width == 0) return false; |
952 | double d = (double)Height/Width*Thumbnail.width()/Thumbnail.height(); | 952 | double d = (double)Height/Width*Thumbnail.width()/Thumbnail.height(); |
953 | return (1-JPEG_TOL < d) && (d < 1+JPEG_TOL); | 953 | return (1-JPEG_TOL < d) && (d < 1+JPEG_TOL); |
954 | } | 954 | } |
955 | 955 | ||
956 | 956 | ||
957 | 957 | ||
958 | static QImage flip_image( const QImage& img ); | 958 | static QImage flip_image( const QImage& img ); |
959 | static QImage rotate_90( const QImage& img ); | 959 | static QImage rotate_90( const QImage& img ); |
960 | static QImage rotate_180( const QImage& ); | 960 | static QImage rotate_180( const QImage& ); |
961 | static QImage rotate_270( const QImage& ); | 961 | static QImage rotate_270( const QImage& ); |
962 | 962 | ||
963 | //-------------------------------------------------------------------------- | 963 | //-------------------------------------------------------------------------- |
964 | // return a thumbnail that respects the orientation flag | 964 | // return a thumbnail that respects the orientation flag |
965 | // only if it seems sane | 965 | // only if it seems sane |
966 | //-------------------------------------------------------------------------- | 966 | //-------------------------------------------------------------------------- |
967 | QImage ExifData::getThumbnail() { | 967 | QImage ExifData::getThumbnail() { |
968 | if (!isThumbnailSane()) return NULL; | 968 | if (!isThumbnailSane()) return NULL; |
@@ -1370,60 +1370,68 @@ QString JpegSlave::fullImageInfo( const QString& path) { | |||
1370 | tag += QObject::tr( "CCD width: %1" ).arg( ImageInfo.getCCDWidth() ); | 1370 | tag += QObject::tr( "CCD width: %1" ).arg( ImageInfo.getCCDWidth() ); |
1371 | if ( ImageInfo.getExposureTime() ) { | 1371 | if ( ImageInfo.getExposureTime() ) { |
1372 | tmp = QString().sprintf("%4.2f", ImageInfo.getExposureTime() ); | 1372 | tmp = QString().sprintf("%4.2f", ImageInfo.getExposureTime() ); |
1373 | float exposureTime = ImageInfo.getExposureTime(); | 1373 | float exposureTime = ImageInfo.getExposureTime(); |
1374 | if ( exposureTime > 0 && exposureTime <= 0.5 ) | 1374 | if ( exposureTime > 0 && exposureTime <= 0.5 ) |
1375 | tmp += QString().sprintf(" (1/%d)", (int)(0.5 +1/exposureTime) ); | 1375 | tmp += QString().sprintf(" (1/%d)", (int)(0.5 +1/exposureTime) ); |
1376 | tag += QObject::tr( "Exposure time: %1\n" ).arg( tmp ); | 1376 | tag += QObject::tr( "Exposure time: %1\n" ).arg( tmp ); |
1377 | } | 1377 | } |
1378 | 1378 | ||
1379 | if ( ImageInfo.getApertureFNumber() ) | 1379 | if ( ImageInfo.getApertureFNumber() ) |
1380 | tag += QObject::tr( "Aperture: %1\n" ).arg( QString().sprintf("f/%3.1f", (double)ImageInfo.getApertureFNumber() ) ); | 1380 | tag += QObject::tr( "Aperture: %1\n" ).arg( QString().sprintf("f/%3.1f", (double)ImageInfo.getApertureFNumber() ) ); |
1381 | 1381 | ||
1382 | if ( ImageInfo.getDistance() ) { | 1382 | if ( ImageInfo.getDistance() ) { |
1383 | if ( ImageInfo.getDistance() < 0 ) | 1383 | if ( ImageInfo.getDistance() < 0 ) |
1384 | tag += QObject::tr( "Distance: %1\n" ).arg( QObject::tr( "Infinite" ) ); | 1384 | tag += QObject::tr( "Distance: %1\n" ).arg( QObject::tr( "Infinite" ) ); |
1385 | else | 1385 | else |
1386 | tag += QObject::tr( "Distance: %1\n" ).arg( QString().sprintf( "%5.2fm", (double)ImageInfo.getDistance() ) ); | 1386 | tag += QObject::tr( "Distance: %1\n" ).arg( QString().sprintf( "%5.2fm", (double)ImageInfo.getDistance() ) ); |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | if ( ImageInfo.getExposureBias() ) { | 1389 | if ( ImageInfo.getExposureBias() ) { |
1390 | tag += QObject::tr( "Exposure bias: %1\n", QString().sprintf("%4.2f", (double)ImageInfo.getExposureBias() ) ); | 1390 | tag += QObject::tr( "Exposure bias: %1\n", QString().sprintf("%4.2f", (double)ImageInfo.getExposureBias() ) ); |
1391 | } | 1391 | } |
1392 | 1392 | ||
1393 | if ( ImageInfo.getWhitebalance() != -1 ) | 1393 | if ( ImageInfo.getWhitebalance() != -1 ) |
1394 | tag += white_balance_string( ImageInfo.getWhitebalance() ); | 1394 | tag += white_balance_string( ImageInfo.getWhitebalance() ); |
1395 | 1395 | ||
1396 | 1396 | ||
1397 | if( ImageInfo.getMeteringMode() != -1 ) | 1397 | if( ImageInfo.getMeteringMode() != -1 ) |
1398 | tag += metering_mode( ImageInfo.getMeteringMode() ); | 1398 | tag += metering_mode( ImageInfo.getMeteringMode() ); |
1399 | 1399 | ||
1400 | if ( ImageInfo.getExposureProgram() ) | 1400 | if ( ImageInfo.getExposureProgram() ) |
1401 | tag += exposure_program( ImageInfo.getExposureProgram() ); | 1401 | tag += exposure_program( ImageInfo.getExposureProgram() ); |
1402 | if ( ImageInfo.getISOequivalent() ) | 1402 | if ( ImageInfo.getISOequivalent() ) |
1403 | tag += QObject::tr( "ISO equivalent: %1\n" ).arg( QString().sprintf("%2d", ImageInfo.getISOequivalent() ) ); | 1403 | tag += QObject::tr( "ISO equivalent: %1\n" ).arg( QString().sprintf("%2d", ImageInfo.getISOequivalent() ) ); |
1404 | 1404 | ||
1405 | tmp = ImageInfo.getUserComment(); | 1405 | tmp = ImageInfo.getUserComment(); |
1406 | if ( tmp.length() ) | 1406 | if ( tmp.length() ) |
1407 | tag += QObject::tr( "EXIF comment: %1" ).arg( tmp ); | 1407 | tag += QObject::tr( "EXIF comment: %1" ).arg( tmp ); |
1408 | 1408 | ||
1409 | tag += QObject::tr( "</qt>" ); | 1409 | tag += QObject::tr( "</qt>" ); |
1410 | 1410 | ||
1411 | 1411 | ||
1412 | 1412 | ||
1413 | return tag; | 1413 | return tag; |
1414 | } | 1414 | } |
1415 | 1415 | ||
1416 | QPixmap JpegSlave::pixmap( const QString& path, int wid, int hei) { | 1416 | QPixmap JpegSlave::pixmap( const QString& path, int wid, int hei) { |
1417 | ExifData ImageInfo; | 1417 | ExifData ImageInfo; |
1418 | /* | ||
1419 | */ | ||
1418 | if ( !ImageInfo.scan( path ) || ImageInfo.isNullThumbnail() ) { | 1420 | if ( !ImageInfo.scan( path ) || ImageInfo.isNullThumbnail() ) { |
1419 | QImage img; | 1421 | QImage img; |
1420 | QImageIO iio( path, 0l ); | 1422 | QImageIO iio( path, 0l ); |
1421 | QString str = QString( "Fast Shrink( 4 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); | 1423 | if (wid < ImageInfo.getWidth() || hei<ImageInfo.getHeight()) { |
1422 | iio.setParameters( str.latin1() );// will be strdupped anyway | 1424 | odebug << "Scaling "<<ImageInfo.getWidth()<<"x"<<ImageInfo.getHeight() |
1425 | << " to "<<wid<<"x"<<hei<< " ("<<path<<")"<<oendl; | ||
1426 | QString str = QString( "Fast Shrink( 4 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); | ||
1427 | iio.setParameters( str.latin1() );// will be strdupped anyway | ||
1428 | } else { | ||
1429 | odebug << "Not scaling "<<ImageInfo.getWidth()<<"x"<<ImageInfo.getHeight()<< " ("<<path<<")"<<oendl; | ||
1430 | } | ||
1423 | img = iio.read() ? iio.image() : QImage(); | 1431 | img = iio.read() ? iio.image() : QImage(); |
1424 | return ThumbNailTool::scaleImage( img, wid,hei ); | 1432 | return ThumbNailTool::scaleImage( img, wid,hei ); |
1425 | }else{ | 1433 | }else{ |
1426 | QImage img = ImageInfo.getThumbnail(); | 1434 | QImage img = ImageInfo.getThumbnail(); |
1427 | return ThumbNailTool::scaleImage( img, wid,hei ); | 1435 | return ThumbNailTool::scaleImage( img, wid,hei ); |
1428 | } | 1436 | } |
1429 | } | 1437 | } |