Simplify gif.decoder.copy_to_image_buffer bpp calc

This commit is contained in:
Nigel Tao committed 2020-01-28 10:37:05 +11:00
1 parent 0e833f909a
commit 55aedb34f9
2 files changed
+4 -21

No files matched your search

+2 -9
View File
@@ -12861,17 +12861,10 @@ wuffs_gif__decoder__copy_to_image_buffer(wuffs_gif__decoder* self,
v_pixfmt = wuffs_base__pixel_buffer__pixel_format(a_pb);
v_bits_per_pixel = wuffs_base__pixel_format__bits_per_pixel(&v_pixfmt);
if (v_bits_per_pixel == 32) {
v_bytes_per_pixel = 4;
} else if (v_bits_per_pixel == 24) {
v_bytes_per_pixel = 3;
} else if (v_bits_per_pixel == 16) {
v_bytes_per_pixel = 2;
} else if (v_bits_per_pixel == 8) {
v_bytes_per_pixel = 1;
} else {
if ((v_bits_per_pixel > 512) || ((v_bits_per_pixel & 7) != 0)) {
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
}
v_bytes_per_pixel = (v_bits_per_pixel >> 3);
v_width_in_bytes = (((uint64_t)(self->private_impl.f_width)) *
((uint64_t)(v_bytes_per_pixel)));
v_tab = wuffs_base__pixel_buffer__plane(a_pb, 0);
+2 -12
View File
@@ -1035,24 +1035,14 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
var replicate_dst : slice base.u8
var replicate_src : slice base.u8
// TODO: a Wuffs (not just C) name for the WUFFS_BASE__PIXEL_FORMAT__ETC
// magic pixfmt constants. Also, support more formats.
//
// TODO: the pixfmt variable shouldn't be necessary. We should be able to
// chain the two calls: "args.pb.pixel_format().bits_per_pixel()".
pixfmt = args.pb.pixel_format()
bits_per_pixel = pixfmt.bits_per_pixel()
if (bits_per_pixel == 32) {
bytes_per_pixel = 4
} else if (bits_per_pixel == 24) {
bytes_per_pixel = 3
} else if (bits_per_pixel == 16) {
bytes_per_pixel = 2
} else if (bits_per_pixel == 8) {
bytes_per_pixel = 1
} else {
if (bits_per_pixel > 512) or ((bits_per_pixel & 7) <> 0) {
return base."#unsupported option"
}
bytes_per_pixel = bits_per_pixel >> 3
width_in_bytes = (this.width as base.u64) * (bytes_per_pixel as base.u64)
tab = args.pb.plane(p: 0)