Skip to content

Commit 3ce3d48

Browse files
committed
extract new header heif_uncompressed.h from heif_experimental.h
1 parent 5d3c503 commit 3ce3d48

File tree

8 files changed

+181
-69
lines changed

8 files changed

+181
-69
lines changed

examples/heif_enc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "libheif/api_structs.h"
5656
#include "libheif/heif_experimental.h"
5757
#include "libheif/heif_sequences.h"
58+
#include "libheif/heif_uncompressed.h"
5859

5960
// --- command line parameters
6061

libheif/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(libheif_headers
2424
api/libheif/heif_image_handle.h
2525
api/libheif/heif_context.h
2626
api/libheif/heif_tiling.h
27+
api/libheif/heif_uncompressed.h
2728
api/libheif/heif_cxx.h
2829
${CMAKE_CURRENT_BINARY_DIR}/heif_version.h)
2930

@@ -80,6 +81,7 @@ set(libheif_sources
8081
api/libheif/heif_image_handle.cc
8182
api/libheif/heif_context.cc
8283
api/libheif/heif_tiling.cc
84+
api/libheif/heif_uncompressed.cc
8385
codecs/decoder.h
8486
codecs/decoder.cc
8587
codecs/encoder.h

libheif/api/libheif/heif_experimental.cc

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -369,35 +369,6 @@ void heif_pyramid_layer_info_release(struct heif_pyramid_layer_info* infos)
369369
}
370370

371371

372-
struct heif_error heif_context_add_unci_image(struct heif_context* ctx,
373-
const struct heif_unci_image_parameters* parameters,
374-
const struct heif_encoding_options* encoding_options,
375-
const heif_image* prototype,
376-
struct heif_image_handle** out_unci_image_handle)
377-
{
378-
#if WITH_UNCOMPRESSED_CODEC
379-
Result<std::shared_ptr<ImageItem_uncompressed>> unciImageResult;
380-
unciImageResult = ImageItem_uncompressed::add_unci_item(ctx->context.get(), parameters, encoding_options, prototype->image);
381-
382-
if (unciImageResult.error != Error::Ok) {
383-
return unciImageResult.error.error_struct(ctx->context.get());
384-
}
385-
386-
if (out_unci_image_handle) {
387-
*out_unci_image_handle = new heif_image_handle;
388-
(*out_unci_image_handle)->image = unciImageResult.value;
389-
(*out_unci_image_handle)->context = ctx->context;
390-
}
391-
392-
return heif_error_success;
393-
#else
394-
return {heif_error_Unsupported_feature,
395-
heif_suberror_Unspecified,
396-
"support for uncompressed images (ISO23001-17) has been disabled."};
397-
#endif
398-
}
399-
400-
401372
struct heif_error heif_image_add_channel(struct heif_image* image,
402373
enum heif_channel channel,
403374
int width, int height,

libheif/api/libheif/heif_experimental.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -149,46 +149,6 @@ struct heif_error heif_context_add_tiled_image(struct heif_context* ctx,
149149
struct heif_image_handle** out_tiled_image_handle);
150150
#endif
151151

152-
// --- 'unci' images
153-
154-
// This is similar to heif_metadata_compression. We should try to keep the integers compatible, but each enum will just
155-
// contain the allowed values.
156-
enum heif_unci_compression
157-
{
158-
heif_unci_compression_off = 0,
159-
//heif_unci_compression_auto = 1,
160-
//heif_unci_compression_unknown = 2, // only used when reading unknown method from input file
161-
heif_unci_compression_deflate = 3,
162-
heif_unci_compression_zlib = 4,
163-
heif_unci_compression_brotli = 5
164-
};
165-
166-
167-
struct heif_unci_image_parameters {
168-
int version;
169-
170-
// --- version 1
171-
172-
uint32_t image_width;
173-
uint32_t image_height;
174-
175-
uint32_t tile_width;
176-
uint32_t tile_height;
177-
178-
enum heif_unci_compression compression; // TODO
179-
180-
// TODO: interleave type, padding
181-
};
182-
183-
#if HEIF_ENABLE_EXPERIMENTAL_FEATURES
184-
LIBHEIF_API
185-
struct heif_error heif_context_add_unci_image(struct heif_context* ctx,
186-
const struct heif_unci_image_parameters* parameters,
187-
const struct heif_encoding_options* encoding_options,
188-
const struct heif_image* prototype,
189-
struct heif_image_handle** out_unci_image_handle);
190-
#endif
191-
192152
// --- 'pymd' entity group (pyramid layers)
193153

194154
struct heif_pyramid_layer_info {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* HEIF codec.
3+
* Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com>
4+
*
5+
* This file is part of libheif.
6+
*
7+
* libheif is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 3 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* libheif is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with libheif. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#include "heif_uncompressed.h"
22+
#include "context.h"
23+
#include "api_structs.h"
24+
#include "image-items/unc_image.h"
25+
26+
#include <array>
27+
#include <memory>
28+
29+
30+
struct heif_error heif_context_add_unci_image(struct heif_context* ctx,
31+
const struct heif_unci_image_parameters* parameters,
32+
const struct heif_encoding_options* encoding_options,
33+
const heif_image* prototype,
34+
struct heif_image_handle** out_unci_image_handle)
35+
{
36+
#if WITH_UNCOMPRESSED_CODEC
37+
if (prototype == nullptr) {
38+
return {heif_error_Usage_error,
39+
heif_suberror_Null_pointer_argument,
40+
"prototype image is NULL"};
41+
}
42+
43+
if (out_unci_image_handle == nullptr) {
44+
return {heif_error_Usage_error,
45+
heif_suberror_Null_pointer_argument,
46+
"out_unci_image_handle image is NULL"};
47+
}
48+
49+
Result<std::shared_ptr<ImageItem_uncompressed>> unciImageResult;
50+
unciImageResult = ImageItem_uncompressed::add_unci_item(ctx->context.get(), parameters, encoding_options, prototype->image);
51+
52+
if (unciImageResult.error != Error::Ok) {
53+
return unciImageResult.error.error_struct(ctx->context.get());
54+
}
55+
56+
assert(out_unci_image_handle);
57+
*out_unci_image_handle = new heif_image_handle;
58+
(*out_unci_image_handle)->image = unciImageResult.value;
59+
(*out_unci_image_handle)->context = ctx->context;
60+
61+
return heif_error_success;
62+
#else
63+
return {heif_error_Unsupported_feature,
64+
heif_suberror_Unspecified,
65+
"support for uncompressed images (ISO23001-17) has been disabled."};
66+
#endif
67+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* HEIF codec.
3+
* Copyright (c) 2024-2025 Dirk Farin <dirk.farin@gmail.com>
4+
*
5+
* This file is part of libheif.
6+
*
7+
* libheif is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 3 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* libheif is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with libheif. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef LIBHEIF_HEIF_UNCOMPRESSED_H
22+
#define LIBHEIF_HEIF_UNCOMPRESSED_H
23+
24+
#include "libheif/heif.h"
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/* @file heif_uncompressed.h
31+
* @brief Functions for adding ISO 23001-17 (uncompressed) images to a HEIF file.
32+
* Despite its name, this is not limited to uncompressed images.
33+
* It is also possible to add images with lossless compression methods.
34+
* See heif_metadata_compression for more information.
35+
*/
36+
37+
// --- 'unci' images
38+
39+
// This is similar to heif_metadata_compression. We should try to keep the integers compatible, but each enum will just
40+
// contain the allowed values.
41+
enum heif_unci_compression
42+
{
43+
heif_unci_compression_off = 0,
44+
//heif_unci_compression_auto = 1,
45+
//heif_unci_compression_unknown = 2, // only used when reading unknown method from input file
46+
heif_unci_compression_deflate = 3,
47+
heif_unci_compression_zlib = 4,
48+
heif_unci_compression_brotli = 5
49+
};
50+
51+
52+
struct heif_unci_image_parameters {
53+
int version;
54+
55+
// --- version 1
56+
57+
uint32_t image_width;
58+
uint32_t image_height;
59+
60+
uint32_t tile_width;
61+
uint32_t tile_height;
62+
63+
enum heif_unci_compression compression;
64+
65+
// TODO: interleave type, padding
66+
};
67+
68+
LIBHEIF_API
69+
struct heif_unci_image_parameters* heif_unci_image_parameters_alloc();
70+
71+
LIBHEIF_API
72+
void heif_unci_image_parameters_copy(struct heif_unci_image_parameters* dst,
73+
const struct heif_unci_image_parameters* src);
74+
75+
LIBHEIF_API
76+
void heif_unci_image_parameters_release(struct heif_unci_image_parameters*);
77+
78+
79+
/*
80+
* This adds an empty iso23001-17 (uncompressed) image to the HEIF file.
81+
* The actual image data is addded later using heif_context_add_image_tile().
82+
* If you do not need tiling, you can use heif_context_encode_image() instead.
83+
* However, this will by default disable any compression and any control about
84+
* the data layout.
85+
*
86+
* @param ctx The file context
87+
* @param parameters The parameters for the image, must not be NULL.
88+
* @param encoding_options Optional, may be NULL.
89+
* @param prototype An image with the same channel configuration as the image data
90+
* that will be later inserted. The image size need not match this.
91+
* Must not be NULL.
92+
* @param out_unci_image_handle Returns a handle to the image. The caller is responsible for freeing it.
93+
* Must not be NULL because this is required to fill in image data.
94+
* @return Returns an error if the passed parameters are incorrect.
95+
* If ISO23001-17 images are not supported, returns heif_error_Unsupported_feature.
96+
*/
97+
LIBHEIF_API
98+
struct heif_error heif_context_add_unci_image(struct heif_context* ctx,
99+
const struct heif_unci_image_parameters* parameters,
100+
const struct heif_encoding_options* encoding_options,
101+
const struct heif_image* prototype,
102+
struct heif_image_handle** out_unci_image_handle);
103+
104+
#ifdef __cplusplus
105+
}
106+
#endif
107+
108+
#endif

libheif/codecs/uncompressed/unc_codec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "pixelimage.h"
2626
#include "file.h"
2727
#include "context.h"
28+
#include "libheif/heif_uncompressed.h"
29+
2830
#if WITH_UNCOMPRESSED_CODEC
2931
#include "unc_boxes.h"
3032
#endif

libheif/image-items/unc_image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "pixelimage.h"
2626
#include "file.h"
2727
#include "context.h"
28+
#include "libheif/heif_uncompressed.h"
2829

2930
#include <cstdint>
3031
#include <string>

0 commit comments

Comments
 (0)