// 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 ConvertPackedFrameToImageBundle(const JxlBasicInfo& info, const JxlBitDepth& input_bitdepth, const PackedFrame& frame, const CodecInOut& io, ThreadPool* pool,
ImageBundle* bundle) {
JxlMemoryManager* memory_manager = io.memory_manager;
JXL_ENSURE(frame.color.pixels() != nullptr);
size_t frame_bits_per_sample; if (input_bitdepth.type == JXL_BIT_DEPTH_FROM_PIXEL_FORMAT) {
JXL_RETURN_IF_ERROR(
PackedImage::ValidateDataType(frame.color.format.data_type));
frame_bits_per_sample =
PackedImage::BitsPerChannel(frame.color.format.data_type);
} else {
frame_bits_per_sample = info.bits_per_sample;
}
JXL_ENSURE(frame_bits_per_sample != 0); // It is ok for the frame.color.format.num_channels to not match the // number of channels on the image.
JXL_ENSURE(1 <= frame.color.format.num_channels &&
frame.color.format.num_channels <= 4);
// Convert the color encoding. if (ppf.primary_color_representation == PackedPixelFile::kIccIsPrimary) {
IccBytes icc = ppf.icc; if (!io->metadata.m.color_encoding.SetICC(std::move(icc),
JxlGetDefaultCms())) {
fprintf(stderr, "Warning: error setting ICC profile, assuming SRGB\n");
io->metadata.m.color_encoding = ColorEncoding::SRGB(is_gray);
} else { if (io->metadata.m.color_encoding.IsCMYK()) { // We expect gray or tri-color. return JXL_FAILURE("Embedded ICC is CMYK");
} if (io->metadata.m.color_encoding.IsGray() != is_gray) { // E.g. JPG image has 3 channels, but gray ICC. return JXL_FAILURE("Embedded ICC does not match image color type");
}
}
} else {
JXL_RETURN_IF_ERROR(
io->metadata.m.color_encoding.FromExternal(ppf.color_encoding)); if (io->metadata.m.color_encoding.ICC().empty()) { return JXL_FAILURE("Failed to serialize ICC");
}
}
// Convert the extra blobs
io->blobs.exif = ppf.metadata.exif;
io->blobs.iptc = ppf.metadata.iptc;
io->blobs.jhgm = ppf.metadata.jhgm;
io->blobs.jumbf = ppf.metadata.jumbf;
io->blobs.xmp = ppf.metadata.xmp;
// Convert the color encoding
ppf->icc.assign(c_desired.ICC().begin(), c_desired.ICC().end());
ppf->primary_color_representation =
c_desired.WantICC() ? PackedPixelFile::kIccIsPrimary
: PackedPixelFile::kColorEncodingIsPrimary;
ppf->color_encoding = c_desired.ToExternal();
// Convert the extra blobs
ppf->metadata.exif = io.blobs.exif;
ppf->metadata.iptc = io.blobs.iptc;
ppf->metadata.jhgm = io.blobs.jhgm;
ppf->metadata.jumbf = io.blobs.jumbf;
ppf->metadata.xmp = io.blobs.xmp; constbool float_out = pixel_format.data_type == JXL_TYPE_FLOAT ||
pixel_format.data_type == JXL_TYPE_FLOAT16; // Convert the pixels
ppf->frames.clear(); for (constauto& frame : io.frames) {
JXL_ENSURE(frame.metadata()->bit_depth.bits_per_sample != 0); // It is ok for the frame.color().kNumPlanes to not match the // number of channels on the image. const uint32_t alpha_channels = has_alpha ? 1 : 0; const uint32_t num_channels =
frame.metadata()->color_encoding.Channels() + alpha_channels;
JxlPixelFormat format{/*num_channels=*/num_channels, /*data_type=*/pixel_format.data_type, /*endianness=*/pixel_format.endianness, /*align=*/pixel_format.align};
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.