Skip to content

Commit

Permalink
JPEG2000: use Decoder_JPEG2000 in ImageItem_JPEG2000
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 3, 2024
1 parent 901ce17 commit a1e388c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
41 changes: 17 additions & 24 deletions libheif/codecs/jpeg2000.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

#include "jpeg2000.h"
#include "libheif/api_structs.h"
#include "jpeg2000_dec.h"
#include <cstdint>
#include <iostream>
#include <stdio.h>
#include <cstdio>

static const uint16_t JPEG2000_CAP_MARKER = 0xFF50;
static const uint16_t JPEG2000_SIZ_MARKER = 0xFF51;
Expand Down Expand Up @@ -542,34 +543,26 @@ Result<std::vector<uint8_t>> ImageItem_JPEG2000::read_bitstream_configuration_da
return std::vector<uint8_t>{};
}

std::shared_ptr<Decoder> ImageItem_JPEG2000::get_decoder() const
{
return m_decoder;
}

int ImageItem_JPEG2000::get_luma_bits_per_pixel() const
Error ImageItem_JPEG2000::on_load_file()
{
Result<std::vector<uint8_t>> imageDataResult = get_compressed_image_data();
if (imageDataResult.error) {
return -1;
auto j2kH = get_file()->get_property<Box_j2kH>(get_id());
if (!j2kH) {
return Error{heif_error_Invalid_input,
heif_suberror_Unspecified,
"No j2kH box found."};
}

JPEG2000MainHeader header;
Error err = header.parseHeader(*imageDataResult);
if (err) {
return -1;
}
return header.get_precision(0);
}
m_decoder = std::make_shared<Decoder_JPEG2000>(j2kH);

DataExtent extent;
extent.set_from_image_item(get_context()->get_heif_file(), get_id());

int ImageItem_JPEG2000::get_chroma_bits_per_pixel() const
{
Result<std::vector<uint8_t>> imageDataResult = get_compressed_image_data();
if (imageDataResult.error) {
return -1;
}
m_decoder->set_data_extent(extent);

JPEG2000MainHeader header;
Error err = header.parseHeader(*imageDataResult);
if (err) {
return -1;
}
return header.get_precision(1);
return Error::Ok;
}
12 changes: 8 additions & 4 deletions libheif/codecs/jpeg2000.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,21 @@ class ImageItem_JPEG2000 : public ImageItem

heif_compression_format get_compression_format() const override { return heif_compression_JPEG2000; }

int get_luma_bits_per_pixel() const override;

int get_chroma_bits_per_pixel() const override;

Result<CodedImageData> encode(const std::shared_ptr<HeifPixelImage>& image,
struct heif_encoder* encoder,
const struct heif_encoding_options& options,
enum heif_image_input_class input_class) override;

protected:
Result<std::vector<uint8_t>> read_bitstream_configuration_data(heif_item_id itemId) const override;

std::shared_ptr<Decoder> get_decoder() const override;

public:
Error on_load_file() override;

private:
std::shared_ptr<class Decoder_JPEG2000> m_decoder;
};

#endif // LIBHEIF_JPEG2000_H

0 comments on commit a1e388c

Please sign in to comment.