Skip to content

Commit b2370d0

Browse files
committed
Update Wuffs to v0.4.0-alpha.9
1 parent 81dbfd3 commit b2370d0

11 files changed

+62
-32
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Generated from CLion C/C++ Code Style settings
22
BasedOnStyle: Google
3+
SortIncludes: true

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include src/wuffs-aux-image-wrapper.h src/wuffs-aux-json-wrapper.h libs/wuffs/release/c/wuffs-unsupported-snapshot.c
1+
include src/wuffs-aux-image-wrapper.h src/wuffs-aux-json-wrapper.h src/wuffs-aux-utils.h libs/wuffs/release/c/wuffs-unsupported-snapshot.c
22

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the [Auxiliary C++ API](https://github.com/google/wuffs/blob/main/doc/note/auxil
1111
interest since it provides for "ridiculously fast" decoding of images of some types.
1212

1313
Current version of Wuffs library used in this project is **unsupported snapshot** taken from
14-
[this](https://github.com/google/wuffs/tree/13c72db3508d33b9416a22a0ab8a8d4d8d5cd7be) commit. The primary
14+
[this](https://github.com/google/wuffs/releases/tag/v0.4.0-alpha.9) tag. The primary
1515
rationale for using the snapshot version instead of a stable release is that it provides JPEG decoder.
1616

1717
## Installation

libs/wuffs

Submodule wuffs updated 199 files

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def build_extensions(self):
4141
]
4242

4343
setup(name="pywuffs",
44-
version="1.2.1",
44+
version="2.0.0",
4545
description="Python bindings for Wuffs the Library",
4646
author="Georgiy Manuilov",
4747
url="https://github.com/dev0x13/pywuffs",

src/wuffs-aux-image-wrapper.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
#include <pybind11/numpy.h>
44

5+
#include <map>
56
#include <string>
67
#include <unordered_set>
78
#include <utility>
89
#include <vector>
9-
1010
#include <wuffs-unsupported-snapshot.c>
1111

12+
#include "wuffs-aux-utils.h"
13+
1214
// This API wraps the wuffs_aux API for image decoding. The wrapper is needed
1315
// since the wuffs_aux API uses the callback-based approach which doesn't play
1416
// well with Python-C++ interop.
@@ -119,7 +121,7 @@ struct ImageDecoderConfig {
119121
std::vector<ImageDecoderFlags> flags;
120122
PixelBlend pixel_blend = static_cast<PixelBlend>(
121123
wuffs_aux::DecodeImageArgPixelBlend::DefaultValue().repr);
122-
std::vector<ImageDecoderQuirks> quirks;
124+
std::map<ImageDecoderQuirks, uint64_t> quirks;
123125
uint32_t background_color =
124126
wuffs_aux::DecodeImageArgBackgroundColor::DefaultValue().repr;
125127
uint32_t max_incl_dimension =
@@ -227,16 +229,15 @@ const std::string ImageDecoderError::UnsupportedPixelFormat =
227229
const std::string ImageDecoderError::FailedToOpenFile =
228230
"wuffs_aux_wrap::ImageDecoder::Decode: failed to open file";
229231

230-
class ImageDecoder : public wuffs_aux::DecodeImageCallbacks {
232+
class ImageDecoder : public wuffs_aux::DecodeImageCallbacks {
231233
public:
232234
explicit ImageDecoder(const ImageDecoderConfig& config)
233-
: quirks_vector_({config.quirks.begin(), config.quirks.end()}),
235+
: quirks_vector_(utils::ConvertQuirks(config.quirks)),
234236
enabled_decoders_(
235237
{config.enabled_decoders.begin(), config.enabled_decoders.end()}),
236238
pixel_format_(wuffs_base__make_pixel_format(config.pixel_format)),
237-
quirks_(wuffs_aux::DecodeImageArgQuirks(
238-
reinterpret_cast<uint32_t*>(quirks_vector_.data()),
239-
quirks_vector_.size())),
239+
quirks_(wuffs_aux::DecodeImageArgQuirks(quirks_vector_.data(),
240+
quirks_vector_.size())),
240241
flags_(GetFlagsBitmask(config.flags)),
241242
pixel_blend_(wuffs_aux::DecodeImageArgPixelBlend(
242243
static_cast<uint32_t>(config.pixel_blend))),
@@ -354,7 +355,7 @@ const std::string ImageDecoderError::FailedToOpenFile =
354355

355356
private:
356357
ImageDecodingResult decoding_result_;
357-
std::vector<ImageDecoderQuirks> quirks_vector_;
358+
std::vector<wuffs_aux::QuirkKeyValuePair> quirks_vector_;
358359
std::unordered_set<ImageDecoderType> enabled_decoders_;
359360
wuffs_base__pixel_format pixel_format_;
360361
wuffs_aux::DecodeImageArgQuirks quirks_;

src/wuffs-aux-json-wrapper.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
#include <pybind11/numpy.h>
44
#include <pybind11/pytypes.h>
55

6+
#include <map>
67
#include <string>
78
#include <utility>
89
#include <vector>
9-
1010
#include <wuffs-unsupported-snapshot.c>
1111

12+
#include "wuffs-aux-utils.h"
13+
1214
// This API wraps the wuffs_aux API for JSON decoding. The wrapper is needed
1315
// since the wuffs_aux API uses the callback-based approach which doesn't play
1416
// well with Python-C++ interop.
@@ -45,7 +47,7 @@ enum class JsonDecoderQuirks : uint32_t {
4547
// This struct hosts wuffs_aux::DecodeJson arguments in more user- and
4648
// Python- friendly fashion
4749
struct JsonDecoderConfig {
48-
std::vector<JsonDecoderQuirks> quirks;
50+
std::map<JsonDecoderQuirks, uint64_t> quirks;
4951
std::string json_pointer;
5052
};
5153

@@ -107,14 +109,20 @@ const std::string JsonDecoderError::BadDepth =
107109
const std::string JsonDecoderError::FailedToOpenFile =
108110
"wuffs_aux_wrap::JsonDecoder::Decode: failed to open file";
109111
// + 1 is for stripping leading '#'
110-
const std::string JsonDecoderError::BadC0ControlCode = wuffs_json__error__bad_c0_control_code + 1;
112+
const std::string JsonDecoderError::BadC0ControlCode =
113+
wuffs_json__error__bad_c0_control_code + 1;
111114
const std::string JsonDecoderError::BadUtf8 = wuffs_json__error__bad_utf_8 + 1;
112-
const std::string JsonDecoderError::BadBackslashEscape = wuffs_json__error__bad_backslash_escape + 1;
115+
const std::string JsonDecoderError::BadBackslashEscape =
116+
wuffs_json__error__bad_backslash_escape + 1;
113117
const std::string JsonDecoderError::BadInput = wuffs_json__error__bad_input + 1;
114-
const std::string JsonDecoderError::BadNewLineInAString = wuffs_json__error__bad_new_line_in_a_string + 1;
115-
const std::string JsonDecoderError::BadQuirkCombination = wuffs_json__error__bad_quirk_combination + 1;
116-
const std::string JsonDecoderError::UnsupportedNumberLength = wuffs_json__error__unsupported_number_length + 1;
117-
const std::string JsonDecoderError::UnsupportedRecursionDepth = wuffs_json__error__unsupported_recursion_depth + 1;
118+
const std::string JsonDecoderError::BadNewLineInAString =
119+
wuffs_json__error__bad_new_line_in_a_string + 1;
120+
const std::string JsonDecoderError::BadQuirkCombination =
121+
wuffs_json__error__bad_quirk_combination + 1;
122+
const std::string JsonDecoderError::UnsupportedNumberLength =
123+
wuffs_json__error__unsupported_number_length + 1;
124+
const std::string JsonDecoderError::UnsupportedRecursionDepth =
125+
wuffs_json__error__unsupported_recursion_depth + 1;
118126

119127
class JsonDecoder : public wuffs_aux::DecodeJsonCallbacks {
120128
public:
@@ -132,10 +140,9 @@ class JsonDecoder : public wuffs_aux::DecodeJsonCallbacks {
132140
};
133141

134142
explicit JsonDecoder(const JsonDecoderConfig& config)
135-
: quirks_vector_({config.quirks.begin(), config.quirks.end()}),
136-
quirks_(wuffs_aux::DecodeJsonArgQuirks(
137-
reinterpret_cast<uint32_t*>(quirks_vector_.data()),
138-
quirks_vector_.size())),
143+
: quirks_vector_(utils::ConvertQuirks(config.quirks)),
144+
quirks_(wuffs_aux::DecodeJsonArgQuirks(quirks_vector_.data(),
145+
quirks_vector_.size())),
139146
json_pointer_(config.json_pointer) {}
140147

141148
/* DecodeJsonCallbacks methods implementation */
@@ -247,7 +254,7 @@ class JsonDecoder : public wuffs_aux::DecodeJsonCallbacks {
247254
}
248255

249256
private:
250-
std::vector<JsonDecoderQuirks> quirks_vector_;
257+
std::vector<wuffs_aux::QuirkKeyValuePair> quirks_vector_;
251258
wuffs_aux::DecodeJsonArgQuirks quirks_;
252259
wuffs_aux::DecodeJsonArgJsonPointer json_pointer_;
253260
std::vector<Entry> stack_;

src/wuffs-aux-utils.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <map>
5+
#include <vector>
6+
7+
namespace utils {
8+
9+
template <typename QuirkType>
10+
std::vector<wuffs_aux::QuirkKeyValuePair> ConvertQuirks(
11+
const std::map<QuirkType, uint64_t>& quirks_map) {
12+
std::vector<wuffs_aux::QuirkKeyValuePair> quirks_vector;
13+
quirks_vector.reserve(quirks_map.size());
14+
for (const auto& quirk : quirks_map) {
15+
quirks_vector.emplace_back(static_cast<uint32_t>(quirk.first),
16+
quirk.second);
17+
}
18+
return quirks_vector;
19+
}
20+
21+
} // namespace utils

src/wuffs-bindings.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ py::enum_<wuffs_aux_wrap::PixelFormat>(
217217
"PixelBlend: pixel blend mode, default is PixelBlend.SRC.")
218218
.def_readwrite(
219219
"quirks", &wuffs_aux_wrap::ImageDecoderConfig::quirks,
220-
"list: list of ImageDecoderQuirks, empty by default (PNG "
221-
"decoder will always have ImageDecoderQuirks.IGNORE_CHECKSUM quirk "
222-
"enabled implicitly).")
220+
"dict: dict of ImageDecoderQuirks:<quirk-value> pairs, empty by "
221+
"default (PNG decoder will always have "
222+
"ImageDecoderQuirks.IGNORE_CHECKSUM quirk enabled implicitly).")
223223
.def_readwrite(
224224
"background_color",
225225
&wuffs_aux_wrap::ImageDecoderConfig::background_color,
@@ -437,7 +437,7 @@ py::enum_<wuffs_aux_wrap::PixelFormat>(
437437
"JsonDecoderError on error.");
438438

439439
py::class_<wuffs_aux_wrap::JsonDecoder>(aux_m, "JsonDecoder",
440-
"JSON decoder class.")
440+
"JSON decoder class.")
441441
.def(py::init<const wuffs_aux_wrap::JsonDecoderConfig&>(),
442442
"Sole constructor.\n\n"
443443
"Args:"

test/test_aux_image_decoder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_decode_background_color(background_color, test_image):
125125
])
126126
def test_decode_image_quirks(test_image, quirk):
127127
config = ImageDecoderConfig()
128-
config.quirks = [quirk]
128+
config.quirks = {quirk: 1}
129129
decoder = ImageDecoder(config)
130130
decoding_result = decoder.decode(test_image[1])
131131
assert_decoded(decoding_result)

test/test_aux_json_decoder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def test_decode_default_config(file_path):
4141

4242
def test_decode_json_quirks():
4343
config = JsonDecoderConfig()
44-
config.quirks = [JsonDecoderQuirks.ALLOW_COMMENT_BLOCK,
45-
JsonDecoderQuirks.ALLOW_EXTRA_COMMA]
44+
config.quirks = {JsonDecoderQuirks.ALLOW_COMMENT_BLOCK: 1,
45+
JsonDecoderQuirks.ALLOW_EXTRA_COMMA: 1}
4646
decoder = JsonDecoder(config)
4747
data = b"{\"test\": \"value\", \"test1\": 123,}"
4848
decoding_result = decoder.decode(data)

0 commit comments

Comments
 (0)