Add a base.pixel_swizzler type

This commit is contained in:
Nigel Tao committed 2018-12-08 13:25:53 +11:00
1 parent 86b8408223
commit 6c9dca47ee
11 files changed
+317 -35

No files matched your search

+6 -4
View File
@@ -49,10 +49,6 @@ extern "C" {
// !! INSERT base/all-private.h.
#ifdef __cplusplus
} // extern "C"
#endif
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)
const uint8_t wuffs_base__low_bits_mask__u8[9] = {
@@ -100,9 +96,15 @@ const uint64_t wuffs_base__low_bits_mask__u64[65] = {
// !! INSERT wuffs_base__status strings.
// !! INSERT base/image-impl.c.
#endif // !defined(WUFFS_CONFIG__MODULES) ||
// defined(WUFFS_CONFIG__MODULE__BASE)
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WUFFS_IMPLEMENTATION
// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.
@@ -0,0 +1,67 @@
// After editing this file, run "go generate" in the parent directory.
// Copyright 2017 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.
// ---------------- Images
static uint64_t //
wuffs_base__pixel_swizzler__copy_1_1(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src) {
return wuffs_base__slice_u8__copy_from_slice(dst, src);
}
void //
wuffs_base__pixel_swizzler__initialize(wuffs_base__pixel_swizzler* p,
wuffs_base__pixel_format dst_format,
wuffs_base__pixel_format src_format) {
if (!p) {
return;
}
// TODO: support many more formats.
uint64_t (*func)(wuffs_base__slice_u8 dst, wuffs_base__slice_u8 src) = NULL;
switch (src_format) {
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
switch (dst_format) {
case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:
func = wuffs_base__pixel_swizzler__copy_1_1;
break;
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:
// TODO: implement.
break;
default:
break;
}
break;
default:
break;
}
p->private_impl.func = func;
}
uint64_t //
wuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,
wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src) {
if (p && p->private_impl.func) {
return (*(p->private_impl.func))(dst, src);
}
return 0;
}
@@ -786,6 +786,7 @@ typedef struct {
inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,
wuffs_base__slice_u8 pixbuf_memory);
inline wuffs_base__slice_u8 palette();
inline wuffs_base__pixel_format pixel_format();
inline wuffs_base__table_u8 plane(uint32_t p);
#endif // __cplusplus
@@ -856,6 +857,14 @@ wuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) {
return ((wuffs_base__slice_u8){});
}
static inline wuffs_base__pixel_format //
wuffs_base__pixel_buffer__pixel_format(wuffs_base__pixel_buffer* b) {
if (b) {
return b->pixcfg.private_impl.pixfmt;
}
return WUFFS_BASE__PIXEL_FORMAT__INVALID;
}
static inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {
return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))
@@ -876,6 +885,11 @@ wuffs_base__pixel_buffer::palette() {
return wuffs_base__pixel_buffer__palette(this);
}
inline wuffs_base__pixel_format //
wuffs_base__pixel_buffer::pixel_format() {
return wuffs_base__pixel_buffer__pixel_format(this);
}
inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer::plane(uint32_t p) {
return wuffs_base__pixel_buffer__plane(this, p);
@@ -900,3 +914,50 @@ typedef struct {
#ifdef __cplusplus
#endif // __cplusplus
// --------
typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so.
struct {
// TODO: should the func type take restrict pointers?
uint64_t (*func)(wuffs_base__slice_u8 dst, wuffs_base__slice_u8 src);
} private_impl;
#ifdef __cplusplus
inline void initialize(wuffs_base__pixel_format dst_format,
wuffs_base__pixel_format src_format);
inline uint64_t swizzle_packed(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src);
#endif // __cplusplus
} wuffs_base__pixel_swizzler;
// TODO: should initialize (both the C and C++ methods) return a status?
void //
wuffs_base__pixel_swizzler__initialize(wuffs_base__pixel_swizzler* p,
wuffs_base__pixel_format dst_format,
wuffs_base__pixel_format src_format);
uint64_t //
wuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,
wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src);
#ifdef __cplusplus
inline void //
wuffs_base__pixel_swizzler::initialize(wuffs_base__pixel_format dst_format,
wuffs_base__pixel_format src_format) {
wuffs_base__pixel_swizzler__initialize(this, dst_format, src_format);
}
uint64_t //
wuffs_base__pixel_swizzler::swizzle_packed(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 src) {
wuffs_base__pixel_swizzler__swizzle_packed(this, dst, src);
}
#endif // __cplusplus