mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Have wuffs_aux::DecodeImage report ICCP, XMP
This commit is contained in:
1 parent
a9a6332be2
commit
c754f81634
5 files changed
+438
-100
No files matched your search
@@ -99,6 +99,126 @@ MemoryInput::CopyIn(IOBuffer* dst) {
|
||||
|
||||
} // namespace sync_io
|
||||
|
||||
namespace private_impl {
|
||||
|
||||
const char ErrMsg_MaxInclMetadataLengthExceeded[] = //
|
||||
"wuffs_aux::private_impl: max_incl_metadata_length exceeded";
|
||||
const char ErrMsg_UnexpectedEndOfFile[] = //
|
||||
"wuffs_aux::private_impl: unexpected end of file";
|
||||
const char ErrMsg_UnsupportedMetadata[] = //
|
||||
"wuffs_aux::private_impl: unsupported metadata";
|
||||
const char ErrMsg_UnsupportedNegativeAdvance[] = //
|
||||
"wuffs_aux::private_impl: unsupported negative advance";
|
||||
|
||||
std::string //
|
||||
AdvanceIOBufferTo(sync_io::Input& input,
|
||||
IOBuffer& io_buf,
|
||||
uint64_t absolute_position) {
|
||||
if (absolute_position < io_buf.reader_position()) {
|
||||
return ErrMsg_UnsupportedNegativeAdvance;
|
||||
}
|
||||
while (true) {
|
||||
uint64_t relative_position = absolute_position - io_buf.reader_position();
|
||||
if (relative_position <= io_buf.reader_length()) {
|
||||
io_buf.meta.ri += (size_t)relative_position;
|
||||
break;
|
||||
} else if (io_buf.meta.closed) {
|
||||
return ErrMsg_UnexpectedEndOfFile;
|
||||
}
|
||||
io_buf.meta.ri = io_buf.meta.wi;
|
||||
if (!input.BringsItsOwnIOBuffer()) {
|
||||
io_buf.compact();
|
||||
}
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return error_message;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string //
|
||||
HandleMetadata(
|
||||
sync_io::Input& input,
|
||||
wuffs_base__io_buffer& io_buf,
|
||||
uint64_t max_incl_metadata_length,
|
||||
wuffs_base__status (*tell_me_more_func)(void*,
|
||||
wuffs_base__io_buffer*,
|
||||
wuffs_base__more_information*,
|
||||
wuffs_base__io_buffer*),
|
||||
void* tell_me_more_receiver,
|
||||
std::string (*handle_metadata_func)(void*,
|
||||
const wuffs_base__more_information*,
|
||||
wuffs_base__slice_u8),
|
||||
void* handle_metadata_receiver) {
|
||||
wuffs_base__more_information minfo = wuffs_base__empty_more_information();
|
||||
std::vector<uint8_t> raw;
|
||||
|
||||
while (true) {
|
||||
wuffs_base__io_buffer empty = wuffs_base__empty_io_buffer();
|
||||
minfo = wuffs_base__empty_more_information();
|
||||
wuffs_base__status status =
|
||||
(*tell_me_more_func)(tell_me_more_receiver, &empty, &minfo, &io_buf);
|
||||
switch (minfo.flavor) {
|
||||
case 0:
|
||||
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_PARSED:
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__MORE_INFORMATION__FLAVOR__METADATA_RAW: {
|
||||
wuffs_base__range_ie_u64 r = minfo.metadata_raw__range();
|
||||
if (r.is_empty()) {
|
||||
break;
|
||||
} else if (r.length() > (max_incl_metadata_length - raw.size())) {
|
||||
return ErrMsg_MaxInclMetadataLengthExceeded;
|
||||
} else if (io_buf.reader_position() > r.min_incl) {
|
||||
return ErrMsg_UnsupportedMetadata;
|
||||
}
|
||||
std::string error_message =
|
||||
AdvanceIOBufferTo(input, io_buf, r.min_incl);
|
||||
if (!error_message.empty()) {
|
||||
return error_message;
|
||||
}
|
||||
|
||||
for (uint64_t num_to_copy = r.length(); num_to_copy > 0;) {
|
||||
uint8_t* ptr = io_buf.reader_pointer();
|
||||
uint64_t len =
|
||||
wuffs_base__u64__min(num_to_copy, io_buf.reader_length());
|
||||
raw.insert(raw.end(), ptr, ptr + len);
|
||||
io_buf.meta.ri += len;
|
||||
num_to_copy -= len;
|
||||
if (num_to_copy == 0) {
|
||||
break;
|
||||
} else if (io_buf.meta.closed) {
|
||||
return ErrMsg_UnexpectedEndOfFile;
|
||||
} else if (!input.BringsItsOwnIOBuffer()) {
|
||||
io_buf.compact();
|
||||
}
|
||||
std::string error_message = input.CopyIn(&io_buf);
|
||||
if (!error_message.empty()) {
|
||||
return error_message;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return ErrMsg_UnsupportedMetadata;
|
||||
}
|
||||
|
||||
if (status.repr == nullptr) {
|
||||
break;
|
||||
} else if (status.repr != wuffs_base__suspension__even_more_information) {
|
||||
return status.message();
|
||||
}
|
||||
}
|
||||
|
||||
return (*handle_metadata_func)(
|
||||
handle_metadata_receiver, &minfo,
|
||||
wuffs_base__make_slice_u8(raw.data(), raw.size()));
|
||||
}
|
||||
|
||||
} // namespace private_impl
|
||||
|
||||
} // namespace wuffs_aux
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
||||
|
||||
Reference in new issue
Block a user