Commit Graph

159 Commits

Author SHA1 Message Date
Nigel Tao
c4226c0d9c font/basicfont: add Descent and Left fields.
A face's glyph height (the height of the glyph image) isn't necessarily
the inter-line spacing: f.Ascent + f.Descent isn't always f.Height.

Similarly, a face's glyph image's left side isn't always dot.X.

Change-Id: I86594c52b8d31bf652ac34a695e9270ac635a5bc
Reviewed-on: https://go-review.googlesource.com/24481
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-30 00:32:31 +00:00
Nigel Tao
97680175a5 font: add a []byte flavor of string methods.
Change-Id: I2506067ba6ac12c275b65c3a52cb38579d4b9dca
Reviewed-on: https://go-review.googlesource.com/23464
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-27 00:37:06 +00:00
Nigel Tao
51ddfee6f3 colornames: export variables such as Darkred.
Change-Id: I1507d510ffa0ee3c899af652e0d1ab9d42a650d3
Reviewed-on: https://go-review.googlesource.com/23463
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-27 00:36:51 +00:00
Nigel Tao
f551d3a6b7 font/plan9font: derive the example's ascent from the metrics.
The Face.Metrics method is relatively new.

Also pick up the unicode.7x13.font fix from the upstream plan9port:
https://plan9port-review.googlesource.com/#/c/1490/

Change-Id: Ia6e0feec4ea3c9a35e19d38aa634ca9eb6b2ffa0
Reviewed-on: https://go-review.googlesource.com/21699
Reviewed-by: Rob Pike <r@golang.org>
2016-04-23 08:08:30 +00:00
Nigel Tao
14f8673644 font: add a MeasureString function, not just a method.
It can be useful to measure some text without having to set up a Drawer.

Change-Id: I18b7b1fecc32ca69b7644d598ed21462e7c41edd
Reviewed-on: https://go-review.googlesource.com/21785
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-04-12 11:16:26 +00:00
Nigel Tao
4cff43048f example/font: use an "example" build tag instead of "ignore".
The golang-dev discussion is at
https://groups.google.com/d/topic/golang-dev/qKpxZiNABcY/discussion

Change-Id: I55d626fd9b4c5585d11c585a8553fb5184d0ace7
Reviewed-on: https://go-review.googlesource.com/21788
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-04-12 11:14:18 +00:00
Nigel Tao
c4e9f1b429 math/fixed: have Floor, Round and Ceil return int, not Int26_6.
Change-Id: I1714bfbaf355771fb5d01508ac1dfe11c3db927a
Reviewed-on: https://go-review.googlesource.com/21787
Reviewed-by: Rob Pike <r@golang.org>
2016-04-10 05:23:37 +00:00
Nigel Tao
0991244d9d math/fixed: add Floor, Round and Ceil methods.
Change-Id: I7ed8c79a9098f45b38db947b5d99d021358e4e96
Reviewed-on: https://go-review.googlesource.com/21700
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-04-10 01:36:18 +00:00
Nigel Tao
22f1b5f81b font/plan9font: optimize the conversion to image.Alpha.
Also remove the dependency on the image/draw package. That package will
give the right answer for arbitrary source images, including those of
type plan9Image, but doing the conversion directly avoids bouncing uint8
or color.Alpha values through the general-purpose draw.Image,
image.Image and color.Color interfaces.

It is possible to optimize this even further, but this will do for now.

benchmark                   old ns/op     new ns/op     delta
BenchmarkParseSubfont-8     2298492       492443        -78.58%

Change-Id: Iea9436bffa097a1ba0052dbabf21516bce8b61e0
Reviewed-on: https://go-review.googlesource.com/21693
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-04-10 01:11:56 +00:00
Ethan Burns
7a320489ae plan9font: use image.Alpha for subface images.
image.Alpha is fast-pathed in draw.Draw, plan9Image is not.

Change-Id: I5ed8fc4d310bb5c6ec2cffdd0ba4295dae2274cf
Reviewed-on: https://go-review.googlesource.com/21453
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-04-07 03:46:29 +00:00
Nigel Tao
8b5ac8f8e5 image/font: make a zero Weight mean a normal weight.
Change-Id: I2000bdf1c49174b9eaefe1c680138392e3434ace
Reviewed-on: https://go-review.googlesource.com/21440
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-04-02 04:27:04 +00:00
Nigel Tao
0ebebfd658 webp: fix tests for webp/nycbcra deprecation.
The previous commit (00fe24ef "webp/nycbcra: deprecate package") was
incomplete.

Change-Id: I6af5e1633b9c291e72b02877b308eae6e5624ef5
Reviewed-on: https://go-review.googlesource.com/21441
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-04-02 01:02:22 +00:00
Nigel Tao
00fe24ef7b webp/nycbcra: deprecate package.
The standard image and image/color packages have NYCbCrA support, as of Go 1.6.

Change-Id: I3ed2a502b3b9fe720968ac21901115e20a11456a
Reviewed-on: https://go-review.googlesource.com/21066
Reviewed-by: Rob Pike <r@golang.org>
2016-03-27 23:18:01 +00:00
Nigel Tao
f1e9747265 font: add Metrics.Descent.
Change-Id: Id38e7e54264e0e77a28afd8e10cf574610b47336
Reviewed-on: https://go-review.googlesource.com/21019
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-23 23:23:04 +00:00
Ethan Burns
7b1c29e1d6 font: add Face.Metrics.
Fixes golang/go#14885

Change-Id: I3aa2d323c97c76cc78d981d4bf6ea9e95c9bf9d2
Reviewed-on: https://go-review.googlesource.com/21035
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-03-23 23:05:57 +00:00
Nigel Tao
7c492694a6 cmd/webp-manual-test: blacklist some versions of the dwebp binary.
In particular, the 0.4.0 version of /usr/bin/dwebp that comes with
Ubuntu 14.04 LTS "Trusty", is known to be bad.

As per https://chromium.googlesource.com/webm/libwebp/+/master/NEWS
(grep for 239), versions 0.4.1 and 0.4.2 are also bad.

The alpha_color_cache.webp test file that triggers the discrepancy
between the (correct) Go implementation and the (buggy) libwebp C
implementation was added on 2015-01-23 in
f64fb2da01
in response to https://bugs.chromium.org/p/webp/issues/detail?id=239

Change-Id: Ifee19be0af634b9bf36ff0e16957648e05be840a
Reviewed-on: https://go-review.googlesource.com/18186
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-07 22:46:02 +00:00
Nigel Tao
baddd3465a font/basicfont: new package for a basic font face.
The key feature is that its data is entirely self-contained and does not
require loading from separate files.

Change-Id: I4ef72b52cde93597be89dcfd55659f418c6cab23
Reviewed-on: https://go-review.googlesource.com/14486
Reviewed-by: Rob Pike <r@golang.org>
2015-09-16 11:25:57 +00:00
Nigel Tao
2dc9880a10 colornames: fix copyright year.
These files were added in 2015:
https://go-review.googlesource.com/#/c/13181/

Presumably they were copy/pasted from something written in 2011.

Change-Id: I3defb4e02d03beb835e8a16c89bcae44c292e914
Reviewed-on: https://go-review.googlesource.com/14487
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-09-11 03:52:25 +00:00
Nigel Tao
b3d8467d91 font: fix up some old x/exp/shiny references.
Also add canonical import paths for the newly merged packages.

Change-Id: I96fe3a964ba08e718fc9163c980ef7ea9da551fe
Reviewed-on: https://go-review.googlesource.com/14148
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-09-01 05:21:00 +00:00
Nigel Tao
00f88f596f Merge x/exp/shiny/font to x/image/font. 2015-09-01 14:51:18 +10:00
Nigel Tao
b53870fbcf shiny/font/plan9font: add an example test.
The testdata/fixed font files come from the Plan 9 Port, and were all
marked as public domain. The total size of the new testdata is 112K.

Change-Id: I8cf5de4e5abd1aec7e6550d330271f2acdc12402
Reviewed-on: https://go-review.googlesource.com/13888
Reviewed-by: Rob Pike <r@golang.org>
2015-09-01 04:36:16 +00:00
Nigel Tao
5ae59125bf shiny/font: have Face.Glyph return an advance width, not a new dot.
This is consistent with Face.GlyphBounds and Face.GlyphAdvance.

Change-Id: I9da6b4f2fdb8f093fc9567c717e8fbbecc624e30
Reviewed-on: https://go-review.googlesource.com/14090
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-08-31 01:31:05 +00:00
Nigel Tao
627898392a shiny/font: add per-glyph metrics.
Change-Id: Ie5c7e29b4eb7bd87b8e99de941f2f94b042e268f
Reviewed-on: https://go-review.googlesource.com/13827
Reviewed-by: Rob Pike <r@golang.org>
2015-08-24 05:53:06 +00:00
Nigel Tao
8ab1ac6834 math/fixed: add rectangle types and the R function.
Change-Id: Ibb3785bcd57f13c7b6f1dc37526f65e44b4ac695
Reviewed-on: https://go-review.googlesource.com/13823
Reviewed-by: Rob Pike <r@golang.org>
2015-08-24 01:31:27 +00:00
Nigel Tao
ab08d42a8a shiny/font: add Hinting, Stretch, Style and Weight option types.
These will be used by other vector font packages, such as the truetype
package, to select specific faces.

Change-Id: I3db8c97335089c2076811e8f85d9a8868fc900bd
Reviewed-on: https://go-review.googlesource.com/13714
Reviewed-by: Rob Pike <r@golang.org>
2015-08-20 02:16:59 +00:00
Nigel Tao
e87ffe258c shiny/font/plan9font: implement ParseFont.
Also delete font.MultiFace. We can resurrect a font.MultiFace type if we
need it in the future, but for now, it's simpler if it lives in the
plan9font package.

Change-Id: I1493b47696c323424e7d91cb7fac15505bfdd023
Reviewed-on: https://go-review.googlesource.com/13520
Reviewed-by: Rob Pike <r@golang.org>
2015-08-19 04:10:22 +00:00
Nigel Tao
d9c0088098 math/fixed: add I and P helper functions.
The P function is especially common in e.g. Freetype code that works
with both the integer-pixel (X,Y) coordinates used by the stdlib image
package and sub-pixel (X,Y) coordinates used by its raster package.

Change-Id: I68be8ca71ceb24f40277ecc39a0896323f6671f5
Reviewed-on: https://go-review.googlesource.com/13652
Reviewed-by: Rob Pike <r@golang.org>
2015-08-17 07:17:06 +00:00
Hariharan Srinath
b137518d47 colornames: new package for named colors
This package provides named colors as defined in the SVG 1.1 spec.
Named colors are parsed from the SVG 1.1 spec web page at
http://www.w3.org/TR/SVG/types.html and written using go generate

fixes golang/go#11734

Change-Id: Ia75a166b3714a36a07be64c7d331231b5b2d0cf2
Reviewed-on: https://go-review.googlesource.com/13181
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-08-16 00:08:16 +00:00
Nigel Tao
b96af5338f math/fixed: add Point methods (Add, Sub, Mul, Div).
These mirror the image.Point methods in the standard library.

Change-Id: I7309af308a8182e325af20b47341f72703cbc95a
Reviewed-on: https://go-review.googlesource.com/13603
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-13 13:30:46 +00:00
Nigel Tao
eecb4e626f shiny/font: new package for drawing text on an image.
Package font defines an interface for font faces.

Other packages provide font face implementations. For example, a
truetype package (not part of this CL) would provide one based on .ttf
font files.

This CL also introduces the golang.org/x/exp/shiny/font/plan9font
package, a concrete implementation of the font.Face interface for the
Plan 9 bitmap font format.

Change-Id: Iead8914caaa58c7562b18a86b45002ae47486903
Reviewed-on: https://go-review.googlesource.com/13463
Reviewed-by: Rob Pike <r@golang.org>
2015-08-11 05:46:15 +00:00
Nigel Tao
3029cff51e math/fixed: add point types.
Change-Id: Ie9ae62eab3c484034ee8207a2b2e573ec6f1464e
Reviewed-on: https://go-review.googlesource.com/13294
Reviewed-by: Rob Pike <r@golang.org>
2015-08-07 00:23:53 +00:00
Nigel Tao
8e3389fa81 draw: have Scale and Transform recognize straight copies.
This is only for the NearestNeighbor and ApproxBiLinear Interpolators. A
Kernel interpolator will add blur even when the dst and src rectangles
are the same size.

We do not bother recognizing Transforms that are Scales. The performance
difference is minimal, as you still need to do a per-dst-pixel inverse
mapping either way.

benchmark                           old ns/op     new ns/op     delta
BenchmarkSimpleScaleCopy-8          4866297       29586         -99.39%
BenchmarkSimpleTransformCopy-8      4875991       29531         -99.39%
BenchmarkSimpleTransformScale-8     1208147       1223206       +1.25%

Change-Id: If649ad27a4e81bcbb24b18315745c02c9186a5b7
Reviewed-on: https://go-review.googlesource.com/13004
Reviewed-by: Rob Pike <r@golang.org>
2015-08-02 10:47:07 +00:00
Nigel Tao
5ec5e003b2 math/fixed: new package.
Fixes golang/go#11906

Change-Id: I2b43311ff145e8453cd255f085c82add6da7de5b
Reviewed-on: https://go-review.googlesource.com/12863
Reviewed-by: Rob Pike <r@golang.org>
2015-07-30 06:07:28 +00:00
Nigel Tao
5f5d3e0618 draw: skip TestFastPaths for Go 1.4.
Fixes golang/go#11921

Change-Id: Iafca8b21523d486ce9b2be494b8fb93216573968
Reviewed-on: https://go-review.googlesource.com/12861
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-07-30 05:48:34 +00:00
Russ Cox
c6de6b60d2 vp8: split expression to placate 386 compiler
Fixes golang/go#11917.

Change-Id: I2eff23bd98be7531d9a115714ca50e45d3064584
Reviewed-on: https://go-review.googlesource.com/12856
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-29 22:52:57 +00:00
Nigel Tao
5c9906b535 image/draw: have Transform take a f64.Aff3 instead of a *f64.Aff3.
It's more args (in terms of bytes), but fewer allocations (Transformer
is an interface). Either way, it's not really that big of a deal, but
the value instead of the pointer seems conceptually more correct.

Change-Id: Ibea76da17cbda0d9633110fd56044b4e2c690e81
Reviewed-on: https://go-review.googlesource.com/12669
Reviewed-by: Rob Pike <r@golang.org>
2015-07-29 01:18:37 +00:00
Nigel Tao
8ca9b58be9 shiny/screen: new package.
Change-Id: Ib0a6296b9c117d64fc76fc6abe59ccb7da3bbae1
Reviewed-on: https://go-review.googlesource.com/12568
Reviewed-by: Rob Pike <r@golang.org>
2015-07-24 06:42:10 +00:00
Nigel Tao
6b7a488d1e draw: tweak the YCbCr to RGBA conversion formula.
This is the golang.org/x equivalent of the golang.org/cl/12220 change to
the standard library.

Change-Id: I220d1398902dec374472ef5b08db8501607cc971
Reviewed-on: https://go-review.googlesource.com/12222
Reviewed-by: Rob Pike <r@golang.org>
2015-07-15 05:30:06 +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
Nigel Tao
d8e202c6ce vp8: limit all other partitions to 1<<24 bytes in size, not just N-1 of
them.

Also check for int32 overflow in the webp package.

Fixes #10790.

Change-Id: Id1162fad8a467a72a5379c7f4432d64ef25bc37a
Reviewed-on: https://go-review.googlesource.com/10072
Reviewed-by: Rob Pike <r@golang.org>
2015-05-15 01:02:58 +00:00
Aamir Khan
c5f9292598 vp8l: don't ignore I/O errors when reading LZ77 parameters.
Fixes golang/go#10383

Change-Id: I3e5e357a40a45189c31f0b4db9422dedc351c910
Reviewed-on: https://go-review.googlesource.com/9912
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-05-11 04:53:56 +00:00
Aamir Khan
25eff15cb8 webp: fix panic in case of invalid chunkID
At the time of decoding webp file, if chunkID is not one of
{'ALPH', 'VP8', 'VP8L', 'VP8X'} return errInvalidFormat

Fixes golang/go#10384

Change-Id: I167909b5ddef174d161f806297a08fac6aabcf19
Reviewed-on: https://go-review.googlesource.com/9839
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-05-11 04:53:49 +00:00