Граф коммитов

50 Коммитов

Автор SHA1 Сообщение Дата
Russ Cox 99f80d0ecb all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae65e4d8854b66205e4cbcdd1ae0eec48c582496
Reviewed-on: https://go-review.googlesource.com/c/image/+/399615
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
2022-04-12 02:13:10 +00:00
Benny Siegert a8550c1d25 tiff: do not crash when encoding with unsupported compression
tiff.Encode only supports uncompressed and deflate compression. When called
with a different compression type, it crashes with a nil pointer dereference.
Return a proper error instead.

Fixes golang/go#43137

Change-Id: I5dd9210ff0ae11b7e4f641375f26c6afc1515b98
Reviewed-on: https://go-review.googlesource.com/c/image/+/380334
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2022-03-21 03:14:19 +00:00
cuishuang 723b81ca98 all: fix typos
Change-Id: I8f9f58babea80bbdad52df2b67a083f3a381c217
GitHub-Last-Rev: 79ce945721
GitHub-Pull-Request: golang/image#8
Reviewed-on: https://go-review.googlesource.com/c/image/+/389054
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
2022-03-02 09:49:43 +00:00
Russ Cox ac19c3e999 all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: Ib758eb8b75286993f3bd83b5004be667846118d4
Reviewed-on: https://go-review.googlesource.com/c/image/+/294419
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-02-20 03:29:44 +00:00
Sardorbek Pulatov da761ea9ff tiff, bmp: return io.UnexpectedEOF on empty data
Check for an EOF when decoding the tiff and bmp headers,
so that decoding empty data does not return an EOF.

Fixes golang/go#11391

Change-Id: I73394b9dcc0d2e4e2a7bc56addb3f690791820ba
GitHub-Last-Rev: 924636fca1
GitHub-Pull-Request: golang/image#3
Reviewed-on: https://go-review.googlesource.com/c/image/+/205458
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2019-12-06 06:52:43 +00:00
Nigel Tao 3a9bac650e tiff/lzw: don't follow code == hi if last is invalid
This does for x/image what
https://go-review.googlesource.com/c/go/+/45111/ did for the standard
library's compress/lzw.

The x variant is a fork of the stdlib, with an extra, explicit tweak
because the TIFF format is "off by one" - a mistake (not Go specific)
somebody introduced decades ago and that we can never fix, given all the
existing TIFF files out there in the wild.

When previously patching the stdlib variant, I was supposed to also
patch the x variant, but forgot.

Updates golang/go#11386

Change-Id: Ic74f9014d2d048ee12cdd151332db62b76f1cde2
Reviewed-on: https://go-review.googlesource.com/c/image/+/191221
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-08-23 06:40:33 +00:00
Horst Rutter 7e034cad64 tiff: Add support for CCITT group 3/4 compression
The algorithm is described at https://www.itu.int/rec/T-REC-T.6/en

Fixes golang/go#19443

Change-Id: Ib8a078ab43c78d1f58d2ac849ed455b05dc209e9
Reviewed-on: https://go-review.googlesource.com/c/image/+/174139
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-22 00:34:08 +00:00
Benny Siegert 6d32002ffd tiff: mark test and benchmark helpers
Mark helper functions for tiff tests with t.Helper and b.Helper
respectively.

Change-Id: I3242d5a9b319bcf8de17e34c731bcd1910acfb2b
Reviewed-on: https://go-review.googlesource.com/c/image/+/174140
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2019-05-01 04:58:29 +00:00
Andrei Tudor Călin 3fc05d484e tiff: add Fuzz function
This change adds a sample Fuzz test function to package tiff, under
the gofuzz build tag. The function is based on the tiff/tiff.go code,
from github.com/dvyukov/go-fuzz-corpus.

Fixes golang/go#30719
Updates golang/go#19109

Change-Id: I78771e9a1bd01651ba6ca421ba41f0c0e95d0c53
Reviewed-on: https://go-review.googlesource.com/c/image/+/167097
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: thepudds <thepudds1460@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2019-03-21 06:31:52 +00:00
Igor Zhilianin 69cc3646b9 all: fix typos
Change-Id: I2140a1a74d1319d9b8746efad539bfaae6038a2d
GitHub-Last-Rev: b00b49e87e
GitHub-Pull-Request: golang/image#1
Reviewed-on: https://go-review.googlesource.com/c/145740
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-30 00:21:51 +00:00
monkeybutter f315e44030 tiff: fixes problem with decoding tiled uint16 tiff files.
The proposed fix updates the x axis offset variable in case the tile
surpasses the limits of the destination image.

Fixes golang/go#24657

Change-Id: I6bc52274a05dc41b058f6a6f1d0a304f1b20152d
Reviewed-on: https://go-review.googlesource.com/104295
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-03 16:11:27 +00:00
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