std/jpeg: add new package

This is just a placeholder decoder implementation (and all of the
required plumbing) that produces a 1x1 reddish-purple image. Follow-up
commits will add flesh to the metaphorical bones.

Updates #42
This commit is contained in:
Nigel Tao committed 2023-04-21 18:33:00 +10:00
1 parent bc86394bef
commit 0bbc4c0083
11 files changed
+1592

No files matched your search

+191
View File
@@ -0,0 +1,191 @@
// Copyright 2023 The Wuffs Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------
/*
This test program is typically run indirectly, by the "wuffs test" or "wuffs
bench" commands. These commands take an optional "-mimic" flag to check that
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
giflib for GIF, libpng for PNG, etc.
To manually run this test:
for CC in clang gcc; do
$CC -std=c99 -Wall -Werror jpeg.c && ./a.out
rm -f a.out
done
Each edition should print "PASS", amongst other information, and exit(0).
Add the "wuffs mimic cflags" (everything after the colon below) to the C
compiler flags (after the .c file) to run the mimic tests.
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
the first "./a.out" with "./a.out -bench". Combine these changes with the
"wuffs mimic cflags" to run the mimic benchmarks.
*/
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// To use that single file as a "foo.c"-like implementation, instead of a
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
// compiling it.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
// entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
// modules we use makes that process explicit. Preprocessing means that such
// code simply isn't compiled.
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__JPEG
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
// No mimic library.
#endif
// ---------------- JPEG Tests
const char* //
wuffs_jpeg_decode(uint64_t* n_bytes_out,
wuffs_base__io_buffer* dst,
uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format pixfmt,
uint32_t* quirks_ptr,
size_t quirks_len,
wuffs_base__io_buffer* src) {
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION,
wuffs_initialize_flags));
return do_run__wuffs_base__image_decoder(
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(&dec),
n_bytes_out, dst, pixfmt, quirks_ptr, quirks_len, src);
}
const char* //
test_wuffs_jpeg_decode_interface() {
CHECK_FOCUS(__func__);
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
return do_test__wuffs_base__image_decoder(
wuffs_jpeg__decoder__upcast_as__wuffs_base__image_decoder(&dec),
"test/data/bricks-color.jpeg", 0, SIZE_MAX, 1, 1, 0xFFFF007F);
}
const char* //
test_wuffs_jpeg_decode_truncated_input() {
CHECK_FOCUS(__func__);
wuffs_base__io_buffer src =
wuffs_base__ptr_u8__reader(g_src_array_u8, 0, false);
wuffs_jpeg__decoder dec;
CHECK_STATUS("initialize",
wuffs_jpeg__decoder__initialize(
&dec, sizeof dec, WUFFS_VERSION,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
wuffs_base__status status =
wuffs_jpeg__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_base__suspension__short_read) {
RETURN_FAIL("closed=false: have \"%s\", want \"%s\"", status.repr,
wuffs_base__suspension__short_read);
}
src.meta.closed = true;
status = wuffs_jpeg__decoder__decode_image_config(&dec, NULL, &src);
if (status.repr != wuffs_jpeg__error__truncated_input) {
RETURN_FAIL("closed=true: have \"%s\", want \"%s\"", status.repr,
wuffs_jpeg__error__truncated_input);
}
return NULL;
}
// ---------------- Mimic Tests
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
// ---------------- JPEG Benches
const char* //
bench_wuffs_jpeg_decode_77k_24bpp() {
CHECK_FOCUS(__func__);
return do_bench_image_decode(
&wuffs_jpeg_decode,
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
wuffs_base__make_pixel_format(WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL),
NULL, 0, "test/data/bricks-color.jpeg", 0, SIZE_MAX, 1000);
}
// ---------------- Mimic Benches
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
// ---------------- Manifest
proc g_tests[] = {
test_wuffs_jpeg_decode_interface,
test_wuffs_jpeg_decode_truncated_input,
#ifdef WUFFS_MIMIC
// No mimic tests.
#endif // WUFFS_MIMIC
NULL,
};
proc g_benches[] = {
bench_wuffs_jpeg_decode_77k_24bpp,
#ifdef WUFFS_MIMIC
// No mimic benches.
#endif // WUFFS_MIMIC
NULL,
};
int //
main(int argc, char** argv) {
g_proc_package_name = "std/jpeg";
return test_main(argc, argv, g_tests, g_benches);
}
+8
View File
@@ -25,6 +25,7 @@ f33b9bc1 test/data/artificial-gif/zero-width-frame.gif
e08a7cc8 test/data/artificial-png/exif.png
e08a7cc8 test/data/artificial-png/key-value-pairs.png
076cb375 test/data/bricks-color.bmp
1f87b217 test/data/bricks-color.jpeg
076cb375 test/data/bricks-color.png
076cb375 test/data/bricks-color.tga
f36c2e80 test/data/bricks-dither.bmp
@@ -33,6 +34,7 @@ f36c2e80 test/data/bricks-dither.no-ancillary.png
f36c2e80 test/data/bricks-dither.png
c2bce675 test/data/bricks-gray.bmp
c2bce675 test/data/bricks-gray.gif
1f87b217 test/data/bricks-gray.jpeg
c2bce675 test/data/bricks-gray.no-ancillary.png
c2bce675 test/data/bricks-gray.png
c2bce675 test/data/bricks-gray.tga
@@ -47,22 +49,27 @@ aa3e6c7c test/data/crude-flag.nie
3014b4c0 test/data/gifplayer-muybridge.gif
030f5a48 test/data/harvesters.bmp
c18b3d5a test/data/harvesters.gif
1f87b217 test/data/harvesters.jpeg
030f5a48 test/data/harvesters.png
e776c90f test/data/hat.bmp
6dcba6a4 test/data/hat.gif
1f87b217 test/data/hat.jpeg
e776c90f test/data/hat.png
d30bfe5d test/data/hat.wbmp
33a44f22 test/data/hibiscus.primitive.bmp
25e212b3 test/data/hibiscus.primitive.gif
1f87b217 test/data/hibiscus.primitive.jpeg
33a44f22 test/data/hibiscus.primitive.png
60040742 test/data/hibiscus.regular.bmp
b727da8b test/data/hibiscus.regular.gif
1f87b217 test/data/hibiscus.regular.jpeg
60040742 test/data/hibiscus.regular.png
dcbb225a test/data/hippopotamus.bmp
ed4b78fc test/data/hippopotamus.interlaced.gif
dcbb225a test/data/hippopotamus.interlaced.png
c3c4bd65 test/data/hippopotamus.interlaced.truncated.gif
7c6a771b test/data/hippopotamus.interlaced.truncated.png
1f87b217 test/data/hippopotamus.jpeg
d3bbed27 test/data/hippopotamus.masked-with-muybridge.gif
7e6acf01 test/data/hippopotamus.masked-with-muybridge.png
dcbb225a test/data/hippopotamus.nie
@@ -74,6 +81,7 @@ db2733f5 test/data/muybridge.apng
db2733f5 test/data/muybridge.gif
bf7e8c96 test/data/pjw-thumbnail.bmp
bf7e8c96 test/data/pjw-thumbnail.gif
1f87b217 test/data/pjw-thumbnail.jpeg
bf7e8c96 test/data/pjw-thumbnail.png
38cb4cbf test/data/red-blue-gradient.dcip3d65-no-chrm-no-gama.png
38cb4cbf test/data/red-blue-gradient.gamma1dot0.png