Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with main branch #1

Merged
merged 15 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ jobs:
build:
strategy:
matrix:
runner: [ macos-12, macos-14 ]
env:
- { NAME: "nothing" }
- { NAME: "cmake", WITH_GRAPHICS: 1, WITH_X265: 1, WITH_AOM: 1, WITH_LIBDE265: 1 }
- { NAME: "libde265 (1) / x265 / graphics", WITH_GRAPHICS: 1, WITH_X265: 1, WITH_LIBDE265: 1 }
- { NAME: "libde265 (2) / x265 / graphics", WITH_GRAPHICS: 1, WITH_X265: 1, WITH_LIBDE265: 2 }
env: ${{ matrix.env }}
runs-on: macos-12
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

Expand Down
4 changes: 2 additions & 2 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,9 @@ Error Box_iloc::read_data(const Item& item,
}
else {
std::stringstream sstr;
sstr << "Item construction method " << item.construction_method << " not implemented";
sstr << "Item construction method " << (int) item.construction_method << " not implemented";
return Error(heif_error_Unsupported_feature,
heif_suberror_No_idat_box,
heif_suberror_Unsupported_item_construction_method,
sstr.str());
}
}
Expand Down
12 changes: 6 additions & 6 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ Error HeifContext::encode_image(const std::shared_ptr<HeifPixelImage>& pixel_ima
error = encode_image_as_hevc(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
Expand All @@ -2264,15 +2264,15 @@ Error HeifContext::encode_image(const std::shared_ptr<HeifPixelImage>& pixel_ima
error = encode_image_as_av1(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
case heif_compression_JPEG2000: {
error = encode_image_as_jpeg2000(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
Expand All @@ -2281,7 +2281,7 @@ Error HeifContext::encode_image(const std::shared_ptr<HeifPixelImage>& pixel_ima
error = encode_image_as_jpeg(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
Expand All @@ -2290,7 +2290,7 @@ Error HeifContext::encode_image(const std::shared_ptr<HeifPixelImage>& pixel_ima
error = encode_image_as_uncompressed(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
Expand All @@ -2299,7 +2299,7 @@ Error HeifContext::encode_image(const std::shared_ptr<HeifPixelImage>& pixel_ima
error = encode_image_as_mask(pixel_image,
encoder,
options,
heif_image_input_class_normal,
input_class,
out_image);
}
break;
Expand Down
12 changes: 5 additions & 7 deletions libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ heif_filetype_result heif_check_filetype(const uint8_t* data, int len)

int heif_check_jpeg_filetype(const uint8_t* data, int len)
{
if (len < 12 || data == nullptr) {
if (len < 4 || data == nullptr) {
return -1;
}

static uint8_t jpeg_signature[12] = {
0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10,
0x4A, 0x46, 0x49, 0x46, 0x00, 0x01
};

return strncmp((const char*) data, (const char*) jpeg_signature, 12) == 0;
return (data[0] == 0xFF &&
data[1] == 0xD8 &&
data[2] == 0xFF &&
(data[3] & 0xF0) == 0xE0);
}


Expand Down
50 changes: 22 additions & 28 deletions libheif/plugins/encoder_kvazaar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ static void copy_plane(kvz_pixel* out_p, uint32_t out_stride, const uint8_t* in_
}


template<typename T, typename D>
std::unique_ptr<T, D> make_guard(T* ptr, D&& deleter) {
return std::unique_ptr<T, D>(ptr, deleter);
}

static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct heif_image* image,
heif_image_input_class input_class)
{
Expand All @@ -381,7 +386,8 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
return err;
}

kvz_config* config = api->config_alloc();
auto uconfig = make_guard(api->config_alloc(), [api](kvz_config* cfg) { api->config_destroy(cfg); });
kvz_config* config = uconfig.get();
api->config_init(config); // param, encoder->preset.c_str(), encoder->tune.c_str());

#if HAVE_KVAZAAR_ENABLE_LOGGING
Expand Down Expand Up @@ -556,9 +562,9 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
}
*/

kvz_picture* pic = api->picture_alloc_csp(kvzChroma, encoded_width, encoded_height);
auto upic = make_guard(api->picture_alloc_csp(kvzChroma, encoded_width, encoded_height), [api](kvz_picture* pic) { api->picture_free(pic); });
kvz_picture* pic = upic.get();
if (!pic) {
api->config_destroy(config);
return heif_error{
heif_error_Encoder_plugin_error,
heif_suberror_Encoder_encoding,
Expand Down Expand Up @@ -588,11 +594,9 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
encoded_width >> chroma_stride_shift, encoded_height >> chroma_height_shift);
}

kvz_encoder* kvzencoder = api->encoder_open(config);
auto uencoder = make_guard(api->encoder_open(config), [api](kvz_encoder* e) { api->encoder_close(e); });
kvz_encoder* kvzencoder = uencoder.get();
if (!kvzencoder) {
api->picture_free(pic);
api->config_destroy(config);

return heif_error{
heif_error_Encoder_plugin_error,
heif_suberror_Encoder_encoding,
Expand All @@ -601,14 +605,18 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
}

kvz_data_chunk* data = nullptr;
auto free_data = [api](kvz_data_chunk** data){
if(*data) {
api->chunk_free(*data);
*data = nullptr;
}
};
auto data_deleter = std::unique_ptr<kvz_data_chunk*, decltype(free_data)>(&data, free_data);

uint32_t data_len;
int success;
success = api->encoder_headers(kvzencoder, &data, &data_len);
if (!success) {
api->picture_free(pic);
api->config_destroy(config);
api->encoder_close(kvzencoder);

return heif_error{
heif_error_Encoder_plugin_error,
heif_suberror_Encoder_encoding,
Expand All @@ -617,17 +625,13 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
}

append_chunk_data(data, encoder->output_data);
free_data(&data);

success = api->encoder_encode(kvzencoder,
pic,
&data, &data_len,
nullptr, nullptr, nullptr);
if (!success) {
api->chunk_free(data);
api->picture_free(pic);
api->config_destroy(config);
api->encoder_close(kvzencoder);

return heif_error{
heif_error_Encoder_plugin_error,
heif_suberror_Encoder_encoding,
Expand All @@ -636,18 +640,14 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
}

append_chunk_data(data, encoder->output_data);
free_data(&data);

for (;;) {
success = api->encoder_encode(kvzencoder,
nullptr,
&data, &data_len,
nullptr, nullptr, nullptr);
if (!success) {
api->chunk_free(data);
api->picture_free(pic);
api->config_destroy(config);
api->encoder_close(kvzencoder);

return heif_error{
heif_error_Encoder_plugin_error,
heif_suberror_Encoder_encoding,
Expand All @@ -660,16 +660,10 @@ static struct heif_error kvazaar_encode_image(void* encoder_raw, const struct he
}

append_chunk_data(data, encoder->output_data);
free_data(&data);
}

(void) success;

api->chunk_free(data);

api->encoder_close(kvzencoder);
api->picture_free(pic);
api->config_destroy(config);

return heif_error_ok;
}

Expand Down
2 changes: 1 addition & 1 deletion libheif/plugins/encoder_svt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ struct heif_error svt_encode_image(void* encoder_raw, const struct heif_image* i

if (nclx) {
svt_config.color_description_present_flag = true;
#if SVT_AV1_VERSION_MAJOR == 1
#if SVT_AV1_VERSION_MAJOR >= 1
svt_config.color_primaries = static_cast<EbColorPrimaries>(nclx->color_primaries);
svt_config.transfer_characteristics = static_cast<EbTransferCharacteristics>(nclx->transfer_characteristics);
svt_config.matrix_coefficients = static_cast<EbMatrixCoefficients>(nclx->matrix_coefficients);
Expand Down
2 changes: 1 addition & 1 deletion third-party/aom.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
: # If you're running this on Windows, be sure you've already run this (from your VC2019 install dir):
: # "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"

git clone -b v3.8.1 --depth 1 https://aomedia.googlesource.com/aom
git clone -b v3.8.2 --depth 1 https://aomedia.googlesource.com/aom

cd aom

Expand Down
2 changes: 1 addition & 1 deletion third-party/dav1d.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
: # If you're running this on Windows, be sure you've already run this (from your VC2019 install dir):
: # "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"

git clone -b 1.3.0 --depth 1 https://code.videolan.org/videolan/dav1d.git
git clone -b 1.4.1 --depth 1 https://code.videolan.org/videolan/dav1d.git

cd dav1d

Expand Down