Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/getpoint
Browse files Browse the repository at this point in the history
# Conflicts:
#	vips/image_golden_test.go
  • Loading branch information
cshum committed Nov 28, 2021
2 parents 6a0cc06 + 52c8c67 commit 164d1c3
Show file tree
Hide file tree
Showing 167 changed files with 1,824 additions and 1,044 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BasedOnStyle: Google
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
CGO_CFLAGS_ALLOW: -Xpreprocessor
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04, macOS-10.15]
os: [ubuntu-20.04, macos-11]

steps:
- name: Set up Go 1.x
Expand All @@ -22,13 +22,15 @@ jobs:
uses: actions/checkout@v2

- name: Install linux deps
if: matrix.os == 'ubuntu-18.04' || matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-20.04'
run: |
sudo add-apt-repository -y ppa:strukturag/libde265
sudo add-apt-repository -y ppa:strukturag/libheif
sudo add-apt-repository -y ppa:tonimelisma/ppa
sudo apt-get -y install libvips-dev
- name: Install macos deps
if: matrix.os == 'macos-10.15'
if: matrix.os == 'macos-11'
run: |
brew install vips
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ build: FORCE
test: FORCE
CGO_CFLAGS_ALLOW=-Xpreprocessor go test -v ./...

FORCE:
FORCE:
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# <img src="https://raw.githubusercontent.com/davidbyttow/govips/master/assets/SVG/govips.svg" width="90" height="90"> <span style="font-size: 4em;">govips</span>

[![GoDoc](https://godoc.org/github.com/davidbyttow/govips?status.svg)](https://pkg.go.dev/mod/github.com/davidbyttow/govips/v2) [![Go Report Card](http://goreportcard.com/badge/davidbyttow/govips)](http://goreportcard.com/report/davidbyttow/govips) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/davidbyttow/govips) ![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://github.com/davidbyttow/govips/workflows/build/badge.svg)](https://github.com/davidbyttow/govips/actions) [![Coverage Status](https://img.shields.io/coveralls/github/davidbyttow/govips)](https://coveralls.io/github/davidbyttow/govips?branch=master)

## A lightning fast image processing and resizing library for Go

This package wraps the core functionality of [libvips](https://github.com/libvips/libvips) image processing library by exposing all image operations on first-class types in Go.
Expand All @@ -26,9 +28,11 @@ brew install vips pkg-config

### Ubuntu

You need at least libvips 8.10.2 to work with govips. Groovy (20.10) repositories have the latest version. However on Bionic (18.04) and Focal (20.04), you need to install libvips and dependencies from a backports repository:
You need a recent libvips to work with govips. New govips functionality is continuously added which takes advantage of new libvips functionality. Groovy (20.10) and Hirsute (21.04) repositories have working versions. However on Focal (20.04), you need to install libvips and dependencies from a backports repository:

```bash
sudo add-apt-repository -y ppa:strukturag/libde265
sudo add-apt-repository -y ppa:strukturag/libheif
sudo add-apt-repository ppa:tonimelisma/ppa
```

Expand Down Expand Up @@ -97,14 +101,28 @@ func main() {
}
```

See *examples/* folder for more examples.
See _examples/_ folder for more examples.

## Running tests

```bash
$ make test
```

## Memory usage note
### MALLOC_ARENA_MAX
`libvips` uses GLib for memory management, and it brings GLib memory fragmentation
issues to heavily multi-threaded programs. First thing you can try if you noticed
constantly growing RSS usage without Go's sys memory growth is set `MALLOC_ARENA_MAX`:

```
MALLOC_ARENA_MAX=2 application
```

This will reduce GLib memory appetites by reducing the number of malloc arenas
that it can create. By default GLib creates one are per thread, and this would
follow to a memory fragmentation.

## Contributing

Feel free to file issues or create pull requests. See this [guide on contributing](https://github.com/davidbyttow/govips/blob/master/CONTRIBUTING.md) for more information.
Expand All @@ -120,4 +138,4 @@ Thanks to:

## License

MIT - David Byttow
MIT
4 changes: 3 additions & 1 deletion build/Dockerfile-ubuntu-20.04
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ RUN apt-get -y --no-install-recommends install software-properties-common gpg-ag
RUN apt-get -y --no-install-recommends install \
build-essential devscripts lsb-release dput wget git golang nvi
RUN add-apt-repository -y ppa:tonimelisma/ppa
RUN add-apt-repository -y ppa:strukturag/libheif
RUN add-apt-repository -y ppa:strukturag/libde265
RUN apt-get -y install --no-install-recommends libvips-dev
RUN go get golang.org/dl/go1.15.4
RUN ~/go/bin/go1.15.4 download
Expand All @@ -24,4 +26,4 @@ ENV DEBEMAIL="[email protected]"
ENV PPANAME="tonimelisma"
ENV DISTRIBUTION="focal"
ENV DISTVERSION="20.04"
ENV PACKAGE="vips"
ENV PACKAGE="vips"
Binary file added resources/avif.avif
Binary file not shown.
Binary file added resources/bmp.Decode_BMP-macos-10.golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gif-animated-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gif-animated.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/has-icc-profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified resources/heic-24bit-exif.RemoveMetadata-macos-11.golden.heic
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/jpg-24bit.Add-linux-bionic.golden.jpeg
Diff not rendered.
Binary file modified resources/jpg-24bit.Add-linux-focal.golden.jpeg
Binary file added resources/jpg-24bit.Add-macos-10.golden.jpeg
Binary file added resources/jpg-24bit.Black-macos-10.golden.jpeg
Binary file added resources/jpg-24bit.DrawRect-macos-10.golden.jpeg
Binary file added resources/jpg-24bit.Embed-macos-10.golden.jpeg
Binary file added resources/jpg-24bit.Flip-macos-10.golden.jpeg
Binary file added resources/jpg-24bit.Invert-macos-10.golden.jpeg
Binary file modified resources/jpg-24bit.Multiply-linux-focal.golden.jpeg
Binary file added resources/jpg-24bit.Multiply-macos-10.golden.jpeg
Binary file modified resources/jpg-24bit.TestImageRef_Divide-linux-focal.golden.jpeg
Binary file added resources/jpg-24bit.Zoom-macos-10.golden.jpeg
Binary file not shown.
Binary file not shown.
Binary file added resources/png-24bit.Rank-linux-focal.golden.png
Binary file added resources/png-24bit.Rank-linux-hirsute.golden.png
Binary file added resources/png-8bit.Decode_PNG-macos-10.golden.png
Binary file not shown.
Binary file added resources/tif.Tiff-macos-10.golden.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added resources/webp-animated.webp
Binary file not shown.
Binary file added resources/with_alpha.ExtractBand-macos-10.golden.png
Binary file added resources/with_alpha.Flatten-macos-10.golden.png
42 changes: 9 additions & 33 deletions vips/color.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "color.h"

#include <unistd.h>

int is_colorspace_supported(VipsImage *in) {
Expand All @@ -11,36 +10,13 @@ int to_colorspace(VipsImage *in, VipsImage **out, VipsInterpretation space) {
}

// https://libvips.github.io/libvips/API/8.6/libvips-colour.html#vips-icc-transform
int optimize_icc_profile(VipsImage *in, VipsImage **out, int isCmyk,
char *srgb_profile_path, char *gray_profile_path) {
// todo: check current embedded profile, and skip if already set

int channels = vips_image_get_bands(in);
int result;

if (vips_icc_present() == 0) {
return 1;
}

if (channels > 2) {
if (isCmyk == 1) {
result =
vips_icc_transform(in, out, srgb_profile_path, "input_profile",
"cmyk", "intent", VIPS_INTENT_PERCEPTUAL, NULL);
} else {
result = vips_icc_transform(in, out, srgb_profile_path, "embedded", TRUE,
"intent", VIPS_INTENT_PERCEPTUAL, NULL);
// ignore embedded errors
if (result != 0) {
result = 0;
*out = in;
}
}
} else {
result = vips_icc_transform(in, out, gray_profile_path, "input_profile",
gray_profile_path, "embedded", TRUE, "intent",
VIPS_INTENT_PERCEPTUAL, NULL);
}

return result;
int icc_transform(VipsImage *in, VipsImage **out, const char *output_profile, const char *input_profile, VipsIntent intent,
int depth, gboolean embedded) {
return vips_icc_transform(
in, out, output_profile,
"input_profile", input_profile ? input_profile : "none",
"intent", intent,
"depth", depth ? depth : 8,
"embedded", embedded,
NULL);
}
37 changes: 29 additions & 8 deletions vips/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vips
// #include "color.h"
import "C"
import (
"path/filepath"
"unsafe"
)

Expand Down Expand Up @@ -38,12 +37,25 @@ const (
InterpretationSRGB Interpretation = C.VIPS_INTERPRETATION_sRGB
InterpretationYXY Interpretation = C.VIPS_INTERPRETATION_YXY
InterpretationFourier Interpretation = C.VIPS_INTERPRETATION_FOURIER
InterpretationGB16 Interpretation = C.VIPS_INTERPRETATION_RGB16
InterpretationGrey16 Interpretation = C.VIPS_INTERPRETATION_GREY16
InterpretationMatrix Interpretation = C.VIPS_INTERPRETATION_MATRIX
InterpretationScRGB Interpretation = C.VIPS_INTERPRETATION_scRGB
InterpretationHSV Interpretation = C.VIPS_INTERPRETATION_HSV
)

// Intent represents VIPS_INTENT type
type Intent int

//Intent enum
const (
IntentPerceptual Intent = C.VIPS_INTENT_PERCEPTUAL
IntentRelative Intent = C.VIPS_INTENT_RELATIVE
IntentSaturation Intent = C.VIPS_INTENT_SATURATION
IntentAbsolute Intent = C.VIPS_INTENT_ABSOLUTE
IntentLast Intent = C.VIPS_INTENT_LAST
)

func vipsIsColorSpaceSupported(in *C.VipsImage) bool {
return C.is_colorspace_supported(in) == 1
}
Expand All @@ -62,18 +74,27 @@ func vipsToColorSpace(in *C.VipsImage, interpretation Interpretation) (*C.VipsIm
return out, nil
}

func vipsOptimizeICCProfile(in *C.VipsImage, isCmyk int) (*C.VipsImage, error) {
func vipsICCTransform(in *C.VipsImage, outputProfile string, inputProfile string, intent Intent, depth int,
embedded bool) (*C.VipsImage, error) {
var out *C.VipsImage
var cInputProfile *C.char
var cEmbedded C.gboolean

srgbProfilePath := C.CString(filepath.Join(temporaryDirectory, sRGBV2MicroICCProfilePath))
grayProfilePath := C.CString(filepath.Join(temporaryDirectory, sGrayV2MicroICCProfilePath))
cOutputProfile := C.CString(outputProfile)
defer C.free(unsafe.Pointer(cOutputProfile))

if res := int(C.optimize_icc_profile(in, &out, C.int(isCmyk), srgbProfilePath, grayProfilePath)); res != 0 {
return nil, handleImageError(out)
if inputProfile != "" {
cInputProfile = C.CString(inputProfile)
defer C.free(unsafe.Pointer(cInputProfile))
}

C.free(unsafe.Pointer(srgbProfilePath))
C.free(unsafe.Pointer(grayProfilePath))
if embedded {
cEmbedded = C.TRUE
}

if res := C.icc_transform(in, &out, cOutputProfile, cInputProfile, C.VipsIntent(intent), C.int(depth), cEmbedded); res != 0 {
return nil, handleImageError(out)
}

return out, nil
}
3 changes: 2 additions & 1 deletion vips/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
int is_colorspace_supported(VipsImage *in);
int to_colorspace(VipsImage *in, VipsImage **out, VipsInterpretation space);

int optimize_icc_profile(VipsImage *in, VipsImage **out, int isCmyk, char *srgb_profile_path, char *gray_profile_path);
int icc_transform(VipsImage *in, VipsImage **out, const char *output_profile, const char *input_profile, VipsIntent intent,
int depth, gboolean embedded);
8 changes: 8 additions & 0 deletions vips/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,12 @@ int insert_image(VipsImage *main, VipsImage *sub, VipsImage **out, int x, int y,
vips_area_unref(VIPS_AREA(vipsBackground));

return code;
}

int join(VipsImage *in1, VipsImage *in2, VipsImage **out, int direction) {
return vips_join(in1, in2, out, direction, NULL);
}

int arrayjoin(VipsImage **in, VipsImage **out, int n, int across) {
return vips_arrayjoin(in, out, n, "across", across, NULL);
}
24 changes: 24 additions & 0 deletions vips/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,27 @@ func vipsInsert(main *C.VipsImage, sub *C.VipsImage, x, y int, expand bool, back

return out, nil
}

// https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-join
func vipsJoin(input1 *C.VipsImage, input2 *C.VipsImage, dir Direction) (*C.VipsImage, error) {
incOpCounter("join")
var out *C.VipsImage

defer C.g_object_unref(C.gpointer(input1))
defer C.g_object_unref(C.gpointer(input2))
if err := C.join(input1, input2, &out, C.int(dir)); err != 0 {
return nil, handleVipsError()
}
return out, nil
}

// https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-arrayjoin
func vipsArrayJoin(inputs []*C.VipsImage, across int) (*C.VipsImage, error) {
incOpCounter("arrayjoin")
var out *C.VipsImage

if err := C.arrayjoin(&inputs[0], &out, C.int(len(inputs)), C.int(across)); err != 0 {
return nil, handleVipsError()
}
return out, nil
}
3 changes: 3 additions & 0 deletions vips/conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ int composite2_image(VipsImage *base, VipsImage *overlay, VipsImage **out,
int insert_image(VipsImage *main, VipsImage *sub, VipsImage **out, int x, int y,
int expand, double r, double g, double b, double a);

int join(VipsImage *in1, VipsImage *in2, VipsImage **out, int direction);
int arrayjoin(VipsImage **in, VipsImage **out, int n, int across);

int is_16bit(VipsInterpretation interpretation);
Loading

0 comments on commit 164d1c3

Please sign in to comment.