-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from klippa-app/feature/improve-libjpeg-turbo
Improve libjpegturbo
- Loading branch information
Showing
10 changed files
with
292 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: lib-jpeg-turbo | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- development | ||
pull_request: | ||
branches: | ||
- main | ||
- development | ||
|
||
jobs: | ||
test-libjpegturbo: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ ubuntu-latest, macos-latest, windows-latest ] | ||
go: [ "1.20", "1.21" ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Set up libturbojpeg library (Linux) | ||
if: matrix.os == 'ubuntu-latest' | ||
run: | | ||
sudo apt install libturbojpeg libturbojpeg-dev | ||
- name: Set up jpeg-turbo library (MacOS) | ||
if: matrix.os == 'macos-latest' | ||
run: | | ||
brew install jpeg-turbo | ||
- name: Set up jpeg-turbo library (Windows) | ||
if: matrix.os == 'windows-latest' | ||
run: | | ||
curl -L https://master.dl.sourceforge.net/project/libjpeg-turbo/3.0.0/libjpeg-turbo-3.0.0-gcc64.exe -o libjpeg-turbo-3.0.0-gcc64.exe | ||
./libjpeg-turbo-3.0.0-gcc64.exe /S | ||
$Folder = 'C:\libjpeg-turbo-gcc64\lib\pkgconfig' | ||
while (!(Test-Path -Path $Folder)) { | ||
"libjpeg-turbo does not exist yet!" | ||
Start-Sleep -s 5 | ||
} | ||
- name: Test package (non-Windows) | ||
if: matrix.os != 'windows-latest' | ||
run: | | ||
go test ./internal/image/image_jpeg -tags pdfium_use_turbojpeg -v | ||
- name: Test package (Windows) | ||
if: matrix.os == 'windows-latest' | ||
run: | | ||
$env:PKG_CONFIG_PATH = 'C:\libjpeg-turbo-gcc64\lib\pkgconfig' | ||
go test ./internal/image/image_jpeg -tags pdfium_use_turbojpeg -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build !pdfium_use_turbojpeg | ||
|
||
package image_jpeg | ||
|
||
import ( | ||
"bytes" | ||
"image" | ||
"image/jpeg" | ||
"testing" | ||
) | ||
|
||
func TestEncode(t *testing.T) { | ||
img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{100, 100}}) | ||
testWriter := bytes.NewBuffer(nil) | ||
err := Encode(testWriter, img, Options{}) | ||
if err != nil { | ||
t.Fatalf("Encode resulted in error: %s", err.Error()) | ||
} | ||
if testWriter.Len() != 789 { | ||
t.Fatalf("Encode resulted in wrong byte result, got %d, want %d", testWriter.Len(), 789) | ||
} | ||
} | ||
|
||
func TestEncodeQuality(t *testing.T) { | ||
img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{100, 100}}) | ||
testWriter := bytes.NewBuffer(nil) | ||
err := Encode(testWriter, img, Options{ | ||
Options: &jpeg.Options{ | ||
Quality: 100, | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Encode resulted in error: %s", err.Error()) | ||
} | ||
if testWriter.Len() != 791 { | ||
t.Fatalf("Encode resulted in wrong byte result, got %d, want %d", testWriter.Len(), 791) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build pdfium_use_turbojpeg | ||
|
||
package image_jpeg | ||
|
||
import ( | ||
"bytes" | ||
"image" | ||
"image/jpeg" | ||
"testing" | ||
) | ||
|
||
func TestEncode(t *testing.T) { | ||
img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{100, 100}}) | ||
testWriter := bytes.NewBuffer(nil) | ||
err := Encode(testWriter, img, Options{}) | ||
if err != nil { | ||
t.Fatalf("Encode resulted in error: %s", err.Error()) | ||
} | ||
if testWriter.Len() != 823 { | ||
t.Fatalf("Encode resulted in wrong byte result, got %d, want %d", testWriter.Len(), 823) | ||
} | ||
} | ||
|
||
func TestEncodeQuality(t *testing.T) { | ||
img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{100, 100}}) | ||
testWriter := bytes.NewBuffer(nil) | ||
err := Encode(testWriter, img, Options{ | ||
Options: &jpeg.Options{ | ||
Quality: 100, | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Encode resulted in error: %s", err.Error()) | ||
} | ||
if testWriter.Len() != 825 { | ||
t.Fatalf("Encode resulted in wrong byte result, got %d, want %d", testWriter.Len(), 825) | ||
} | ||
} | ||
|
||
func TestEncodeProgressive(t *testing.T) { | ||
img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{100, 100}}) | ||
testWriter := bytes.NewBuffer(nil) | ||
err := Encode(testWriter, img, Options{ | ||
Options: &jpeg.Options{ | ||
Quality: 100, | ||
}, | ||
Progressive: true, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Encode resulted in error: %s", err.Error()) | ||
} | ||
if testWriter.Len() != 592 { | ||
t.Fatalf("Encode resulted in wrong byte result, got %d, want %d", testWriter.Len(), 592) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package image_jpeg | ||
|
||
import "image/jpeg" | ||
|
||
type Options struct { | ||
*jpeg.Options | ||
Progressive bool // Render in progressive mode, only available with libturbojpeg. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters