Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image/bmp: support to decode 8-bit format with up to 256 color palette #61240

Closed
entooone opened this issue Jul 9, 2023 · 1 comment
Closed
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@entooone
Copy link

entooone commented Jul 9, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home//.cache/go-build"
GOENV="/home//.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home//go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home//go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1874621086=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I got bmp: unsupported BMP image when I tried to Decode the following image.

Sample code:

package main

import (
	"os"

	"golang.org/x/image/bmp"
)

func main() {
	f, err := os.Open("colormap-251.bmp")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	_, err = bmp.Decode(f)
	if err != nil {
		panic(err)
	}
}

What did you expect to see?

Decode success

What did you see instead?

$ go run .
panic: bmp: unsupported BMP image
...

Additional information

Current implementation of reader.go assumes that the number of palette is 256. Therefore, bmp: unsupported BMP image occurs when the number of palette is not 256.

I think that the number of palette should depend on biClrUsed of BITMAPINFOHEADER instead of fixing it to 256. Note that if biClrUsed is 0, the number of palette is 2 to the power of bit per pixel (e.g. 256 colors for 8-bit format, 16 colors for 4-bit format).

I will modify reader.go to support 8-bit format with up to 256 color palette.

References:

@gopherbot gopherbot added this to the Unreleased milestone Jul 9, 2023
@gopherbot
Copy link

Change https://go.dev/cl/508575 mentions this issue: bmp: support to decode 8-bit format with up to 256 color palette

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 9, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants