Skip to content

Commit 72b7fcd

Browse files
committed
keep the 'old' transform property functions with the propertyId, but accept a zero propertyId (#1561)
1 parent d3287bf commit 72b7fcd

File tree

4 files changed

+35
-89
lines changed

4 files changed

+35
-89
lines changed

libheif/api/libheif/heif_experimental.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ struct heif_property_camera_intrinsic_matrix
3838

3939
struct heif_error heif_item_get_property_camera_intrinsic_matrix(const struct heif_context* context,
4040
heif_item_id itemId,
41+
heif_property_id propertyId,
4142
struct heif_property_camera_intrinsic_matrix** out_matrix)
4243
{
4344
if (!out_matrix || !context) {
4445
return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "NULL passed"};
4546
}
4647

47-
auto cmin = context->context->find_property<Box_cmin>(itemId);
48+
auto cmin = context->context->find_property<Box_cmin>(itemId, propertyId);
4849
if (!cmin) {
49-
return cmin.error.error_struct(context->context.get());
50+
return cmin.error_struct(context->context.get());
5051
}
5152

5253
*out_matrix = new heif_property_camera_intrinsic_matrix;
53-
(*out_matrix)->matrix = cmin.value->get_intrinsic_matrix();
54+
(*out_matrix)->matrix = (*cmin)->get_intrinsic_matrix();
5455

5556
return heif_error_success;
5657
}
@@ -195,11 +196,11 @@ struct heif_error heif_item_get_property_camera_extrinsic_matrix(const struct he
195196

196197
auto cmex = context->context->find_property<Box_cmex>(itemId, propertyId);
197198
if (!cmex) {
198-
return cmex.error.error_struct(context->context.get());
199+
return cmex.error_struct(context->context.get());
199200
}
200201

201202
*out_matrix = new heif_property_camera_extrinsic_matrix;
202-
(*out_matrix)->matrix = cmex.value->get_extrinsic_matrix();
203+
(*out_matrix)->matrix = (*cmex)->get_extrinsic_matrix();
203204

204205
return heif_error_success;
205206
}

libheif/api/libheif/heif_properties.cc

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ struct heif_error heif_item_get_property_user_description(const struct heif_cont
153153
}
154154
auto udes = context->context->find_property<Box_udes>(itemId, propertyId);
155155
if (!udes) {
156-
return udes.error.error_struct(context->context.get());
156+
return udes.error_struct(context->context.get());
157157
}
158158

159159
auto* udes_c = new heif_property_user_description();
160160
udes_c->version = 1;
161-
udes_c->lang = create_c_string_copy(udes.value->get_lang());
162-
udes_c->name = create_c_string_copy(udes.value->get_name());
163-
udes_c->description = create_c_string_copy(udes.value->get_description());
164-
udes_c->tags = create_c_string_copy(udes.value->get_tags());
161+
udes_c->lang = create_c_string_copy((*udes)->get_lang());
162+
udes_c->name = create_c_string_copy((*udes)->get_name());
163+
udes_c->description = create_c_string_copy((*udes)->get_description());
164+
udes_c->tags = create_c_string_copy((*udes)->get_tags());
165165

166166
*out = udes_c;
167167

@@ -218,18 +218,7 @@ enum heif_transform_mirror_direction heif_item_get_property_transform_mirror(con
218218
return heif_transform_mirror_direction_invalid;
219219
}
220220

221-
return imir.value->get_mirror_direction();
222-
}
223-
224-
enum heif_transform_mirror_direction heif_item_get_property_transform_mirror2(const struct heif_context* context,
225-
heif_item_id itemId)
226-
{
227-
auto imir = context->context->find_property<Box_imir>(itemId);
228-
if (!imir) {
229-
return heif_transform_mirror_direction_invalid;
230-
}
231-
232-
return imir.value->get_mirror_direction();
221+
return (*imir)->get_mirror_direction();
233222
}
234223

235224

@@ -242,19 +231,7 @@ int heif_item_get_property_transform_rotation_ccw(const struct heif_context* con
242231
return -1;
243232
}
244233

245-
return irot.value->get_rotation_ccw();
246-
}
247-
248-
249-
int heif_item_get_property_transform_rotation_ccw2(const struct heif_context* context,
250-
heif_item_id itemId)
251-
{
252-
auto irot = context->context->find_property<Box_irot>(itemId);
253-
if (!irot) {
254-
return -1;
255-
}
256-
257-
return irot.value->get_rotation_ccw();
234+
return (*irot)->get_rotation_ccw();
258235
}
259236

260237
void heif_item_get_property_transform_crop_borders(const struct heif_context* context,
@@ -268,29 +245,13 @@ void heif_item_get_property_transform_crop_borders(const struct heif_context* co
268245
return;
269246
}
270247

271-
if (left) *left = clap.value->left_rounded(image_width);
272-
if (right) *right = image_width - 1 - clap.value->right_rounded(image_width);
273-
if (top) *top = clap.value->top_rounded(image_height);
274-
if (bottom) *bottom = image_height - 1 - clap.value->bottom_rounded(image_height);
248+
if (left) *left = (*clap)->left_rounded(image_width);
249+
if (right) *right = image_width - 1 - (*clap)->right_rounded(image_width);
250+
if (top) *top = (*clap)->top_rounded(image_height);
251+
if (bottom) *bottom = image_height - 1 - (*clap)->bottom_rounded(image_height);
275252
}
276253

277254

278-
void heif_item_get_property_transform_crop_borders2(const struct heif_context* context,
279-
heif_item_id itemId,
280-
int image_width, int image_height,
281-
int* left, int* top, int* right, int* bottom)
282-
{
283-
auto clap = context->context->find_property<Box_clap>(itemId);
284-
if (!clap) {
285-
return;
286-
}
287-
288-
if (left) *left = clap.value->left_rounded(image_width);
289-
if (right) *right = image_width - 1 - clap.value->right_rounded(image_width);
290-
if (top) *top = clap.value->top_rounded(image_height);
291-
if (bottom) *bottom = image_height - 1 - clap.value->bottom_rounded(image_height);
292-
}
293-
294255
struct heif_error heif_item_add_raw_property(const struct heif_context* context,
295256
heif_item_id itemId,
296257
uint32_t short_type,
@@ -333,15 +294,15 @@ struct heif_error heif_item_get_property_raw_size(const struct heif_context* con
333294
}
334295
auto box_other = context->context->find_property<Box_other>(itemId, propertyId);
335296
if (!box_other) {
336-
return box_other.error.error_struct(context->context.get());
297+
return box_other.error_struct(context->context.get());
337298
}
338299

339300
// TODO: every Box (not just Box_other) should have a get_raw_data() method.
340-
if (box_other.value == nullptr) {
301+
if (*box_other == nullptr) {
341302
return {heif_error_Usage_error, heif_suberror_Invalid_property, "this property is not read as a raw box"};
342303
}
343304

344-
const auto& data = box_other.value->get_raw_data();
305+
const auto& data = (*box_other)->get_raw_data();
345306

346307
*size_out = data.size();
347308

@@ -360,16 +321,15 @@ struct heif_error heif_item_get_property_raw_data(const struct heif_context* con
360321

361322
auto box_other = context->context->find_property<Box_other>(itemId, propertyId);
362323
if (!box_other) {
363-
return box_other.error.error_struct(context->context.get());
324+
return box_other.error_struct(context->context.get());
364325
}
365326

366327
// TODO: every Box (not just Box_other) should have a get_raw_data() method.
367-
if (box_other.value == nullptr) {
328+
if (*box_other == nullptr) {
368329
return {heif_error_Usage_error, heif_suberror_Invalid_property, "this property is not read as a raw box"};
369330
}
370331

371-
auto data = box_other.value->get_raw_data();
372-
332+
auto data = (*box_other)->get_raw_data();
373333

374334
std::copy(data.begin(), data.end(), data_out);
375335

@@ -388,14 +348,14 @@ struct heif_error heif_item_get_property_uuid_type(const struct heif_context* co
388348

389349
auto box_other = context->context->find_property<Box_other>(itemId, propertyId);
390350
if (!box_other) {
391-
return box_other.error.error_struct(context->context.get());
351+
return box_other.error_struct(context->context.get());
392352
}
393353

394-
if (box_other.value == nullptr) {
354+
if (*box_other == nullptr) {
395355
return {heif_error_Usage_error, heif_suberror_Invalid_property, "this property is not read as a raw box"};
396356
}
397357

398-
auto uuid = box_other.value->get_uuid_type();
358+
auto uuid = (*box_other)->get_uuid_type();
399359

400360
std::copy(uuid.begin(), uuid.end(), extended_type);
401361

libheif/api/libheif/heif_properties.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,51 +112,31 @@ enum heif_transform_mirror_direction
112112
};
113113

114114
// Will return 'heif_transform_mirror_direction_invalid' in case of error.
115-
// DEPRECATED - use version that does not take a propertyId since there can only ever be one imir property
115+
// If 'propertyId==0', it returns the first imir property found.
116116
LIBHEIF_API
117117
enum heif_transform_mirror_direction heif_item_get_property_transform_mirror(const heif_context* context,
118118
heif_item_id itemId,
119119
heif_property_id propertyId);
120120

121-
// Will return 'heif_transform_mirror_direction_invalid' in case of error.
122-
LIBHEIF_API
123-
enum heif_transform_mirror_direction heif_item_get_property_transform_mirror2(const heif_context* context,
124-
heif_item_id itemId);
125-
126121
// Returns only 0, 90, 180, or 270 angle values.
127122
// Returns -1 in case of error (but it will only return an error in case of wrong usage).
128-
// DEPRECATED - use version that does not take a propertyId since there can only ever be one irot property
123+
// If 'propertyId==0', it returns the first irot property found.
129124
LIBHEIF_API
130125
int heif_item_get_property_transform_rotation_ccw(const heif_context* context,
131126
heif_item_id itemId,
132127
heif_property_id propertyId);
133128

134-
// Returns only 0, 90, 180, or 270 angle values.
135-
// Returns -1 in case of error (but it will only return an error in case of wrong usage).
136-
LIBHEIF_API
137-
int heif_item_get_property_transform_rotation_ccw2(const heif_context* context,
138-
heif_item_id itemId);
139-
140129
// Returns the number of pixels that should be removed from the four edges.
141130
// Because of the way this data is stored, you have to pass the image size at the moment of the crop operation
142131
// to compute the cropped border sizes.
132+
// If 'propertyId==0', it returns the first clap property found.
143133
LIBHEIF_API
144134
void heif_item_get_property_transform_crop_borders(const heif_context* context,
145135
heif_item_id itemId,
146136
heif_property_id propertyId,
147137
int image_width, int image_height,
148138
int* left, int* top, int* right, int* bottom);
149139

150-
// Returns the number of pixels that should be removed from the four edges.
151-
// Because of the way this data is stored, you have to pass the image size at the moment of the crop operation
152-
// to compute the cropped border sizes.
153-
// DEPRECATED - use version that does not take a propertyId since there can only ever be one clap property
154-
LIBHEIF_API
155-
void heif_item_get_property_transform_crop_borders2(const heif_context* context,
156-
heif_item_id itemId,
157-
int image_width, int image_height,
158-
int* left, int* top, int* right, int* bottom);
159-
160140
/**
161141
* @param context The heif_context for the file
162142
* @param itemId The image item id to which this property belongs.

libheif/context.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,18 @@ class HeifContext : public ErrorBuffer
228228
{
229229
auto file = this->get_heif_file();
230230

231+
// For propertyId == 0, return the first property with this type.
232+
if (propertyId == 0) {
233+
return find_property<T>(itemId);
234+
}
235+
231236
std::vector<std::shared_ptr<Box>> properties;
232237
Error err = file->get_properties(itemId, properties);
233238
if (err) {
234239
return err;
235240
}
236241

237-
if (propertyId < 1 || propertyId - 1 >= properties.size()) {
242+
if (propertyId - 1 >= properties.size()) {
238243
Error(heif_error_Usage_error, heif_suberror_Invalid_property, "property index out of range");
239244
}
240245

0 commit comments

Comments
 (0)