Skip to content

Commit 4ef6ae0

Browse files
add claude's tiled heic encoding
1 parent 054059a commit 4ef6ae0

5 files changed

Lines changed: 36 additions & 6 deletions

File tree

config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ var (
5151
PngQuantize bool
5252
PngQuantizationColors int
5353
AvifSpeed int
54+
HeicTileWidth int
55+
HeicTileHeight int
5456
Quality int
5557
FormatQuality map[imagetype.Type]int
5658
StripMetadata bool
@@ -244,6 +246,8 @@ func Reset() {
244246
PngQuantize = false
245247
PngQuantizationColors = 256
246248
AvifSpeed = 9
249+
HeicTileWidth = 0
250+
HeicTileHeight = 0
247251
Quality = 80
248252
FormatQuality = map[imagetype.Type]int{imagetype.AVIF: 65}
249253
StripMetadata = true
@@ -436,6 +440,8 @@ func Configure() error {
436440
configurators.Bool(&PngQuantize, "IMGPROXY_PNG_QUANTIZE")
437441
configurators.Int(&PngQuantizationColors, "IMGPROXY_PNG_QUANTIZATION_COLORS")
438442
configurators.Int(&AvifSpeed, "IMGPROXY_AVIF_SPEED")
443+
configurators.Int(&HeicTileWidth, "IMGPROXY_HEIC_TILE_WIDTH")
444+
configurators.Int(&HeicTileHeight, "IMGPROXY_HEIC_TILE_HEIGHT")
439445
configurators.Int(&Quality, "IMGPROXY_QUALITY")
440446
if err := configurators.ImageTypesQuality(FormatQuality, "IMGPROXY_FORMAT_QUALITY"); err != nil {
441447
return err
@@ -666,6 +672,13 @@ func Configure() error {
666672
return fmt.Errorf("Avif speed can't be greater than 9, now - %d\n", AvifSpeed)
667673
}
668674

675+
if HeicTileWidth < 0 {
676+
return fmt.Errorf("HEIC tile width should be 0 (disabled) or a positive value, now - %d\n", HeicTileWidth)
677+
}
678+
if HeicTileHeight < 0 {
679+
return fmt.Errorf("HEIC tile height should be 0 (disabled) or a positive value, now - %d\n", HeicTileHeight)
680+
}
681+
669682
if Quality <= 0 {
670683
return fmt.Errorf("Quality should be greater than 0, now - %d\n", Quality)
671684
} else if Quality > 100 {

docker/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ RUN apt-get update \
7272
curl \
7373
zstd \
7474
build-essential \
75-
cmake \
76-
git
75+
cmake
7776

78-
RUN pip3 install scikit-image==0.22.0 scipy==1.11.4 opencv-python numpy Pillow dlib==19.24.4 --break-system-packages
77+
RUN CMAKE_BUILD_PARALLEL_LEVEL=1 pip3 install scikit-image==0.22.0 scipy==1.11.4 opencv-python numpy Pillow dlib==19.24.4 --break-system-packages
7978

8079
# https://pushd.slack.com/archives/C07A4MNKDE2/p1755641040891479?thread_ts=1755542357.600459&cid=C07A4MNKDE2
8180
RUN pip3 install git+https://github.com/pushd/pyamg.git@v5.2.0_with_pinned_scm --break-system-packages

vips/vips.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#define VIPS_SUPPORT_GIFSAVE \
1616
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 12))
1717

18+
#define VIPS_SUPPORT_HEIF_TILE \
19+
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 13))
20+
1821
#define VIPS_GIF_RESOLUTION_LIMITED \
1922
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION <= 12)
2023

@@ -919,8 +922,19 @@ vips_tiffsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
919922
}
920923

921924
int
922-
vips_heifsave_go(VipsImage *in, void **buf, size_t *len, int quality)
925+
vips_heifsave_go(VipsImage *in, void **buf, size_t *len, int quality, int tile_width, int tile_height)
923926
{
927+
#if VIPS_SUPPORT_HEIF_TILE
928+
if (tile_width > 0 && tile_height > 0) {
929+
return vips_heifsave_buffer(
930+
in, buf, len,
931+
"Q", quality,
932+
"compression", VIPS_FOREIGN_HEIF_COMPRESSION_HEVC,
933+
"tile_width", tile_width,
934+
"tile_height", tile_height,
935+
NULL);
936+
}
937+
#endif
924938
return vips_heifsave_buffer(
925939
in, buf, len,
926940
"Q", quality,

vips/vips.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ var vipsConf struct {
4747
PngQuantize C.int
4848
PngQuantizationColors C.int
4949
AvifSpeed C.int
50+
HeicTileWidth C.int
51+
HeicTileHeight C.int
5052
}
5153

5254
func Init() error {
@@ -82,6 +84,8 @@ func Init() error {
8284
vipsConf.PngQuantize = gbool(config.PngQuantize)
8385
vipsConf.PngQuantizationColors = C.int(config.PngQuantizationColors)
8486
vipsConf.AvifSpeed = C.int(config.AvifSpeed)
87+
vipsConf.HeicTileWidth = C.int(config.HeicTileWidth)
88+
vipsConf.HeicTileHeight = C.int(config.HeicTileHeight)
8589

8690
prometheus.AddGaugeFunc(
8791
"vips_memory_bytes",
@@ -405,7 +409,7 @@ func (img *Image) Save(imgtype imagetype.Type, quality int) (*imagedata.ImageDat
405409
case imagetype.GIF:
406410
err = C.vips_gifsave_go(img.VipsImage, &ptr, &imgsize)
407411
case imagetype.HEIC:
408-
err = C.vips_heifsave_go(img.VipsImage, &ptr, &imgsize, C.int(quality))
412+
err = C.vips_heifsave_go(img.VipsImage, &ptr, &imgsize, C.int(quality), vipsConf.HeicTileWidth, vipsConf.HeicTileHeight)
409413
case imagetype.AVIF:
410414
err = C.vips_avifsave_go(img.VipsImage, &ptr, &imgsize, C.int(quality), vipsConf.AvifSpeed)
411415
case imagetype.TIFF:

vips/vips.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int q
9797
int colors);
9898
int vips_webpsave_go(VipsImage *in, void **buf, size_t *len, int quality);
9999
int vips_gifsave_go(VipsImage *in, void **buf, size_t *len);
100-
int vips_heifsave_go(VipsImage *in, void **buf, size_t *len, int quality);
100+
int vips_heifsave_go(VipsImage *in, void **buf, size_t *len, int quality, int tile_width, int tile_height);
101101
int vips_avifsave_go(VipsImage *in, void **buf, size_t *len, int quality, int speed);
102102
int vips_tiffsave_go(VipsImage *in, void **buf, size_t *len, int quality);
103103

0 commit comments

Comments
 (0)