mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
lib/uncompng: rearrange Encode argument order
This commit is contained in:
1 parent
1230506e7c
commit
e772ccd47a
4 files changed
+21
-21
No files matched your search
@@ -804,10 +804,10 @@ print_uncompressed_png_frame() {
|
||||
uint32_t h = wuffs_base__pixel_config__height(&g_pixbuf.pixcfg);
|
||||
wuffs_base__table_u8 tab = wuffs_base__pixel_buffer__plane(&g_pixbuf, 0);
|
||||
return UNCOMPNG__RESULT__OK ==
|
||||
uncompng__encode(&my_uncompng_write_func, NULL, tab.ptr,
|
||||
uncompng__encode(&my_uncompng_write_func, NULL, pixfmt, w, h, tab.ptr,
|
||||
wuffs_base__table__flattened_length(
|
||||
tab.width, tab.height, tab.stride),
|
||||
w, h, tab.stride, pixfmt);
|
||||
tab.stride);
|
||||
}
|
||||
|
||||
void //
|
||||
|
||||
@@ -196,7 +196,7 @@ const (
|
||||
// pix holds the pixel data, either 1 or 4 bytes per pixel (doubled for
|
||||
// Depth16) depending on the colorType. width and height are measured in
|
||||
// pixels. stride is measured in bytes. depth must be either Depth8 or Depth16.
|
||||
func (e *Encoder) Encode(w io.Writer, pix []byte, width int, height int, stride int, depth Depth, colorType ColorType) error {
|
||||
func (e *Encoder) Encode(w io.Writer, depth Depth, colorType ColorType, width int, height int, pix []byte, stride int) error {
|
||||
if (width < 0) || (height < 0) ||
|
||||
((depth != Depth8) && (depth != Depth16)) ||
|
||||
(colorType.pngFileFormatEncoding() == 0xFF) {
|
||||
|
||||
@@ -26,39 +26,39 @@ func encodeImage(w io.Writer, src image.Image) error {
|
||||
|
||||
switch src := src.(type) {
|
||||
case *image.Gray:
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeGray)
|
||||
return e.Encode(w, Depth8, ColorTypeGray, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
|
||||
case *image.Gray16:
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeGray)
|
||||
return e.Encode(w, Depth16, ColorTypeGray, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
|
||||
case *image.RGBA:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth8, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.RGBA64:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth16, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.NRGBA:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth8, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
} else {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth8, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth8, ColorTypeNRGBA, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
|
||||
case *image.NRGBA64:
|
||||
if src.Opaque() {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeRGBX)
|
||||
return e.Encode(w, Depth16, ColorTypeRGBX, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
} else {
|
||||
return e.Encode(w, src.Pix, b.Dx(), b.Dy(), src.Stride, Depth16, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth16, ColorTypeNRGBA, b.Dx(), b.Dy(), src.Pix, src.Stride)
|
||||
}
|
||||
}
|
||||
|
||||
tmp := image.NewNRGBA(b)
|
||||
draw.Draw(tmp, b, src, b.Min, draw.Src)
|
||||
return e.Encode(w, tmp.Pix, b.Dx(), b.Dy(), tmp.Stride, Depth8, ColorTypeNRGBA)
|
||||
return e.Encode(w, Depth8, ColorTypeNRGBA, b.Dx(), b.Dy(), tmp.Pix, tmp.Stride)
|
||||
}
|
||||
|
||||
func getPix(m image.Image) []byte {
|
||||
@@ -144,7 +144,7 @@ func TestNoAllocation(tt *testing.T) {
|
||||
enc := Encoder{}
|
||||
pix := make([]byte, 4*3*5)
|
||||
got := testing.AllocsPerRun(100, func() {
|
||||
enc.Encode(io.Discard, pix, 3, 5, 4*3, Depth8, ColorTypeNRGBA)
|
||||
enc.Encode(io.Discard, Depth8, ColorTypeNRGBA, 3, 5, pix, 4*3)
|
||||
})
|
||||
if got != 0 {
|
||||
tt.Errorf("AllocsPerRun: got %v, want 0", got)
|
||||
|
||||
+8
-8
@@ -94,12 +94,12 @@ uncompng__encode(int (*write_func)(void* context,
|
||||
const uint8_t* data_ptr,
|
||||
size_t data_len),
|
||||
void* context,
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
uint32_t pixel_format,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
size_t stride,
|
||||
uint32_t pixel_format);
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
size_t stride);
|
||||
|
||||
// --------
|
||||
|
||||
@@ -581,12 +581,12 @@ uncompng__encode(int (*write_func)(void* context,
|
||||
const uint8_t* data_ptr,
|
||||
size_t data_len),
|
||||
void* context,
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
uint32_t pixel_format,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
size_t stride,
|
||||
uint32_t pixel_format) {
|
||||
const uint8_t* pixel_ptr,
|
||||
size_t pixel_len,
|
||||
size_t stride) {
|
||||
if (!write_func) {
|
||||
return UNCOMPNG__RESULT__INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user