mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
std/handsum: make 1:1 aspect ratio be landscape
This commit is contained in:
1 parent
ff4132b3ca
commit
2822b1a65d
3 files changed
+26
-10
No files matched your search
+19
-8
@@ -292,19 +292,22 @@ func Encode(w io.Writer, src image.Image, options *EncodeOptions) error {
|
||||
return ErrBadArgument
|
||||
}
|
||||
|
||||
aspectRatio := byte(0x0F)
|
||||
if srcW > srcH { // Landscape.
|
||||
aspectRatio := byte(0)
|
||||
if srcW >= srcH { // Landscape.
|
||||
a := ((int64(srcH) * 32) + int64(srcW)) / (2 * int64(srcW))
|
||||
if a <= 0 {
|
||||
a = 1
|
||||
}
|
||||
aspectRatio = byte(a-1) | 0x00
|
||||
} else if srcW < srcH { // Portrait.
|
||||
} else { // Portrait.
|
||||
a := ((int64(srcW) * 32) + int64(srcH)) / (2 * int64(srcH))
|
||||
if a <= 0 {
|
||||
a = 1
|
||||
}
|
||||
aspectRatio = byte(a-1) | 0x10
|
||||
if aspectRatio == 0x1F { // Reserved for future expansion.
|
||||
aspectRatio = 0x0F
|
||||
}
|
||||
}
|
||||
|
||||
alphasQuadBlock := lowleveljpeg.QuadBlockU8{}
|
||||
@@ -465,6 +468,10 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
||||
if !ok {
|
||||
return image.Config{}, ErrNotAHandsumFile
|
||||
}
|
||||
w, h, ok := decodeWidthAndHeight(buf[2])
|
||||
if !ok {
|
||||
return image.Config{}, ErrNotAHandsumFile
|
||||
}
|
||||
|
||||
cm := color.GrayModel
|
||||
if c == ColorRGB {
|
||||
@@ -473,7 +480,6 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
|
||||
cm = color.NRGBAModel
|
||||
}
|
||||
|
||||
w, h := decodeWidthAndHeight(buf[2])
|
||||
return image.Config{
|
||||
ColorModel: cm,
|
||||
Width: w,
|
||||
@@ -509,6 +515,10 @@ func Decode(r io.Reader) (image.Image, error) {
|
||||
if _, err := io.ReadFull(r, buf[fileSizeHeader:fileSize(c, q)]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dstW, dstH, ok := decodeWidthAndHeight(buf[2])
|
||||
if !ok {
|
||||
return nil, ErrNotAHandsumFile
|
||||
}
|
||||
|
||||
bitOffset := 3 * 8
|
||||
decodeBlock := decodeBlockFuncs[q]
|
||||
@@ -548,19 +558,20 @@ func Decode(r io.Reader) (image.Image, error) {
|
||||
}
|
||||
}
|
||||
|
||||
dstW, dstH := decodeWidthAndHeight(buf[2])
|
||||
return finishDecode(dstW, dstH, c, &lumaQuadBlockU8, &cbQuadBlockU8, &crQuadBlockU8, &aaQuadBlockU8), nil
|
||||
}
|
||||
|
||||
func decodeWidthAndHeight(buf2 byte) (w int, h int) {
|
||||
if (buf2 & 0x10) == 0 { // Landscape.
|
||||
func decodeWidthAndHeight(buf2 byte) (w int, h int, ok bool) {
|
||||
if (buf2 & 0x1F) == 0x1F {
|
||||
return 0, 0, false
|
||||
} else if (buf2 & 0x10) == 0x00 { // Landscape.
|
||||
w = 16
|
||||
h = 1 + int(buf2&0x0F)
|
||||
} else { // Portrait.
|
||||
w = 1 + int(buf2&0x0F)
|
||||
h = 16
|
||||
}
|
||||
return w, h
|
||||
return w, h, true
|
||||
}
|
||||
|
||||
type decodeBlockFunc func(dst []byte, stride int, buf *[fileSizeMax]byte, bitOffset int, nCoeffs int) int
|
||||
|
||||
@@ -51002,7 +51002,10 @@ wuffs_handsum__decoder__do_decode_image_config(
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_quality = ((v_c32 >> 5u) & 3u);
|
||||
if ((v_c32 & 16u) == 0u) {
|
||||
if ((v_c32 & 31u) == 31u) {
|
||||
status = wuffs_base__make_status(wuffs_handsum__error__bad_header);
|
||||
goto exit;
|
||||
} else if ((v_c32 & 16u) == 0u) {
|
||||
self->private_impl.f_width = 16u;
|
||||
self->private_impl.f_height = ((v_c32 & 15u) + 1u);
|
||||
} else {
|
||||
|
||||
@@ -78,7 +78,9 @@ pri func decoder.do_decode_image_config?(dst: nptr base.image_config, src: base.
|
||||
}
|
||||
this.quality = (c32 >> 5) & 3
|
||||
|
||||
if (c32 & 0x10) == 0x00 { // Landscape.
|
||||
if (c32 & 0x1F) == 0x1F { // Reserved for future expansion.
|
||||
return "#bad header"
|
||||
} else if (c32 & 0x10) == 0x00 { // Landscape.
|
||||
this.width = 16
|
||||
this.height = (c32 & 0x0F) + 1
|
||||
} else { // Portrait.
|
||||
|
||||
Reference in new issue
Block a user