Skip to content

Commit

Permalink
Merge pull request #1 from strukturag/master
Browse files Browse the repository at this point in the history
Sync with main branch
  • Loading branch information
DichenZhang1 committed Apr 18, 2024
2 parents 3fe697a + 9ea417c commit d4dda15
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 41 deletions.
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
1 change: 1 addition & 0 deletions libheif/gain_map_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define LIBHEIF_GAIN_MAP_METADATA_H

#include "error.h"
#include <vector>

// Gain map metadata, for tone mapping between SDR and HDR.
class GainMapMetadata {
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 @@ -561,9 +567,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 @@ -593,11 +599,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 @@ -606,14 +610,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 @@ -622,17 +630,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 @@ -641,18 +645,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 @@ -665,16 +665,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

0 comments on commit d4dda15

Please sign in to comment.