1
0
mirror of https://github.com/golang/go synced 2024-10-01 01:18:32 -06:00
Commit Graph

49 Commits

Author SHA1 Message Date
Nigel Tao
62ea2c9093 image/gif: be consistent wrt "color map" or "color table" names.
The spec at http://www.w3.org/Graphics/GIF/spec-gif89a.txt always says
"color table" and not "color map".

Change-Id: I4c172e3ade15618cbd616629822ce7d109a200af
Reviewed-on: https://go-review.googlesource.com/9668
Reviewed-by: Rob Pike <r@golang.org>
2015-05-05 06:14:41 +00:00
Nigel Tao
4ddd751c92 image/gif: don't encode local color tables if they're the same as the
global color table.

Change-Id: Ia38f75708ed5e5b430680a1eecafb4fc8047269c
Reviewed-on: https://go-review.googlesource.com/9467
Reviewed-by: Rob Pike <r@golang.org>
2015-05-04 06:38:54 +00:00
Nigel Tao
6abfdc3fdd image/gif: check that individual frame's bounds are within the overall
GIF's bounds.

Also change the implicit Config Width and Height to be the
Rectangle.Max, not the Dx and Dy, of the first frame's bounds. For the
case where the first frame's bounds is something like (5,5)-(8,8), the
overall width should be 8, not 3.

Change-Id: I3affc484f5e32941a36f15517a92ca8d189d9c22
Reviewed-on: https://go-review.googlesource.com/9465
Reviewed-by: Rob Pike <r@golang.org>
2015-04-29 04:42:01 +00:00
Nigel Tao
baf3814b29 image/gif: encode disposal, bg index and Config.
The previous CL implemented decoding, but not encoding.

Also return the global color map (if present) for DecodeConfig.

Change-Id: I3b99c93720246010c9fe0924dc40a67875dfc852
Reviewed-on: https://go-review.googlesource.com/9389
Reviewed-by: Rob Pike <r@golang.org>
2015-04-28 23:01:37 +00:00
Nigel Tao
ba8fa0e1a9 image/png: don't silently swallow io.ReadFull's io.EOF error when it
lands exactly on an IDAT row boundary.

Fixes #10493

Change-Id: I12be7c5bdcde7032e17ed1d4400db5f17c72bc87
Reviewed-on: https://go-review.googlesource.com/9270
Reviewed-by: Rob Pike <r@golang.org>
2015-04-23 06:39:56 +00:00
Nigel Tao
5e9ab665fb image/jpeg: have the LargeImageWithShortData test only allocate 64 MiB, not 604
MiB.

Fixes #10531

Change-Id: I9eece86837c3df2b1f7df315d5ec94bd3ede3eec
Reviewed-on: https://go-review.googlesource.com/9238
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2015-04-23 00:32:59 +00:00
Nigel Tao
72e867ed8e image/jpeg: ensure that we can't unread a byte if we didn't read a byte.
Fixes #10413

Change-Id: I7a4ecd042c40f786ea7406c670d561b1c1179bf0
Reviewed-on: https://go-review.googlesource.com/8998
Reviewed-by: Rob Pike <r@golang.org>
2015-04-22 00:20:17 +00:00
Nigel Tao
28388c4eb1 image/color: have Palette.Index honor alpha for closest match, not just
red, green and blue.

Fixes #9902

Change-Id: Ibffd0aa2f98996170e39a919296f69e9d5c71545
Reviewed-on: https://go-review.googlesource.com/8907
Reviewed-by: Rob Pike <r@golang.org>
2015-04-16 23:52:41 +00:00
Nigel Tao
f5b5e41814 image: spell coordinate consistently, without the hyphen.
Change-Id: I211c0d33dc292c6a703d788f6d4d286107bcb6b0
Reviewed-on: https://go-review.googlesource.com/8906
Reviewed-by: Rob Pike <r@golang.org>
2015-04-16 01:21:31 +00:00
Nigel Tao
7e7d55f888 image/png: reject multiple tRNS chunks.
http://www.w3.org/TR/PNG/#5ChunkOrdering disallows them.

Fixes #10423

Change-Id: I3399ce53dc8b41b1b5f0b906a5912e6efd80418f
Reviewed-on: https://go-review.googlesource.com/8905
Reviewed-by: Rob Pike <r@golang.org>
2015-04-15 04:35:27 +00:00
Nigel Tao
2f98bac310 image/jpeg: don't assume that an ensureNBits failure implies that we can
call unreadByteStuffedByte.

If ensureNBits was due to an io.EOF that was translated to
jpeg.errShortHuffmanData, then we may have read no bytes, so there is no
byte-stuffed-byte to unread.

Fixes #10387

Change-Id: I39a3842590c6cef2aa48943288d52f603338b44d
Reviewed-on: https://go-review.googlesource.com/8841
Reviewed-by: Rob Pike <r@golang.org>
2015-04-14 07:22:44 +00:00
Colin Kennedy
e6092d64a7 image/gif: expose disposal, bg index and Config
The background index in the global palette (located in the image.Config)
is necessary for interpreting GIF frames properly

Frame disposal information is necessary for interpreting GIF frames in
the context of a sequence (or animation)

Removes decoder.flags as it can be a local variable

Change-Id: I6790a7febf6ba0859175c834c807bc6413e6b194
Reviewed-on: https://go-review.googlesource.com/4620
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-04-13 04:35:04 +00:00
Nigel Tao
eb44082915 image/jpeg: reject multiple Start-Of-Frame markers.
Fixes #10389

Change-Id: Id1c687122751f9317041d9e425d03b267a26c6de
Reviewed-on: https://go-review.googlesource.com/8681
Reviewed-by: Rob Pike <r@golang.org>
2015-04-09 02:32:23 +00:00
Nigel Tao
0def13ac3f image/color: have CMYK.RGBA work in 16-bit color, per the Color interface.
Change-Id: I3621527c924a43724032f80a072505c60d929ab3
Reviewed-on: https://go-review.googlesource.com/8180
Reviewed-by: Rob Pike <r@golang.org>
2015-04-08 03:39:11 +00:00
Nigel Tao
180fbb16c4 image/draw: fix golden test for YCbCr.RGBA change.
The previous change was
https://go-review.googlesource.com/#/c/8073/

Change-Id: I0c48502d1ba90fb5d41c5e66346a8e7f4ee87ce7
Reviewed-on: https://go-review.googlesource.com/8151
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-03-27 00:30:14 +00:00
Nigel Tao
2f34e606fa image/color: have YCbCr.RGBA work in 16-bit color, per the Color
interface.

Change-Id: Ie025753df08ae93e7a5095a3426aff15fa2016fd
Reviewed-on: https://go-review.googlesource.com/8073
Reviewed-by: Rob Pike <r@golang.org>
2015-03-26 22:30:55 +00:00
Nigel Tao
a3a193c018 image/internal/imageutil: inline the color.YCbCrToRGB calls.
The image/draw benchmark:
benchmark          old ns/op     new ns/op     delta
BenchmarkYCbCr     1198605       978647        -18.35%

Change-Id: Iacfc21e6f641ecb05adc00b3aec0048f1f43d265
Reviewed-on: https://go-review.googlesource.com/7952
Reviewed-by: Rob Pike <r@golang.org>
2015-03-25 21:01:57 +00:00
Nigel Tao
7180cfa864 image/internal/imageutil: generate subsample-ratio-specific code.
This is in preparation for inlining the color.YCbCrToRGB calls in a
follow-up change.

Change-Id: I30750ace11a8ef6016b3c1e0b4bfdbcc8151f9a5
Reviewed-on: https://go-review.googlesource.com/7951
Reviewed-by: Rob Pike <r@golang.org>
2015-03-24 01:01:20 +00:00
Nigel Tao
b2f29511dd image/internal/imageutil: new package, used by image/draw and image/jpeg.
The imageutil.DrawYCbCr function lives in an internal package because it
is needed by both the image/draw and image/jpeg packages, but it doesn't
seem right for one of those two to depend on the other.

It could eventually go into the image package, but that would require
committing to an API for the rest of Go 1.x.

Change-Id: I7b12555c970d86409365e99eef9360702aaffa30
Reviewed-on: https://go-review.googlesource.com/7925
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-03-23 23:22:58 +00:00
Nigel Tao
25bf792197 image/color: add alpha-premultiplied comment.
Change-Id: I9968f53a8286a0e5ccc197a9b5fae499e2f95326
Reviewed-on: https://go-review.googlesource.com/7790
Reviewed-by: Rob Pike <r@golang.org>
2015-03-21 06:15:57 +00:00
Nigel Tao
3eb84c8908 image/jpeg: reject bad Tq values in SOF data.
Fixes #10154

Change-Id: Ibb8ea9bcf512e7639c57a6f17afbe4495fa329cd
Reviewed-on: https://go-review.googlesource.com/7494
Reviewed-by: Minux Ma <minux@golang.org>
2015-03-13 05:22:55 +00:00
Nigel Tao
782db7fc88 image/jpeg: support chroma hv values other than 0x11.
The testdata was generated by:
convert video-001.png tmp1.tga
cjpeg -quality 100 -sample 2x2,1x2,1x2 tmp1.tga > video-001.221212.jpeg
djpeg -nosmooth -targa video-001.221212.jpeg > tmp2.tga
convert tmp2.tga video-001.221212.png
rm tmp1.tga tmp2.tga

Change-Id: Ica241dfc19b3eb47ade150bf0432373c6006c38a
Reviewed-on: https://go-review.googlesource.com/7264
Reviewed-by: Rob Pike <r@golang.org>
2015-03-11 00:10:09 +00:00
Nigel Tao
cc009687bc image/jpeg: support RGB JPEG images.
The testdata was generated by:
convert video-001.png tmp1.tga
cjpeg -rgb -sample 2x2,1x1,1x1 tmp1.tga > video-001.rgb.jpeg
djpeg -nosmooth -targa video-001.rgb.jpeg > tmp2.tga
convert tmp2.tga video-001.rgb.png
rm tmp1.tga tmp2.tga

Change-Id: I5da0591b9005c1c75e807311f157d385e0e20a38
Reviewed-on: https://go-review.googlesource.com/6910
Reviewed-by: Rob Pike <r@golang.org>
2015-03-09 23:18:33 +00:00
Nigel Tao
9b73ecc327 image/jpeg: check for component uniqueness and total sampling factors.
Change-Id: I83de9d83708edc8d196bbcfdc7d2ba7ffaff50d2
Reviewed-on: https://go-review.googlesource.com/6586
Reviewed-by: Rob Pike <r@golang.org>
2015-03-04 22:44:28 +00:00
Nigel Tao
848e2feac6 image: make Rectangle implement Image.
Change-Id: I01e328fc3644b679bacf2209c3d7ade9d8bffe53
Reviewed-on: https://go-review.googlesource.com/6551
Reviewed-by: Rob Pike <r@golang.org>
2015-03-04 00:03:46 +00:00
Nigel Tao
0fe6b1293a image/jpeg: when following component selectors, only consider valid
components.

This fixes decoding JPEG images where the component selector is 0. Such
images are rare, but not impossible.

Change-Id: I6d221bce01cce8cc0440e117543233371782ca22
Reviewed-on: https://go-review.googlesource.com/6421
Reviewed-by: Rob Pike <r@golang.org>
2015-03-03 00:01:43 +00:00
Nigel Tao
a773fae808 image/jpeg: distinguish between FormatError and UnsupportedError when
encountering unknown markers.

Change-Id: Ica86013308d69da2f5b486119235ff693135b2f1
Reviewed-on: https://go-review.googlesource.com/6393
Reviewed-by: David Symonds <dsymonds@golang.org>
Run-TryBot: David Symonds <dsymonds@golang.org>
2015-03-02 00:53:23 +00:00
Nigel Tao
c20323d2bb image/draw: add a fast path for Gray src images.
Grayscale PNG and JPEG images are not uncommon. We should have a fast path.

Also add a benchmark for the recently added CMYK fast path.

benchmark                    old ns/op     new ns/op     delta
BenchmarkGray                13960348      324152        -97.68%

Change-Id: I72b5838c8c3d1f2d0a4536a848e020e80b10c0f7
Reviewed-on: https://go-review.googlesource.com/6237
Reviewed-by: Rob Pike <r@golang.org>
2015-02-28 21:43:39 +00:00
Nigel Tao
66c4031ee9 image/draw: optimize drawFillSrc.
benchmark                    old ns/op     new ns/op     delta
BenchmarkFillSrc             46781         46000         -1.67%

Change-Id: I0ab25d42d5763f1a0fe5a67ee00b83f0aa55f1f6
Reviewed-on: https://go-review.googlesource.com/6235
Reviewed-by: Rob Pike <r@golang.org>
2015-02-28 01:26:54 +00:00
Nigel Tao
a32dd83253 image/jpeg: support 4:1:1 and 4:1:0 chroma subsampling.
The test data was generated by:
convert video-001.png tmp.tga
cjpeg -quality 50 -sample 4x2,1x1,1x1 tmp.tga > video-001.q50.410.jpeg
cjpeg -quality 50 -sample 4x1,1x1,1x1 tmp.tga > video-001.q50.411.jpeg
cjpeg -quality 50 -sample 4x2,1x1,1x1 -progressive tmp.tga > video-001.q50.410.progressive.jpeg
cjpeg -quality 50 -sample 4x1,1x1,1x1 -progressive tmp.tga > video-001.q50.411.progressive.jpeg
rm tmp.tga

Change-Id: I5570389c462360f98c3160f3c6963d9466d511de
Reviewed-on: https://go-review.googlesource.com/6041
Reviewed-by: Rob Pike <r@golang.org>
2015-02-26 02:08:45 +00:00
Nigel Tao
7d7351395d image: add YCbCrSubsampleRatio411 and YCbCrSubsampleRatio410.
Some real world JPEG images are in 4:1:1 and 4:1:0 formats.

See also http://en.wikipedia.org/wiki/Chroma_subsampling

Change-Id: I2d51a41944f581cf11f4ab975046b1737271842f
Reviewed-on: https://go-review.googlesource.com/5838
Reviewed-by: Rob Pike <r@golang.org>
2015-02-26 00:14:16 +00:00
Nigel Tao
270f8447d6 image/jpeg: support 16-bit quantization tables and Extended Sequential
frames.

Fixes #9888.

Change-Id: I60f1d843e72e1b7bc77ab984f149c9ddb5258a06
Reviewed-on: https://go-review.googlesource.com/5251
Reviewed-by: Rob Pike <r@golang.org>
2015-02-19 05:00:43 +00:00
Nigel Tao
84c7a6583a image: change Rectangle.Eq to return true for all empty rectangles, even
if their nominal Min and Max points differ.

This is a behavior change, but arguably a bug fix, as Eq wasn't
previously consistent with In, and the concept of a rectangle being a
set of points. This is demonstrated by the new geom_test.go test.

It does mean that r.Eq(s) no longer implies that Inset'ting both r and s
with a negative inset results in two rectangles that are still Eq, but
that seems acceptable to me.

The previous behavior is still available as "r == s".

Also clarify the image.Rect doc comment when the inputs are
non-canonical.

Also simplify the Point and Rectangle Eq implementations dating from
before Go 1.0, when you couldn't compare structs via the == operator.

Change-Id: Ic39e628db31dc5fe5220f4b444e6d5000eeace5b
Reviewed-on: https://go-review.googlesource.com/5006
Reviewed-by: Rob Pike <r@golang.org>
2015-02-18 23:50:09 +00:00
Nigel Tao
391805b14b image/draw: add CMYK fast path.
Change-Id: I9582aff7ca141a8aead5692af74b9c708b1700cc
Reviewed-on: https://go-review.googlesource.com/5020
Reviewed-by: Rob Pike <r@golang.org>
2015-02-17 23:17:12 +00:00
Nigel Tao
5c8f9e38eb image: fix Rectangle.Overlaps and Rectangle.Union for empty rectangles.
Fixes #9895.

Change-Id: I37d78ced9ff8196e32d299504908a1c41ad4592d
Reviewed-on: https://go-review.googlesource.com/4990
Reviewed-by: Rob Pike <r@golang.org>
2015-02-17 03:40:33 +00:00
Nigel Tao
37a61746ee image/draw: add CMYK test.
This just adds test cases. Optimizing CMYK draws will be a follow-up
change.

Change-Id: Ic0d6343d420cd021e21f88623ad7182e93017da9
Reviewed-on: https://go-review.googlesource.com/4941
Reviewed-by: Rob Pike <r@golang.org>
2015-02-17 00:08:47 +00:00
Nigel Tao
10a4696fb8 image/jpeg: remove the (temporary) dependency on image/draw.
Change-Id: Idd66f9c3c9eaa4ff1f950fb90e4800dc625dec08
Reviewed-on: https://go-review.googlesource.com/4916
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2015-02-16 04:37:15 +00:00
Nigel Tao
f10e03770c image/jpeg: support decoding CMYK and YCbCrK images.
The new testdata was created by:

convert video-001.png -colorspace cmyk video-001.cmyk.jpeg

video-001.cmyk.jpeg was then converted back to video-001.cmyk.png via
the GIMP. ImageMagick (convert) wasn't used for this second conversion
because IM's default color profiles complicates things.

Fixes #4500.

Change-Id: Ibf533f6a6c7e76883acc493ce3a4289d7875df3f
Reviewed-on: https://go-review.googlesource.com/4801
Reviewed-by: Rob Pike <r@golang.org>
2015-02-16 00:25:47 +00:00
Nigel Tao
b5c3a9e572 image: add image.CMYK and color.CMYK types.
Change-Id: Icf212a4b890725c803b16e76e1a88294b8b62cb8
Reviewed-on: https://go-review.googlesource.com/4800
Reviewed-by: Rob Pike <r@golang.org>
2015-02-16 00:08:49 +00:00
Andrew Ekstedt
f5f00be2ec image: fix obsolete reference in PalettedImage doc comment
PalettedColorModel was renamed to color.Palette
over three years ago by https://golang.org/cl/5132048.

Change-Id: I0204ade10eabff45620fda2990fed428c65d871e
Reviewed-on: https://go-review.googlesource.com/3305
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-02-06 04:06:44 +00:00
Andrew Ekstedt
dfc4997ede image: fix typo in Alpha16 doc comment
Change-Id: Ie7031ae37f52ea1f229bfb769daf306d537b3d3e
Reviewed-on: https://go-review.googlesource.com/3300
Reviewed-by: Minux Ma <minux@golang.org>
2015-01-25 22:46:49 +00:00
Nigel Tao
9785a3962d image/draw: fold TestClipWithNilMP into TestClip.
https://go-review.googlesource.com/#/c/1876/ introduced a new
TestClipWithNilMP test, along with a code change that fixed a panic,
but the existing TestClip test already contained almost enough machinery
to cover that bug.

There is a small code change in this CL, but it is a no-op: (*x).y is
equivalent to x.y for a pointer-typed x, but the latter is cleaner.

Change-Id: I79cf6952a4999bc4b91f0a8ec500acb108106e56
Reviewed-on: https://go-review.googlesource.com/2304
Reviewed-by: Dave Cheney <dave@cheney.net>
2015-01-14 06:04:13 +00:00
Nigel Tao
0b52392ef7 image: use three-index slice for NewYCbCr.
This ensures that changing an image.YCbCr's Y values can't change its
chroma values, even after re-slicing up to capacity.

Change-Id: Icb626561522e336a3220e10f456c95330ae7db9e
Reviewed-on: https://go-review.googlesource.com/2209
Reviewed-by: Rob Pike <r@golang.org>
2015-01-05 03:32:15 +00:00
Dave Cheney
64e6fe2d29 image/draw: fix crash in clip
Fixes #9177

Change-Id: I1c7e57f0f0a9b00fb3ddc7fa4844ac53ea6df46f
Reviewed-on: https://go-review.googlesource.com/1876
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-20 06:00:38 +00:00
Russ Cox
04923042bd image/jpeg: handle Read returning n > 0, err != nil in d.fill
Fixes #9127.

LGTM=r
R=bradfitz, r
CC=golang-codereviews, nigeltao
https://golang.org/cl/178120043
2014-11-22 13:55:33 -05:00
Nigel Tao
0be3176a8b image/gif: don't let the per-frame transparent index modify the global
palette.

Fixes #7993.

LGTM=r
R=r
CC=golang-codereviews, james.jdunne
https://golang.org/cl/138600043
2014-09-22 14:29:45 +10:00
Nigel Tao
a2910958a2 image/gif: fix GIF encoding of sub-images.
benchmark                    old ns/op     new ns/op     delta
BenchmarkEncode              8641055       8646829       +0.07%

Fixes #7792.

LGTM=r
R=r
CC=dbathgate, golang-codereviews
https://golang.org/cl/147730043
2014-09-18 12:43:01 +10:00
Nigel Tao
8e77a7ef6b image/jpeg: reject invalid Ta and Td values.
Fixes #8693.

LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/141470043
2014-09-15 08:41:59 +10:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00