// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
Status UnmapColors(uint8_t* row, size_t xsize, int components,
JSAMPARRAY colormap, size_t num_colors) {
JXL_ENSURE(colormap != nullptr);
std::vector<uint8_t> tmp(xsize * components); for (size_t x = 0; x < xsize; ++x) {
JXL_ENSURE(row[x] < num_colors); for (int c = 0; c < components; ++c) {
tmp[x * components + c] = colormap[c][row[x]];
}
}
memcpy(row, tmp.data(), tmp.size()); returntrue;
}
} // namespace
Status DecodeJpeg(const std::vector<uint8_t>& compressed, const JpegDecompressParams& dparams, ThreadPool* pool,
PackedPixelFile* ppf) { // Don't do anything for non-JPEG files (no need to report an error) if (!IsJPG(compressed)) returnfalse;
// TODO(veluca): use JPEGData also for pixels?
// We need to declare all the non-trivial destructor local variables before // the call to setjmp().
std::unique_ptr<JSAMPLE[]> row;
jpeg_decompress_struct cinfo; constauto try_catch_block = [&]() -> bool { // Setup error handling in jpeg library so we can deal with broken jpegs in // the fuzzer.
jpeg_error_mgr jerr;
jmp_buf env;
cinfo.err = jpegli_std_error(&jerr);
jerr.error_exit = &MyErrorExit;
jerr.output_message = &MyOutputMessage; if (setjmp(env)) { returnfalse;
}
cinfo.client_data = static_cast<void*>(&env);
jpegli_create_decompress(&cinfo);
jpegli_mem_src(&cinfo, reinterpret_cast<constunsignedchar*>(compressed.data()),
compressed.size());
jpegli_save_markers(&cinfo, kICCMarker, 0xFFFF);
jpegli_save_markers(&cinfo, kExifMarker, 0xFFFF); constauto failure = [&cinfo](constchar* str) -> Status {
jpegli_abort_decompress(&cinfo);
jpegli_destroy_decompress(&cinfo); return JXL_FAILURE("%s", str);
};
jpegli_read_header(&cinfo, TRUE); // Might cause CPU-zip bomb. if (cinfo.arith_code) { return failure("arithmetic code JPEGs are not supported");
} int nbcomp = cinfo.num_components; if (nbcomp != 1 && nbcomp != 3) {
std::string msg = "unsupported number of components in JPEG: " + std::to_string(nbcomp); return failure(msg.c_str());
} if (dparams.force_rgb) {
cinfo.out_color_space = JCS_RGB;
} elseif (dparams.force_grayscale) {
cinfo.out_color_space = JCS_GRAYSCALE;
} if (ReadICCProfile(&cinfo, &ppf->icc)) {
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
} else {
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
ppf->icc.clear(); // Default to SRGB
ppf->color_encoding.color_space =
ConvertColorSpace(cinfo.out_color_space);
ppf->color_encoding.white_point = JXL_WHITE_POINT_D65;
ppf->color_encoding.primaries = JXL_PRIMARIES_SRGB;
ppf->color_encoding.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
ppf->color_encoding.rendering_intent = JXL_RENDERING_INTENT_PERCEPTUAL;
}
ReadExif(&cinfo, &ppf->metadata.exif);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.