[QOI] Add support for RGB images (previously loader always output RGBA).

Also add QOI to CI test suite by roundtripping 8-bit RGB(A) through QOI and checking the hashes match.
This commit is contained in:
Jeroen van Rijn
2022-04-12 19:23:48 +02:00
parent ab9457346d
commit bf712e9355
2 changed files with 44 additions and 19 deletions
+29 -5
View File
@@ -5,7 +5,7 @@
List of contributors:
Jeroen van Rijn: Initial implementation.
A test suite for PNG.
A test suite for PNG + QOI.
*/
package test_core_image
@@ -14,6 +14,7 @@ import "core:testing"
import "core:compress"
import "core:image"
import "core:image/png"
import "core:image/qoi"
import "core:bytes"
import "core:hash"
@@ -1499,11 +1500,34 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) -> (subtotal: int) {
passed &= dims_pass
hash := hash.crc32(pixels)
error = fmt.tprintf("%v test %v hash is %08x, expected %08x with %v.", file.file, count, hash, test.hash, test.options)
expect(t, test.hash == hash, error)
png_hash := hash.crc32(pixels)
error = fmt.tprintf("%v test %v hash is %08x, expected %08x with %v.", file.file, count, png_hash, test.hash, test.options)
expect(t, test.hash == png_hash, error)
passed &= test.hash == png_hash
// Roundtrip through QOI to test the QOI encoder and decoder.
if passed && img.depth == 8 && (img.channels == 3 || img.channels == 4) {
qoi_buffer: bytes.Buffer
defer bytes.buffer_destroy(&qoi_buffer)
qoi_save_err := qoi.save(&qoi_buffer, img)
error = fmt.tprintf("%v test %v QOI save failed with %v.", file.file, count, qoi_save_err)
expect(t, qoi_save_err == nil, error)
if qoi_save_err == nil {
qoi_img, qoi_load_err := qoi.load(qoi_buffer.buf[:])
defer qoi.destroy(qoi_img)
error = fmt.tprintf("%v test %v QOI load failed with %v.", file.file, count, qoi_load_err)
expect(t, qoi_load_err == nil, error)
qoi_hash := hash.crc32(qoi_img.pixels.buf[:])
error = fmt.tprintf("%v test %v QOI load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, qoi_hash, png_hash, test.options)
expect(t, qoi_hash == png_hash, error)
}
}
passed &= test.hash == hash
if .return_metadata in test.options {
if v, ok := img.metadata.(^image.PNG_Info); ok {