Skip to content

Commit ab2e0bf

Browse files
committed
Merge branch '8.13'
2 parents 5fcca56 + fbef674 commit ab2e0bf

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ master
1414
- threaded tiff jp2k and jpeg decompress
1515
- improve speed and efficiency of animated WebP write [dloebl]
1616

17+
11/10/22 started 8.13.3
18+
- improve rules for 16-bit heifsave [johntrunc]
19+
1720
5/9/22 started 8.13.2
1821
- in dzsave, add add missing include directive for errno/EEXIST [kleisauke]
1922
- fix 8 bit pallete PNG save [lovell]

libvips/foreign/heifsave.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* - rename "speed" as "effort" for consistency with other savers
1515
* 22/12/21
1616
* - add >8 bit support
17+
* 22/10/11
18+
* - improve rules for 16-bit write [johntrunc]
1719
*/
1820

1921
/*
@@ -48,21 +50,6 @@
4850
#define DEBUG
4951
*/
5052

51-
/*
52-
*
53-
54-
TODO:
55-
56-
what about a 16-bit PNG saved with bitdepth=8? does this work?
57-
58-
no!
59-
60-
what about a 8-bit PNG saved with bitdepth=12? does this work?
61-
62-
*
63-
*/
64-
65-
6653
#ifdef HAVE_CONFIG_H
6754
#include <config.h>
6855
#endif /*HAVE_CONFIG_H*/
@@ -320,7 +307,7 @@ vips_foreign_save_heif_pack( VipsForeignSaveHeif *heif,
320307

321308
if( heif->image->BandFmt == VIPS_FORMAT_UCHAR &&
322309
heif->bitdepth == 8 )
323-
/* Most common cases -- 8 bit to 8 bit.
310+
/* Most common case -- 8 bit to 8 bit.
324311
*/
325312
memcpy( q, p, ne );
326313
else if( heif->image->BandFmt == VIPS_FORMAT_UCHAR &&
@@ -341,8 +328,14 @@ vips_foreign_save_heif_pack( VipsForeignSaveHeif *heif,
341328
else if( heif->image->BandFmt == VIPS_FORMAT_USHORT &&
342329
heif->bitdepth <= 8 ) {
343330
/* 16-bit native byte order source, 8 bit write.
344-
*/
345-
int shift = 16 - heif->bitdepth;
331+
*
332+
* Pick the high or low bits of the source.
333+
*/
334+
int vips_bitdepth =
335+
heif->image->Type == VIPS_INTERPRETATION_RGB16 ||
336+
heif->image->Type == VIPS_INTERPRETATION_GREY16 ?
337+
16 : 8;
338+
int shift = vips_bitdepth - heif->bitdepth;
346339

347340
for( i = 0; i < ne; i++ ) {
348341
guint16 v = *((gushort *) p) >> shift;
@@ -356,7 +349,11 @@ vips_foreign_save_heif_pack( VipsForeignSaveHeif *heif,
356349
heif->bitdepth > 8 ) {
357350
/* 16-bit native byte order source, 16 bit bigendian write.
358351
*/
359-
int shift = 16 - heif->bitdepth;
352+
int vips_bitdepth =
353+
heif->image->Type == VIPS_INTERPRETATION_RGB16 ||
354+
heif->image->Type == VIPS_INTERPRETATION_GREY16 ?
355+
16 : 8;
356+
int shift = vips_bitdepth - heif->bitdepth;
360357

361358
for( i = 0; i < ne; i++ ) {
362359
guint16 v = *((gushort *) p) >> shift;
@@ -446,25 +443,27 @@ vips_foreign_save_heif_build( VipsObject *object )
446443
build( object ) )
447444
return( -1 );
448445

446+
/* Make a copy of the image in case we modify the metadata eg. for
447+
* exif_update.
448+
*/
449+
if( vips_copy( save->ready, &heif->image, NULL ) )
450+
return( -1 );
451+
449452
/* If the old, deprecated "speed" param is being used and the new
450453
* "effort" param is not, use speed to init effort.
451454
*/
452455
if( vips_object_argument_isset( object, "speed" ) &&
453456
!vips_object_argument_isset( object, "effort" ) )
454457
heif->effort = 9 - heif->speed;
455458

456-
/* Default 12 bit save for ushort. HEIC (for example) implements
459+
/* Default 12 bit save for 16-bit images. HEIC (for example) implements
457460
* 8 / 10 / 12.
458461
*/
459462
if( !vips_object_argument_isset( object, "bitdepth" ) )
460-
heif->bitdepth = save->ready->BandFmt == VIPS_FORMAT_UCHAR ?
461-
8 : 12;
462-
463-
/* Make a copy of the image in case we modify the metadata eg. for
464-
* exif_update.
465-
*/
466-
if( vips_copy( save->ready, &heif->image, NULL ) )
467-
return( -1 );
463+
heif->bitdepth =
464+
heif->image->Type == VIPS_INTERPRETATION_RGB16 ||
465+
heif->image->Type == VIPS_INTERPRETATION_GREY16 ?
466+
12 : 8;
468467

469468
error = heif_context_get_encoder_for_format( heif->ctx,
470469
(enum heif_compression_format) heif->compression,

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ version_patch = version_parts[2]
1919
# binary interface changed: increment current, reset revision to 0
2020
# binary interface changes backwards compatible?: increment age
2121
# binary interface changes not backwards compatible?: reset age to 0
22+
library_revision = 0
2223
library_current = 58
2324
library_age = 16
24-
library_revision = 0
2525
library_version = '@0@.@1@.@2@'.format(library_current - library_age, library_age, library_revision)
2626
darwin_versions = [library_current + 1, '@0@.@1@'.format(library_current + 1, library_revision)]
2727

0 commit comments

Comments
 (0)