Commit Graph

39 Commits

Author SHA1 Message Date
Nigel Tao
d442804300 tiff/lzw: sync with the stdlib compress/lzw.
As noted at the top of reader.go, this package is a fork of the standard
library's LZW package, due to an "off by one" in the TIFF format. Grep
for "NOTE" in the Go code for more details.

This commit picks up an upstream change:
https://go-review.googlesource.com/14410 "tidy up some flush calls"

Picking up the more recent change:
https://go-review.googlesource.com/42032 "fix hi code overflow"
will be a follow-up commit, separate from this straightforward commit,
since it has a non-trivial interaction with that off by one.

Change-Id: Iaf795d11590b3e3e0891e3ea3f04b696de4243c9
Reviewed-on: https://go-review.googlesource.com/42191
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-30 11:58:49 +00:00
kim yongbin
a74d51e6d3 tiff: remove InternalError which is not used anywhere.
Change-Id: I92fd800bafd380797651e158c9385dcf3d3578da
Reviewed-on: https://go-review.googlesource.com/40892
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-04-16 14:51:06 +00:00
Benny Siegert
1be1b0af35 tiff: reject TIFF images with unsorted IFD tags.
The spec says that these images are invalid. Add a test with an invalid
tiff generated by go-fuzz.

Fixes golang/go#10549

Change-Id: I3fd3ae5e607202b41735a2d930f55cb7997f7a9b
Reviewed-on: https://go-review.googlesource.com/9377
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-04 16:59:28 +00:00
Nigel Tao
92cae9f9bc tiff/lzw: sync (yet again) to the upstream lzw in the stdlib.
This picks up a recent change:
https://go-review.googlesource.com/#/c/11661/

Change-Id: I0309f7b804e0d88ea623c8ae97b65cd0c2bad101
Reviewed-on: https://go-review.googlesource.com/11850
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-07-02 03:36:51 +00:00
Nigel Tao
eb11b45157 tiff/lzw: sync (again) to the upstream lzw in the stdlib.
I somehow missed this in the previous change. Not sure how.

Change-Id: Ib9277944418a73cda6acc07fc308d846b4064b9e
Reviewed-on: https://go-review.googlesource.com/11321
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-22 01:01:28 +00:00
Nigel Tao
ef56035c4b tiff/lzw: sync to the upstream lzw in the stdlib.
Change-Id: If6086ada81498327c61e91b18d135aa255401e68
Reviewed-on: https://go-review.googlesource.com/11320
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-06-22 00:56:16 +00:00
Jeff R. Allen
090ed236cf image/tiff: replace repeated error creations with one
Make all occurrences of "not enough pixel data" refer to the
same one.

Change-Id: Iecff9f22eba7a8852174ba18d1e68226c76f84c6
Reviewed-on: https://go-review.googlesource.com/11030
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-22 00:40:40 +00:00
Nigel Tao
d6cb0a28ce tiff: re-organize some test cases, and make comment style consistent.
There is no code changes in this CL, just a copy/paste and some
wordsmithing.

Change-Id: I418e8aed5ab997fad4214e8049287cac4bce8bf6
Reviewed-on: https://go-review.googlesource.com/11274
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-19 07:18:22 +00:00
Nigel Tao
e5f3f2f6c0 tiff: format the find/replace test strings consistently.
Change-Id: Id3222a76702e8f2017aec77a25df715ef378c8ef
Reviewed-on: https://go-review.googlesource.com/11224
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-18 23:38:30 +00:00
Jeff R. Allen
b7cdfbb5c4 image/tiff: fix a panic with invalid tile sizes
Fuzzing detected that an invalid tile size could cause a
panic. Fix a typo in the range check to solve it.

Fixes golang/go#10712.

Change-Id: I88a5a7884d98f622cc89ed6e394becebb07c6e60
Reviewed-on: https://go-review.googlesource.com/11020
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-18 01:57:12 +00:00
Nigel Tao
9af7e1b58b tiff: don't apply the 8 bps predictor to a 1 bps image.
Change-Id: I112fc7189f8afdd54b96562e1989f9fca1d24d68
Reviewed-on: https://go-review.googlesource.com/11135
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-18 01:44:20 +00:00
Jeff R. Allen
3157439762 image/tiff: do not allow zero bits per sample
Fuzzing detected a divide by zero in images with 0 bits
per sample. Instead of panicing, return an error. Do more
validation of bits per sample so that the package only
supports what we've actually tested.

Fixes golang/go#10711.

Change-Id: Ib41b5cd798c32b06429164c9bc471f5f321d88c5
Reviewed-on: https://go-review.googlesource.com/10943
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-16 21:37:07 +00:00
chai2010
4a3ed0c124 tiff: don't panic on reading bad ifd
Fixes golang/go#10597

Change-Id: I57b3614de7181134cf4bd0ca9dc9ff879d3d2e3d
Reviewed-on: https://go-review.googlesource.com/9414
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-05-05 06:22:24 +00:00
Benny Siegert
6af46c2009 tiff: reject IFDs whose data is longer than int.
Fixes golang/go#10596

Change-Id: Ib5035569e84c67868c7f278281620f6c9b11b470
Reviewed-on: https://go-review.googlesource.com/9378
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-05-04 03:48:26 +00:00
Nigel Tao
b2f48f3f51 tiff: don't panic on reading short block data.
Fixes golang/go#10394

Change-Id: I12621650f0c21579047497407ca2745febe4521b
Reviewed-on: https://go-review.googlesource.com/9278
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-04-28 01:06:15 +00:00
Håvard Haugen
72a6583050 x/image/tiff: fix division by zero when decoding empty image
Return a zero width or zero height image of the appropriate type.

Fixes golang/go#10393.

Change-Id: I3aa7b6125447726600fb072ce1e8682373ce2a57
Reviewed-on: https://go-review.googlesource.com/9182
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-04-28 00:39:31 +00:00
chai2010
f681781743 tiff: fix shadowed err variable.
Fixes golang/go#10395

Change-Id: Ice768df7bb0bdac979d49328bfdf0d6713a1e7c3
Reviewed-on: https://go-review.googlesource.com/9264
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-04-24 01:40:59 +00:00
David Symonds
0351284b2d image: add import comments.
Change-Id: I2d3a1d002ad43af24cd8b451a2cae4c217482675
Reviewed-on: https://go-review.googlesource.com/1237
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-09 22:43:18 +00:00
Andrew Gerrand
2e99ef522d go.image: use golang.org/x/... import paths
LGTM=bradfitz, rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/169090043
2014-11-10 08:52:14 +11:00
Nigel Tao
34eb6b7c8b go.image/tiff: remove unreachable code.
This makes "go vet code.google.com/p/go.image/..." happy.

LGTM=dsymonds
R=dsymonds
CC=golang-codereviews
https://golang.org/cl/103630047
2014-06-30 11:43:54 +10:00
Nigel Tao
a1da419f1a go.image/tiff: fix (TIFF-specific) LZW decompression.
The blue-purple-pink.lzwcompressed.tiff image was created by
"bmp2tiff -c lzw".

LGTM=djd
R=djd
CC=bsiegert, golang-codereviews
https://golang.org/cl/105750045
2014-06-02 14:51:51 +10:00
Nigel Tao
2bda575717 go.image/tiff/lzw: fork the standard library's compress/lzw package.
This CL has no code changes. Future CLs will modify the code to
implement TIFF's LZW instead of the standard LZW.

LGTM=bradfitz
R=djd, bradfitz
CC=golang-codereviews
https://golang.org/cl/105750044
2014-06-02 13:56:21 +10:00
Patrick Riley
38c1f4ffe8 go.image/tiff: Support missing Compression tag
no_compress.tiff is no_rps.tiff that was read in by go.image/tiff and written out again (with a hack to avoid creating the Compression tag on the way out).

$ tiffdump no_compress.tiff
no_compress.tiff:
Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 968 (0x3c8) next 0 (0)
ImageWidth (256) SHORT (3) 1<16>
ImageLength (257) SHORT (3) 1<15>
BitsPerSample (258) SHORT (3) 4<8 8 8 8>
Photometric (262) SHORT (3) 1<2>
StripOffsets (273) LONG (4) 1<8>
SamplesPerPixel (277) SHORT (3) 1<4>
RowsPerStrip (278) SHORT (3) 1<15>
StripByteCounts (279) LONG (4) 1<960>
XResolution (282) RATIONAL (5) 1<72>
YResolution (283) RATIONAL (5) 1<72>
ResolutionUnit (296) SHORT (3) 1<2>
ExtraSamples (338) SHORT (3) 1<2>

LGTM=bsiegert, nigeltao
R=bsiegert, nigeltao
CC=golang-codereviews
https://golang.org/cl/95930044
2014-05-12 16:41:44 +10:00
ChaiShushan
420d421738 go.image/tiff: encoder fix non LZW Predictor and Paletted SamplesPerPixel and non RGB ExtraSamples.
TIFF6.0 Spec:
Page 31: ExtraSamples can only included in RGB mode image.
Page 39, SamplesPerPixel is usually 1 for bilevel, grayscale, and palette-color images.
Page 64, Currently Predictor field is used only with LZW.

Fixes golang/go#6421.

R=bsiegert, nigeltao, gbulmer
CC=golang-dev
https://golang.org/cl/13779043
2013-09-22 11:21:53 +10:00
ChaiShushan
b2d744f611 go.image/tiff: support 16bit RGB
R=nigeltao, bsiegert
CC=golang-dev
https://golang.org/cl/13736044
2013-09-18 17:16:05 +10:00
ChaiShushan
e39b2394e5 go.image/tiff: encoder support Gray/Gray16/Paletted format
Use these commands to generate testdata:

# TIFF Tools
tiff2bw    video-001.tiff video-001-gray.tiff
tiffmedian video-001.tiff video-001-paletted.tiff

# ImageMagick
convert -depth 16 video-001.tiff      video-001-16bit.tiff
convert -depth 16 video-001-gray.tiff video-001-gray-16bit.tiff

R=nigeltao, bsiegert
CC=golang-dev
https://golang.org/cl/13243047
2013-09-13 17:42:53 +10:00
ChaiShushan
de306d5329 go.image/tiff: decoder support tiled tiff format
Use these commands to generate testdata:
tiffcp -s -r 64 video-001.tiff video-001-strip-64.tiff
tiffcp -t -l 64 -w 64 video-001.tiff video-001-tile-64x64.tiff

R=golang-dev, nigeltao, bsiegert
CC=golang-dev
https://golang.org/cl/13453043
2013-09-06 20:07:58 +10:00
ChaiShushan
822abc7ef1 go.image/tiff: add missing encoder to pkg doc
R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/13302045
2013-09-02 13:29:55 +10:00
Benny Siegert
26936f5590 go.image/tiff: Support reading 16-bit gray images.
Fixes golang/go#5866.

R=nigeltao
CC=golang-dev
https://golang.org/cl/11920043
2013-07-30 15:02:33 +10:00
Benny Siegert
d165204442 go.image/tiff: support for writing compressed images.
Only Deflate compression is supported for now.

R=nigeltao, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/6866051
2012-12-12 13:24:12 +11:00
Benny Siegert
41cf08abcf tiff: support writing files with differencing predictor.
This will make more sense after implementing compression.

R=nigeltao
CC=golang-dev
https://golang.org/cl/6567077
2012-10-03 10:11:21 +10:00
Benny Siegert
5198c64fc9 tiff: new Options parameter for Encode.
No functional change at the moment but it will allow choosing
the compression type.

This is an incompatible, user-visible change. To get the old
behavior, callers of tiff.Encode need to add ", nil" as the
last parameter.

R=nigeltao
CC=golang-dev
https://golang.org/cl/6479044
2012-08-23 20:16:03 +10:00
Benny Siegert
c35a1ecb6c go.image/tiff: use optimized routines for RGBA and NRGBA
Performance for an RGBA image:

benchmark          old ns/op    new ns/op    delta
BenchmarkEncode      1633495         7897  -99.52%

benchmark           old MB/s     new MB/s  speedup
BenchmarkEncode        37.83      7824.96  206.85x

NRGBA images are now encoded as such, the spec calls it
"unassociated alpha".

R=nigeltao, rsc
CC=golang-dev
https://golang.org/cl/6308049
2012-06-13 10:40:38 +10:00
Benny Siegert
de792da79c go.image/tiff: add a benchmark for the encoder
The idea is to see whether it is worthwhile to implement special cases.

On my Mac Book Pro:

BenchmarkEncode	    1000	   1689656 ns/op	  36.69 MB/s

R=nigeltao, minux.ma
CC=golang-dev
https://golang.org/cl/6278050
2012-06-07 09:41:24 +10:00
Nigel Tao
20e9620e99 go.image/tiff: simplify encoding.
R=bsiegert
CC=golang-dev
https://golang.org/cl/5738044
2012-03-07 10:32:33 +11:00
Benny Siegert
f594c3aad5 go.image/tiff: initial support for writing TIFF images
The basic functionality works. Features to add in future CLs:

- compression
- fast paths for image formats that can be directly expressed in TIFF,
  such as RGBA, NRGBA and maybe Gray and Paletted.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5694051
2012-03-05 11:45:47 +11:00
Benny Siegert
324e6dabf0 go.image/tiff: optimize reading uncompressed files from a tiff.buffer.
In case the image is read via a tiff.buffer, avoid copying the
data strip before decoding it. Remove corresponding TODO.
Speeds up reading uncompressed images (which is the common case)
and uses much less memory.

benchmark                      old ns/op    new ns/op    delta
BenchmarkDecodeCompressed        4619438      4630774   +0.25%
BenchmarkDecodeUncompressed       260809       219875  -15.70%

R=nigeltao
CC=golang-dev
https://golang.org/cl/5683050
2012-02-21 11:25:19 +11:00
Nigel Tao
996c335c4a go.image/{bmp,tiff}: move tiff/testdata to testdata.
Add a "compare to golden PNG" test for BMP and TIFF.

R=rsc
CC=golang-dev
https://golang.org/cl/5601054
2012-01-31 14:02:27 +11:00
Nigel Tao
cc3e6234e7 go.image: initial code.
Manual edits to README.
Moved from main Go repository, deleted Makefiles.

Tested with go test code.google.com/p/go.image/...

Fixes golang/go#2797.

R=rsc, rsc, r
CC=golang-dev
https://golang.org/cl/5593053
2012-01-31 11:32:50 +11:00