Bump github.com/davidbyttow/govips/v2 from 2.15.0 to 2.16.0

Bumps [github.com/davidbyttow/govips/v2](https://github.com/davidbyttow/govips) from 2.15.0 to 2.16.0.
- [Release notes](https://github.com/davidbyttow/govips/releases)
- [Commits](https://github.com/davidbyttow/govips/compare/v2.15.0...v2.16.0)

---
updated-dependencies:
- dependency-name: github.com/davidbyttow/govips/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot]
2025-02-10 15:02:04 +00:00
committed by GitHub
parent c5c81546e8
commit c8c83dd9b9
9 changed files with 145 additions and 45 deletions
+1 -1
View File
@@ -526,7 +526,7 @@ static SaveParams defaultSaveParams = {
.stripMetadata = FALSE,
.jpegOptimizeCoding = FALSE,
.jpegSubsample = VIPS_FOREIGN_JPEG_SUBSAMPLE_ON,
.jpegSubsample = VIPS_FOREIGN_SUBSAMPLE_ON,
.jpegTrellisQuant = FALSE,
.jpegOvershootDeringing = FALSE,
.jpegOptimizeScans = FALSE,
+23 -13
View File
@@ -6,13 +6,12 @@ import (
"bytes"
"encoding/xml"
"fmt"
"golang.org/x/image/bmp"
"golang.org/x/net/html/charset"
"image/png"
"math"
"runtime"
"unsafe"
"golang.org/x/image/bmp"
"golang.org/x/net/html/charset"
)
// SubsampleMode correlates to a libvips subsample mode
@@ -20,10 +19,10 @@ type SubsampleMode int
// SubsampleMode enum correlating to libvips subsample modes
const (
VipsForeignSubsampleAuto SubsampleMode = C.VIPS_FOREIGN_JPEG_SUBSAMPLE_AUTO
VipsForeignSubsampleOn SubsampleMode = C.VIPS_FOREIGN_JPEG_SUBSAMPLE_ON
VipsForeignSubsampleOff SubsampleMode = C.VIPS_FOREIGN_JPEG_SUBSAMPLE_OFF
VipsForeignSubsampleLast SubsampleMode = C.VIPS_FOREIGN_JPEG_SUBSAMPLE_LAST
VipsForeignSubsampleAuto SubsampleMode = C.VIPS_FOREIGN_SUBSAMPLE_AUTO
VipsForeignSubsampleOn SubsampleMode = C.VIPS_FOREIGN_SUBSAMPLE_ON
VipsForeignSubsampleOff SubsampleMode = C.VIPS_FOREIGN_SUBSAMPLE_OFF
VipsForeignSubsampleLast SubsampleMode = C.VIPS_FOREIGN_SUBSAMPLE_LAST
)
// ImageType represents an image type
@@ -154,14 +153,14 @@ func DetermineImageType(buf []byte) ImageType {
return ImageTypeHEIF
} else if isSVG(buf) {
return ImageTypeSVG
} else if isPDF(buf) {
return ImageTypePDF
} else if isBMP(buf) {
return ImageTypeBMP
} else if isJP2K(buf) {
return ImageTypeJP2K
} else if isJXL(buf) {
return ImageTypeJXL
} else if isPDF(buf) {
return ImageTypePDF
} else {
return ImageTypeUnknown
}
@@ -240,7 +239,10 @@ func isSVG(buf []byte) bool {
var pdf = []byte("\x25\x50\x44\x46")
func isPDF(buf []byte) bool {
return bytes.HasPrefix(buf, pdf)
if len(buf) <= 1024 {
return bytes.Contains(buf, pdf)
}
return bytes.Contains(buf[:1024], pdf)
}
var bmpHeader = []byte("BM")
@@ -257,10 +259,14 @@ func isJP2K(buf []byte) bool {
return bytes.HasPrefix(buf, jp2kHeader)
}
// As a 'naked' codestream
var jxlHeader = []byte("\xff\x0a")
// As an ISOBMFF-based container: 0x0000000C 4A584C20 0D0A870A
var jxlHeaderISOBMFF = []byte("\x00\x00\x00\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A")
func isJXL(buf []byte) bool {
return bytes.HasPrefix(buf, jxlHeader)
return bytes.HasPrefix(buf, jxlHeader) || bytes.HasPrefix(buf, jxlHeaderISOBMFF)
}
func vipsLoadFromBuffer(buf []byte, params *ImportParams) (*C.VipsImage, ImageType, ImageType, error) {
@@ -352,7 +358,7 @@ func vipsSaveJPEGToBuffer(in *C.VipsImage, params JpegExportParams) ([]byte, err
p.quality = C.int(params.Quality)
p.interlace = C.int(boolToInt(params.Interlace))
p.jpegOptimizeCoding = C.int(boolToInt(params.OptimizeCoding))
p.jpegSubsample = C.VipsForeignJpegSubsample(params.SubsampleMode)
p.jpegSubsample = C.VipsForeignSubsample(params.SubsampleMode)
p.jpegTrellisQuant = C.int(boolToInt(params.TrellisQuant))
p.jpegOvershootDeringing = C.int(boolToInt(params.OvershootDeringing))
p.jpegOptimizeScans = C.int(boolToInt(params.OptimizeScans))
@@ -408,6 +414,10 @@ func vipsSaveTIFFToBuffer(in *C.VipsImage, params TiffExportParams) ([]byte, err
p.stripMetadata = C.int(boolToInt(params.StripMetadata))
p.quality = C.int(params.Quality)
p.tiffCompression = C.VipsForeignTiffCompression(params.Compression)
p.tiffPyramid = C.int(boolToInt(params.Pyramid))
p.tiffTile = C.int(boolToInt(params.Tile))
p.tiffTileHeight = C.int(params.TileHeight)
p.tiffTileWidth = C.int(params.TileWidth)
return vipsSaveToBuffer(p)
}
@@ -457,7 +467,7 @@ func vipsSaveJP2KToBuffer(in *C.VipsImage, params Jp2kExportParams) ([]byte, err
p.jp2kLossless = C.int(boolToInt(params.Lossless))
p.jp2kTileWidth = C.int(params.TileWidth)
p.jp2kTileHeight = C.int(params.TileHeight)
p.jpegSubsample = C.VipsForeignJpegSubsample(params.SubsampleMode)
p.jpegSubsample = C.VipsForeignSubsample(params.SubsampleMode)
return vipsSaveToBuffer(p)
}
+1 -1
View File
@@ -84,7 +84,7 @@ typedef struct SaveParams {
// JPEG
BOOL jpegOptimizeCoding;
VipsForeignJpegSubsample jpegSubsample;
VipsForeignSubsample jpegSubsample;
BOOL jpegTrellisQuant;
BOOL jpegOvershootDeringing;
BOOL jpegOptimizeScans;
+3 -3
View File
@@ -96,8 +96,6 @@ func Startup(config *Config) {
panic(fmt.Sprintf("Failed to start vips code=%v", err))
}
initializeICCProfiles()
running = true
if config != nil {
@@ -185,7 +183,9 @@ func Shutdown() {
return
}
os.RemoveAll(temporaryDirectory)
if temporaryDirectory != "" {
os.RemoveAll(temporaryDirectory)
}
C.vips_shutdown()
disableLogging()
+72 -21
View File
@@ -1,9 +1,9 @@
package vips
import (
"fmt"
"os"
"path/filepath"
"sync"
)
var (
@@ -644,32 +644,83 @@ var (
0x00, 0x20, 0x63, 0xcf, 0x8f, 0xf0, 0x65, 0x87, 0x4e, 0xf6, 0x00, 0x00,
}
temporaryDirectory = temporaryDirectoryOrPanic()
SRGBV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "srgb_v2_micro.icc")
SGrayV2MicroICCProfilePath = filepath.Join(temporaryDirectory, "sgray_v2_micro.icc")
SRGBIEC6196621ICCProfilePath = filepath.Join(temporaryDirectory, "srgb_iec61966_2_1.icc")
GenericGrayGamma22ICCProfilePath = filepath.Join(temporaryDirectory, "generic_gray_gamma_2_2.icc")
sRGBV2MicroICCProfilePathToken = "\x00srgb_v2_micro.icc"
sGrayV2MicroICCProfilePathToken = "\x00sgray_v2_micro.icc"
sRGBIEC6196621ICCProfilePathToken = "\x00srgb_iec61966_2_1.icc"
genericGrayGamma22ICCProfilePathToken = "\x00generic_gray_gamma_2_2.icc"
temporaryDirectory = ""
SRGBV2MicroICCProfilePath = sRGBV2MicroICCProfilePathToken
SGrayV2MicroICCProfilePath = sGrayV2MicroICCProfilePathToken
SRGBIEC6196621ICCProfilePath = sRGBIEC6196621ICCProfilePathToken
GenericGrayGamma22ICCProfilePath = genericGrayGamma22ICCProfilePathToken
)
func initializeICCProfiles() {
storeIccProfile(SRGBV2MicroICCProfilePath, sRGBV2MicroICCProfile)
storeIccProfile(SGrayV2MicroICCProfilePath, sGrayV2MicroICCProfile)
storeIccProfile(SRGBIEC6196621ICCProfilePath, sRGBIEC6196621ICCProfile)
storeIccProfile(GenericGrayGamma22ICCProfilePath, genericGrayGamma22ICCProfile)
}
func storeIccProfile(path string, data []byte) {
err := os.WriteFile(path, data, 0600)
if err != nil {
panic(fmt.Sprintf("Couldn't store temporary file for ICC profile in '%v': %v", path, err.Error()))
// Back support
func ensureLoadICCPath(name *string) (err error) {
if len(*name) > 0 && (*name)[0] == 0 {
switch *name {
case sRGBV2MicroICCProfilePathToken:
*name, err = GetSRGBV2MicroICCProfilePath()
return
case sGrayV2MicroICCProfilePathToken:
*name, err = GetSGrayV2MicroICCProfilePath()
return
case sRGBIEC6196621ICCProfilePathToken:
*name, err = GetSRGBIEC6196621ICCProfilePath()
return
case genericGrayGamma22ICCProfilePathToken:
*name, err = GetGenericGrayGamma22ICCProfilePath()
return
}
}
return
}
func temporaryDirectoryOrPanic() string {
temporaryDirectory, err := os.MkdirTemp("", "govips-")
func getTemporaryDirectory() (string, error) {
if temporaryDirectory != "" {
return temporaryDirectory, nil
}
var err error
temporaryDirectory, err = os.MkdirTemp("", "govips-")
if err != nil {
panic(fmt.Sprintf("Couldn't create temporary directory: %v", err.Error()))
return "", err
}
return temporaryDirectory, nil
}
var lockIcc sync.Mutex
func GetSRGBV2MicroICCProfilePath() (string, error) {
return getOrLoad(&SRGBV2MicroICCProfilePath, "srgb_v2_micro.icc", sRGBV2MicroICCProfile)
}
func GetSGrayV2MicroICCProfilePath() (string, error) {
return getOrLoad(&SGrayV2MicroICCProfilePath, "sgray_v2_micro.icc", sGrayV2MicroICCProfile)
}
func GetSRGBIEC6196621ICCProfilePath() (string, error) {
return getOrLoad(&SRGBIEC6196621ICCProfilePath, "srgb_iec61966_2_1.icc", sRGBIEC6196621ICCProfile)
}
func GetGenericGrayGamma22ICCProfilePath() (string, error) {
return getOrLoad(&GenericGrayGamma22ICCProfilePath, "generic_gray_gamma_2_2.icc", genericGrayGamma22ICCProfile)
}
func getOrLoad(pathFile *string, name string, fileBytes []byte) (string, error) {
lockIcc.Lock()
defer lockIcc.Unlock()
if len(*pathFile) > 0 && (*pathFile)[0] != 0 {
return *pathFile, nil
}
return temporaryDirectory
if _, err := getTemporaryDirectory(); err != nil {
return "", err
}
*pathFile = filepath.Join(temporaryDirectory, name)
if err := os.WriteFile(*pathFile, fileBytes, 0600); err != nil {
return "", err
}
return *pathFile, nil
}
+22
View File
@@ -8,6 +8,9 @@ import (
"errors"
"fmt"
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io"
"os"
"runtime"
@@ -303,6 +306,10 @@ type TiffExportParams struct {
Quality int
Compression TiffCompression
Predictor TiffPredictor
Pyramid bool
Tile bool
TileHeight int
TileWidth int
}
// NewTiffExportParams creates default values for an export of a TIFF image.
@@ -311,6 +318,10 @@ func NewTiffExportParams() *TiffExportParams {
Quality: 80,
Compression: TiffCompressionLzw,
Predictor: TiffPredictorHorizontal,
Pyramid: false,
Tile: false,
TileHeight: 256,
TileWidth: 256,
}
}
@@ -1391,6 +1402,13 @@ func (r *ImageRef) RemoveICCProfile() error {
// TransformICCProfileWithFallback transforms from the embedded ICC profile of the image to the ICC profile at the given path.
// The fallback ICC profile is used if the image does not have an embedded ICC profile.
func (r *ImageRef) TransformICCProfileWithFallback(targetProfilePath, fallbackProfilePath string) error {
if err := ensureLoadICCPath(&targetProfilePath); err != nil {
return err
}
if err := ensureLoadICCPath(&fallbackProfilePath); err != nil {
return err
}
depth := 16
if r.BandFormat() == BandFormatUchar || r.BandFormat() == BandFormatChar || r.BandFormat() == BandFormatNotSet {
depth = 8
@@ -1426,6 +1444,10 @@ func (r *ImageRef) OptimizeICCProfile() error {
r.optimizedIccProfile = SGrayV2MicroICCProfilePath
}
if err := ensureLoadICCPath(&r.optimizedIccProfile); err != nil {
return err
}
embedded := r.HasICCProfile() && (inputProfile == "")
depth := 16