2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
7 #include "exif_parser.h"
17 #include "ReadHelper.h"
22 process_exif(uint8
* data
, uint32 length
)
24 if (memcmp(data
+ 2, "Exif", 4))
27 BMemoryIO
source(data
+ 8, length
- 8);
29 status_t status
= convert_exif_to_message(source
, exif
);
32 // even if it failed, some data might end up in the message
39 process_jpeg(BPositionIO
& stream
)
42 START_OF_IMAGE_MARKER
= 0xd8,
47 if (stream
.Read(&header
, 2) != 2)
49 if (header
[0] != 0xff || header
[1] != START_OF_IMAGE_MARKER
)
55 for (int32 i
= 0; i
< 7; i
++) {
56 if (stream
.Read(&marker
, 1) != 1)
66 // get length of section
69 if (stream
.Read(&length
, 2) != 2)
72 swap_data(B_UINT16_TYPE
, &length
, 2, B_SWAP_BENDIAN_TO_HOST
);
74 if (marker
== EXIF_MARKER
) {
76 stream
.Seek(-2, SEEK_CUR
);
78 uint8 exifData
[length
];
79 if (stream
.Read(exifData
, length
) == length
80 && process_exif(exifData
, length
) == B_OK
)
84 stream
.Seek(length
- 2, SEEK_CUR
);
93 process_file(entry_ref
& ref
)
95 BFile
file(&ref
, B_READ_WRITE
);
96 status_t status
= file
.InitCheck();
102 BBufferIO
stream(&file
, 65536, false);
103 status
= process_jpeg(file
);
105 fprintf(stderr
, "%s: processing JPEG file failed: %s\n", ref
.name
,
115 main(int argc
, char **argv
)
117 for (int i
= 1; i
< argc
; i
++) {
118 BEntry
entry(argv
[i
]);
120 if (entry
.InitCheck() != B_OK
|| entry
.GetRef(&ref
) != B_OK
)