golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.03k stars 17.67k forks source link

x/image/tiff: Missing raw stream read/write #39900

Open kpym opened 4 years ago

kpym commented 4 years ago

If I understand well the TIFF library only offers encode/decode but not raw read/write methods.

As TIFF is an image container that can support multiple encodings, IMO, it could be very useful to have direct read/write access to the encoded data stream. In this way for example a jpeg encoded image can be encapsulated in a TIFF container without decoding/encoding. The same is valid for CCITT or JBIG2 encodings.

This can also be very useful to extract images from PDF file and save them to TIFF without encoding/decoding. Or to make the inverse : import TIFF images to PDF files.

bsiegert commented 4 years ago

/cc @nigeltao

A priori, I am open to such a thing. It might be a useful addition. What should the API look like? Similar to archive/tar maybe?

kpym commented 4 years ago

I have no precise idea about the API but may be something close to Encode/Decode like:

func Write(w io.Writer, p []byte, opt *Options) error

and

func Read(r io.Reader, p []byte) (n int, err error)
dtrehas commented 2 years ago

Very useful for extracting images from old tiff (fax) documents in order be converted to pdf having small size (still in ccit 6 format). Useful also for jbig2 tiffs.