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 1-bit format #29711

Open
cbrake opened this Issue Jan 12, 2019 · 7 comments

Comments

Projects
None yet
5 participants
@cbrake
Copy link

cbrake commented Jan 12, 2019

Hi, I implemented support for 1-bit bmp files in the reader:

cbrake/golang.org-x-image@25481fe

Is there interest merging this (or an improved version)?

@gopherbot gopherbot added this to the Unreleased milestone Jan 12, 2019

@ALTree

This comment has been minimized.

Copy link
Member

ALTree commented Jan 12, 2019

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Jan 15, 2019

I'm open to merging 1-bit support, although if it's not too much extra work, it'd be nice to also get 2-bit and 4-bit support.

@cbrake

This comment has been minimized.

Copy link
Author

cbrake commented Jan 16, 2019

I'll look into 2/4 bit.

Is writer support needed? It does not seem that the 1/2/4 bit formats are supported in the image pkg, but I may be missing something:

https://golang.org/pkg/image/color/#Model

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Jan 17, 2019

Writer support is not needed.

When reading, decode to an image.Paletted or image.RGBA, even for 1/2/4 bits per pixel.

@ljubomirb

This comment has been minimized.

Copy link

ljubomirb commented Jan 24, 2019

But how to write to 1bit then? I'm also missing something. Is there any blog or example you can point us @nigeltao, please?
Because, if using image filters like dithering, you will always get bw 1bit result. With my limiting knowledge, I always end up using image.Gray, and that is not what I need. Looking at image.Gray, I think I see it is defined as h.bpp = 8. How to get it to be 1?

@nigeltao

This comment has been minimized.

Copy link
Contributor

nigeltao commented Jan 30, 2019

If you really must write 1bpp images, then I think you're going to have to fork the bmp package, as the image package doesn't have a specific representation for 1bpp. Or write your own package. If your input is always going to be 1bpp, writing that particular subset of the BMP file format shouldn't be that complicated.

If you're talking about dithering, it's already possible (using Go's standard and x libraries) to dither to a 2-element palette (black and white). You can either encode that directly, or convert that to your own 1bpp representation.

@ljubomirb

This comment has been minimized.

Copy link

ljubomirb commented Jan 31, 2019

The thing is, 1bit bmp has its use and purpose. One such is for laser engraver machines.
In particular, I wanted to write the Go variant of uploader/control software for one such, very common device. The same thing exists, thanks to community doing reverse engineering, in almost any language you can imagine, all on github, in Swift, C#, Qt, Python and so on...
But not in Go. I'll simply use different language for this project now, but please, do consider implementing 1bit bmp support. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.