chunky_png 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/chunky_png.gemspec +2 -2
- data/lib/chunky_png.rb +1 -1
- data/lib/chunky_png/canvas.rb +1 -1
- data/lib/chunky_png/canvas/png_decoding.rb +3 -3
- data/lib/chunky_png/canvas/png_encoding.rb +7 -7
- data/lib/chunky_png/chunk.rb +1 -1
- data/lib/chunky_png/color.rb +71 -71
- data/lib/chunky_png/palette.rb +5 -5
- metadata +20 -9
data/chunky_png.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
|
4
4
|
# Do not change the version and date fields by hand. This will be done
|
5
5
|
# automatically by the gem release script.
|
6
|
-
s.version = "0.7.
|
7
|
-
s.date = "2010-03-
|
6
|
+
s.version = "0.7.1"
|
7
|
+
s.date = "2010-03-23"
|
8
8
|
|
9
9
|
s.summary = "Pure ruby library for read/write, chunk-level access to PNG files"
|
10
10
|
s.description = <<-EOT
|
data/lib/chunky_png.rb
CHANGED
@@ -27,7 +27,7 @@ module ChunkyPNG
|
|
27
27
|
|
28
28
|
# The current version of ChunkyPNG. This value will be updated automatically
|
29
29
|
# by them gem:release rake task.
|
30
|
-
VERSION = "0.7.
|
30
|
+
VERSION = "0.7.1"
|
31
31
|
|
32
32
|
###################################################
|
33
33
|
# PNG international standard defined constants
|
data/lib/chunky_png/canvas.rb
CHANGED
@@ -179,12 +179,12 @@ module ChunkyPNG
|
|
179
179
|
# scanline, combining them using a color mode dependent color decoder.
|
180
180
|
#
|
181
181
|
# @param [Integer] filter The filter used to encode the bytes.
|
182
|
-
# @param [Array<
|
183
|
-
# @param [Array<
|
182
|
+
# @param [Array<Integer>] bytes The filtered bytes to decode.
|
183
|
+
# @param [Array<Integer>] previous_bytes The decoded bytes of the
|
184
184
|
# previous scanline.
|
185
185
|
# @param [Integer] pixelsize The amount of bytes used for every pixel.
|
186
186
|
# This depends on the used color mode and color depth.
|
187
|
-
# @return [Array<
|
187
|
+
# @return [Array<Integer>] The array of original bytes for the scanline,
|
188
188
|
# before they were encoded.
|
189
189
|
def decode_png_scanline(filter, bytes, previous_bytes, pixelsize = 3)
|
190
190
|
case filter
|
@@ -202,7 +202,7 @@ module ChunkyPNG
|
|
202
202
|
|
203
203
|
# Passes to this canvas of pixel values line by line.
|
204
204
|
# @yield [line] Yields the scanlines of this image one by one.
|
205
|
-
# @yieldparam [Array<
|
205
|
+
# @yieldparam [Array<Integer>] line An line of fixnums representing pixels
|
206
206
|
def each_scanline(&block)
|
207
207
|
for line_no in 0...height do
|
208
208
|
scanline = pixels[width * line_no, width]
|
@@ -212,10 +212,10 @@ module ChunkyPNG
|
|
212
212
|
|
213
213
|
# Encodes the bytes of a scanline with a given filter.
|
214
214
|
# @param [Integer] filter The filter method to use.
|
215
|
-
# @param [Array<
|
216
|
-
# @param [Array<
|
215
|
+
# @param [Array<Integer>] bytes The scanline bytes to encode.
|
216
|
+
# @param [Array<Integer>] previous_bytes The original bytes of the previous scanline.
|
217
217
|
# @param [Integer] pixelsize The number of bytes per pixel.
|
218
|
-
# @return [Array<
|
218
|
+
# @return [Array<Integer>] The filtered array of bytes.
|
219
219
|
def encode_png_scanline(filter, bytes, previous_bytes = nil, pixelsize = 3)
|
220
220
|
case filter
|
221
221
|
when ChunkyPNG::FILTER_NONE then encode_png_scanline_none( bytes, previous_bytes, pixelsize)
|
@@ -228,10 +228,10 @@ module ChunkyPNG
|
|
228
228
|
end
|
229
229
|
|
230
230
|
# Encodes the bytes of a scanline without filtering.
|
231
|
-
# @param [Array<
|
232
|
-
# @param [Array<
|
231
|
+
# @param [Array<Integer>] bytes The scanline bytes to encode.
|
232
|
+
# @param [Array<Integer>] previous_bytes The original bytes of the previous scanline.
|
233
233
|
# @param [Integer] pixelsize The number of bytes per pixel.
|
234
|
-
# @return [Array<
|
234
|
+
# @return [Array<Integer>] The filtered array of bytes.
|
235
235
|
def encode_png_scanline_none(original_bytes, previous_bytes = nil, pixelsize = 3)
|
236
236
|
[ChunkyPNG::FILTER_NONE] + original_bytes
|
237
237
|
end
|
data/lib/chunky_png/chunk.rb
CHANGED
@@ -31,7 +31,7 @@ module ChunkyPNG
|
|
31
31
|
# Verifies the CRC of a chunk.
|
32
32
|
# @param [String] type The chunk's type.
|
33
33
|
# @param [String] content The chunk's content.
|
34
|
-
# @param [
|
34
|
+
# @param [Integer] content The chunk's content.
|
35
35
|
# @raise [RuntimeError] An exception is raised if the found CRC value
|
36
36
|
# is not equal to the expected CRC value.
|
37
37
|
def self.verify_crc!(type, content, found_crc)
|
data/lib/chunky_png/color.rb
CHANGED
@@ -2,12 +2,12 @@ module ChunkyPNG
|
|
2
2
|
|
3
3
|
# The Color module defines methods for handling colors. Within the ChunkyPNG
|
4
4
|
# library, the concepts of pixels and colors are both used, and they are
|
5
|
-
# both represented by a
|
5
|
+
# both represented by a Integer.
|
6
6
|
#
|
7
7
|
# Pixels/colors are represented in RGBA componetns. Each of the four
|
8
8
|
# components is stored with a depth of 8 bits (maximum value = 255 =
|
9
9
|
# {ChunkyPNG::Color::MAX}). Together, these components are stored in a 4-byte
|
10
|
-
#
|
10
|
+
# Integer.
|
11
11
|
#
|
12
12
|
# A color will always be represented using these 4 components in memory.
|
13
13
|
# When the image is encoded, a more suitable representation can be used
|
@@ -24,13 +24,13 @@ module ChunkyPNG
|
|
24
24
|
####################################################################
|
25
25
|
|
26
26
|
# Creates a new color using an r, g, b triple and an alpha value.
|
27
|
-
# @return [
|
27
|
+
# @return [Integer] The newly constructed color value.
|
28
28
|
def rgba(r, g, b, a)
|
29
29
|
r << 24 | g << 16 | b << 8 | a
|
30
30
|
end
|
31
31
|
|
32
32
|
# Creates a new color using an r, g, b triple.
|
33
|
-
# @return [
|
33
|
+
# @return [Integer] The newly constructed color value.
|
34
34
|
def rgb(r, g, b)
|
35
35
|
r << 24 | g << 16 | b << 8 | 0xff
|
36
36
|
end
|
@@ -42,7 +42,7 @@ module ChunkyPNG
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Creates a new color using a grayscale teint and alpha value.
|
45
|
-
# @return [
|
45
|
+
# @return [Integer] The newly constructed color value.
|
46
46
|
def grayscale_alpha(teint, a)
|
47
47
|
teint << 24 | teint << 16 | teint << 8 | a
|
48
48
|
end
|
@@ -55,8 +55,8 @@ module ChunkyPNG
|
|
55
55
|
#
|
56
56
|
# @param [String] stream The string to load the color from. It should be
|
57
57
|
# at least 3 + pos bytes long.
|
58
|
-
# @param [
|
59
|
-
# @return [
|
58
|
+
# @param [Integer] pos The position in the string to load the triple from.
|
59
|
+
# @return [Integer] The newly constructed color value.
|
60
60
|
def from_rgb_stream(stream, pos = 0)
|
61
61
|
rgb(*stream.unpack("@#{pos}C3"))
|
62
62
|
end
|
@@ -65,8 +65,8 @@ module ChunkyPNG
|
|
65
65
|
#
|
66
66
|
# @param [String] stream The string to load the color from. It should be
|
67
67
|
# at least 4 + pos bytes long.
|
68
|
-
# @param [
|
69
|
-
# @return [
|
68
|
+
# @param [Integer] pos The position in the string to load the triple from.
|
69
|
+
# @return [Integer] The newly constructed color value.
|
70
70
|
def from_rgba_stream(stream, pos = 0)
|
71
71
|
rgba(*stream.unpack("@#{pos}C4"))
|
72
72
|
end
|
@@ -76,7 +76,7 @@ module ChunkyPNG
|
|
76
76
|
# It supports colors with (#rrggbbaa) or without (#rrggbb) alpha channel.
|
77
77
|
# Color strings may include the prefix "0x" or "#".
|
78
78
|
#
|
79
|
-
# @param [String] str The color in hex notation. @return [
|
79
|
+
# @param [String] str The color in hex notation. @return [Integer] The
|
80
80
|
# converted color value.
|
81
81
|
def from_hex(str)
|
82
82
|
case str
|
@@ -92,54 +92,54 @@ module ChunkyPNG
|
|
92
92
|
|
93
93
|
# Returns the red-component from the color value.
|
94
94
|
#
|
95
|
-
# @param [
|
96
|
-
# @return [
|
95
|
+
# @param [Integer] value The color value.
|
96
|
+
# @return [Integer] A value between 0 and MAX.
|
97
97
|
def r(value)
|
98
98
|
(value & 0xff000000) >> 24
|
99
99
|
end
|
100
100
|
|
101
101
|
# Returns the green-component from the color value.
|
102
102
|
#
|
103
|
-
# @param [
|
104
|
-
# @return [
|
103
|
+
# @param [Integer] value The color value.
|
104
|
+
# @return [Integer] A value between 0 and MAX.
|
105
105
|
def g(value)
|
106
106
|
(value & 0x00ff0000) >> 16
|
107
107
|
end
|
108
108
|
|
109
109
|
# Returns the blue-component from the color value.
|
110
110
|
#
|
111
|
-
# @param [
|
112
|
-
# @return [
|
111
|
+
# @param [Integer] value The color value.
|
112
|
+
# @return [Integer] A value between 0 and MAX.
|
113
113
|
def b(value)
|
114
114
|
(value & 0x0000ff00) >> 8
|
115
115
|
end
|
116
116
|
|
117
117
|
# Returns the alpha channel value for the color value.
|
118
118
|
#
|
119
|
-
# @param [
|
120
|
-
# @return [
|
119
|
+
# @param [Integer] value The color value.
|
120
|
+
# @return [Integer] A value between 0 and MAX.
|
121
121
|
def a(value)
|
122
122
|
value & 0x000000ff
|
123
123
|
end
|
124
124
|
|
125
125
|
# Returns true if this color is fully opaque.
|
126
126
|
#
|
127
|
-
# @param [
|
127
|
+
# @param [Integer] value The color to test.
|
128
128
|
# @return [true, false] True if the alpha channel equals MAX.
|
129
129
|
def opaque?(value)
|
130
130
|
a(value) == 0x000000ff
|
131
131
|
end
|
132
132
|
|
133
133
|
# Returns the opaque value of this color by removing the alpha channel.
|
134
|
-
# @param [
|
135
|
-
# @return [
|
134
|
+
# @param [Integer] value The color to transform.
|
135
|
+
# @return [Integer] The opauq color
|
136
136
|
def opaque!(value)
|
137
137
|
value | 0x000000ff
|
138
138
|
end
|
139
139
|
|
140
140
|
# Returns true if this color is fully transparent.
|
141
141
|
#
|
142
|
-
# @param [
|
142
|
+
# @param [Integer] value The color to test.
|
143
143
|
# @return [true, false] True if the r, g and b component are equal.
|
144
144
|
def grayscale?(value)
|
145
145
|
r(value) == b(value) && b(value) == g(value)
|
@@ -147,7 +147,7 @@ module ChunkyPNG
|
|
147
147
|
|
148
148
|
# Returns true if this color is fully transparent.
|
149
149
|
#
|
150
|
-
# @param [
|
150
|
+
# @param [Integer] value The color to test.
|
151
151
|
# @return [true, false] True if the alpha channel equals 0.
|
152
152
|
def fully_transparent?(value)
|
153
153
|
a(value) == 0x00000000
|
@@ -163,9 +163,9 @@ module ChunkyPNG
|
|
163
163
|
#
|
164
164
|
# This is a quicker implementation of ((a * b) / 255.0).round.
|
165
165
|
#
|
166
|
-
# @param [
|
167
|
-
# @param [
|
168
|
-
# @return [
|
166
|
+
# @param [Integer] a The first fraction.
|
167
|
+
# @param [Integer] b The second fraction.
|
168
|
+
# @return [Integer] The result of the multiplication.
|
169
169
|
def int8_mult(a, b)
|
170
170
|
t = a * b + 0x80
|
171
171
|
((t >> 8) + t) >> 8
|
@@ -176,9 +176,9 @@ module ChunkyPNG
|
|
176
176
|
# This version is faster than the version based on floating point math, so this
|
177
177
|
# compositing function is used by default.
|
178
178
|
#
|
179
|
-
# @param [
|
180
|
-
# @param [
|
181
|
-
# @return [
|
179
|
+
# @param [Integer] fg The foreground color.
|
180
|
+
# @param [Integer] bg The foreground color.
|
181
|
+
# @return [Integer] The composited color.
|
182
182
|
# @see ChunkyPNG::Color#compose_precise
|
183
183
|
def compose_quick(fg, bg)
|
184
184
|
return fg if opaque?(fg)
|
@@ -198,9 +198,9 @@ module ChunkyPNG
|
|
198
198
|
# when the result is converted back to an integer. Because it is slower than
|
199
199
|
# the version based on integer math, that version is preferred.
|
200
200
|
#
|
201
|
-
# @param [
|
202
|
-
# @param [
|
203
|
-
# @return [
|
201
|
+
# @param [Integer] fg The foreground color.
|
202
|
+
# @param [Integer] bg The foreground color.
|
203
|
+
# @return [Integer] The composited color.
|
204
204
|
# @see ChunkyPNG::Color#compose_quick
|
205
205
|
def compose_precise(fg, bg)
|
206
206
|
return fg if opaque?(fg)
|
@@ -222,17 +222,17 @@ module ChunkyPNG
|
|
222
222
|
# Blends the foreground and background color by taking the average of
|
223
223
|
# the components.
|
224
224
|
#
|
225
|
-
# @param [
|
226
|
-
# @param [
|
227
|
-
# @return [
|
225
|
+
# @param [Integer] fg The foreground color.
|
226
|
+
# @param [Integer] bg The foreground color.
|
227
|
+
# @return [Integer] The blended color.
|
228
228
|
def blend(fg, bg)
|
229
229
|
(fg + bg) >> 1
|
230
230
|
end
|
231
231
|
|
232
232
|
# Lowers the intensity of a color, by lowering its alpha by a given factor.
|
233
|
-
# @param [
|
234
|
-
# @param [
|
235
|
-
# @return [
|
233
|
+
# @param [Integer] color The color to adjust.
|
234
|
+
# @param [Integer] factor Fade factor as an integer between 0 and 255.
|
235
|
+
# @return [Integer] The faded color.
|
236
236
|
def fade(color, factor)
|
237
237
|
new_alpha = int8_mult(a(color), factor)
|
238
238
|
(color & 0xffffff00) | new_alpha
|
@@ -246,11 +246,11 @@ module ChunkyPNG
|
|
246
246
|
# If the color cannot be decomposed, this method will return the fully
|
247
247
|
# transparentvariant of the mask color.
|
248
248
|
#
|
249
|
-
# @param [
|
250
|
-
# @param [
|
251
|
-
# @param [
|
252
|
-
# @param [
|
253
|
-
# @return [
|
249
|
+
# @param [Integer] color The color that was the result of compositing.
|
250
|
+
# @param [Integer] mask The opaque variant of the color that was being composed
|
251
|
+
# @param [Integer] bg The background color on which the color was composed.
|
252
|
+
# @param [Integer] tolerance The decomposition tolerance level, a value between 0 and 255.
|
253
|
+
# @return [Integer] The decomposed color,a variant of the masked color with the
|
254
254
|
# alpha channel set to an appropriate value.
|
255
255
|
def decompose_color(color, mask, bg, tolerance = 1)
|
256
256
|
if alpha_decomposable?(color, mask, bg, tolerance)
|
@@ -264,11 +264,11 @@ module ChunkyPNG
|
|
264
264
|
# given the resulting color, the mask color and a background color,
|
265
265
|
# all of which should be opaque.
|
266
266
|
#
|
267
|
-
# @param [
|
268
|
-
# @param [
|
269
|
-
# @param [
|
270
|
-
# @param [
|
271
|
-
# @return [
|
267
|
+
# @param [Integer] color The color that was the result of compositing.
|
268
|
+
# @param [Integer] mask The opauqe variant of the color that was being composed
|
269
|
+
# @param [Integer] bg The background color on which the color was composed.
|
270
|
+
# @param [Integer] tolerance The decomposition tolerance level, a value between 0 and 255.
|
271
|
+
# @return [Integer] The decomposed alpha channel value, between 0 and 255.
|
272
272
|
# @see #decompose_alpha
|
273
273
|
def alpha_decomposable?(color, mask, bg, tolerance = 1)
|
274
274
|
components = decompose_alpha_components(color, mask, bg)
|
@@ -284,10 +284,10 @@ module ChunkyPNG
|
|
284
284
|
# value can successfully decomposed with a given tolerance, otherwise the return
|
285
285
|
# value of this method is undefined.
|
286
286
|
#
|
287
|
-
# @param [
|
288
|
-
# @param [
|
289
|
-
# @param [
|
290
|
-
# @return [
|
287
|
+
# @param [Integer] color The color that was the result of compositing.
|
288
|
+
# @param [Integer] mask The opauqe variant of the color that was being composed
|
289
|
+
# @param [Integer] bg The background color on which the color was composed.
|
290
|
+
# @return [Integer] The best fitting alpha channel, a value between 0 and 255.
|
291
291
|
# @see #alpha_decomposable?
|
292
292
|
def decompose_alpha(color, mask, bg)
|
293
293
|
components = decompose_alpha_components(color, mask, bg)
|
@@ -296,20 +296,20 @@ module ChunkyPNG
|
|
296
296
|
|
297
297
|
# Decomposes an alpha channel for either the r, g or b color channel.
|
298
298
|
# @param [:r, :g, :b] The channel to decompose the alpha channel from.
|
299
|
-
# @param [
|
300
|
-
# @param [
|
301
|
-
# @param [
|
302
|
-
# @param [
|
299
|
+
# @param [Integer] color The color that was the result of compositing.
|
300
|
+
# @param [Integer] mask The opauqe variant of the color that was being composed
|
301
|
+
# @param [Integer] bg The background color on which the color was composed.
|
302
|
+
# @param [Integer] The decomposed alpha value for the channel.
|
303
303
|
def decompose_alpha_component(channel, color, mask, bg)
|
304
304
|
((send(channel, bg) - send(channel, color)).to_f /
|
305
305
|
(send(channel, bg) - send(channel, mask)).to_f * MAX).round
|
306
306
|
end
|
307
307
|
|
308
308
|
# Decomposes the alpha channels for the r, g and b color channel.
|
309
|
-
# @param [
|
310
|
-
# @param [
|
311
|
-
# @param [
|
312
|
-
# @return [Array<
|
309
|
+
# @param [Integer] color The color that was the result of compositing.
|
310
|
+
# @param [Integer] mask The opauqe variant of the color that was being composed
|
311
|
+
# @param [Integer] bg The background color on which the color was composed.
|
312
|
+
# @return [Array<Integer>] The decomposed alpha values for the r, g and b channels.
|
313
313
|
def decompose_alpha_components(color, mask, bg)
|
314
314
|
[
|
315
315
|
decompose_alpha_component(:r, color, mask, bg),
|
@@ -324,7 +324,7 @@ module ChunkyPNG
|
|
324
324
|
|
325
325
|
# Returns a string representing this color using hex notation (i.e. #rrggbbaa).
|
326
326
|
#
|
327
|
-
# @param [
|
327
|
+
# @param [Integer] value The color to convert.
|
328
328
|
# @return [String] The color in hex notation, starting with a pound sign.
|
329
329
|
def to_hex(color, include_alpha = true)
|
330
330
|
include_alpha ? ('#%08x' % color) : ('#%06x' % [color >> 8])
|
@@ -332,8 +332,8 @@ module ChunkyPNG
|
|
332
332
|
|
333
333
|
# Returns an array with the separate RGBA values for this color.
|
334
334
|
#
|
335
|
-
# @param [
|
336
|
-
# @return [Array<
|
335
|
+
# @param [Integer] color The color to convert.
|
336
|
+
# @return [Array<Integer>] An array with 4 Integer elements.
|
337
337
|
def to_truecolor_alpha_bytes(color)
|
338
338
|
[r(color), g(color), b(color), a(color)]
|
339
339
|
end
|
@@ -341,8 +341,8 @@ module ChunkyPNG
|
|
341
341
|
# Returns an array with the separate RGB values for this color.
|
342
342
|
# The alpha channel will be discarded.
|
343
343
|
#
|
344
|
-
# @param [
|
345
|
-
# @return [Array<
|
344
|
+
# @param [Integer] color The color to convert.
|
345
|
+
# @return [Array<Integer>] An array with 3 Integer elements.
|
346
346
|
def to_truecolor_bytes(color)
|
347
347
|
[r(color), g(color), b(color)]
|
348
348
|
end
|
@@ -352,8 +352,8 @@ module ChunkyPNG
|
|
352
352
|
# This method expects the r,g and b value to be equal, and the alpha
|
353
353
|
# channel will be discarded.
|
354
354
|
#
|
355
|
-
# @param [
|
356
|
-
# @return [Array<
|
355
|
+
# @param [Integer] color The grayscale color to convert.
|
356
|
+
# @return [Array<Integer>] An array with 1 Integer element.
|
357
357
|
def to_grayscale_bytes(color)
|
358
358
|
[r(color)] # assumption r == g == b
|
359
359
|
end
|
@@ -363,8 +363,8 @@ module ChunkyPNG
|
|
363
363
|
#
|
364
364
|
# This method expects the r,g and b value to be equal.
|
365
365
|
#
|
366
|
-
# @param [
|
367
|
-
# @return [Array<
|
366
|
+
# @param [Integer] color The grayscale color to convert.
|
367
|
+
# @return [Array<Integer>] An array with 2 Integer elements.
|
368
368
|
def to_grayscale_alpha_bytes(color)
|
369
369
|
[r(color), a(color)] # assumption r == g == b
|
370
370
|
end
|
@@ -387,8 +387,8 @@ module ChunkyPNG
|
|
387
387
|
####################################################################
|
388
388
|
|
389
389
|
# Returns the size in bytes of a pixel when it is stored using a given color mode.
|
390
|
-
# @param [
|
391
|
-
# @return [
|
390
|
+
# @param [Integer] color_mode The color mode in which the pixels are stored.
|
391
|
+
# @return [Integer] The number of bytes used per pixel in a datastream.
|
392
392
|
def bytesize(color_mode)
|
393
393
|
case color_mode
|
394
394
|
when ChunkyPNG::COLOR_INDEXED then 1
|
data/lib/chunky_png/palette.rb
CHANGED
@@ -15,7 +15,7 @@ module ChunkyPNG
|
|
15
15
|
|
16
16
|
# Builds a new palette given a set (Enumerable instance) of colors.
|
17
17
|
#
|
18
|
-
# @param [Enumerbale<
|
18
|
+
# @param [Enumerbale<Integer>] enum The set of colors to include in this palette.
|
19
19
|
# This Enumerbale can contains duplicates.
|
20
20
|
# @param [Array] decoding_map An array of colors in the exact order at which
|
21
21
|
# they appeared in the palette chunk, so that this array can be used for decoding.
|
@@ -64,7 +64,7 @@ module ChunkyPNG
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# Builds a palette instance from a given set of pixels.
|
67
|
-
# @param [Enumerable<
|
67
|
+
# @param [Enumerable<Integer>] pixels An enumeration of pixels to create a palette for
|
68
68
|
# @return [ChunkyPNG::Palette] The palette instance.
|
69
69
|
def self.from_pixels(pixels)
|
70
70
|
self.new(pixels)
|
@@ -118,7 +118,7 @@ module ChunkyPNG
|
|
118
118
|
end
|
119
119
|
|
120
120
|
# Returns a color, given the position in the original palette chunk.
|
121
|
-
# @param [
|
121
|
+
# @param [Integer] index The 0-based position of the color in the palette.
|
122
122
|
# @return [ChunkyPNG::Color] The color that is stored in the palette under the given index
|
123
123
|
# @see ChunkyPNG::Palette#can_decode?
|
124
124
|
def [](index)
|
@@ -127,7 +127,7 @@ module ChunkyPNG
|
|
127
127
|
|
128
128
|
# Returns the position of a color in the palette
|
129
129
|
# @param [ChunkyPNG::Color] color The color for which to look up the index.
|
130
|
-
# @return [
|
130
|
+
# @return [Integer] The 0-based position of the color in the palette.
|
131
131
|
# @see ChunkyPNG::Palette#can_encode?
|
132
132
|
def index(color)
|
133
133
|
@encoding_map[color]
|
@@ -166,7 +166,7 @@ module ChunkyPNG
|
|
166
166
|
end
|
167
167
|
|
168
168
|
# Determines the most suitable colormode for this palette.
|
169
|
-
# @return [
|
169
|
+
# @return [Integer] The colormode which would create the smalles possible
|
170
170
|
# file for images that use this exact palette.
|
171
171
|
def best_colormode
|
172
172
|
if grayscale?
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chunky_png
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 7
|
8
|
+
- 1
|
9
|
+
version: 0.7.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Willem van Bergen
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-23 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
description: " This pure Ruby library can read and write PNG images without depending on an external \n image library, like RMagick. It tries to be memory efficient and reasonably fast.\n \n It supports reading and writing all PNG variants that are defined in the specification, \n with one limitation: only 8-bit color depth is supported. It supports all transparency, \n interlacing and filtering options the PNG specifications allows. It can also read and \n write textual metadata from PNG files. Low-level read/write access to PNG chunks is\n also possible.\n \n This library supports simple drawing on the image canvas and simple operations like alpha composition\n and cropping. Finally, it can import from and export to RMagick for interoperability. \n"
|
26
35
|
email:
|
27
36
|
- willem@railsdoctors.com
|
@@ -110,18 +119,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
119
|
requirements:
|
111
120
|
- - ">="
|
112
121
|
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
113
124
|
version: "0"
|
114
|
-
version:
|
115
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
126
|
requirements:
|
117
127
|
- - ">="
|
118
128
|
- !ruby/object:Gem::Version
|
129
|
+
segments:
|
130
|
+
- 0
|
119
131
|
version: "0"
|
120
|
-
version:
|
121
132
|
requirements: []
|
122
133
|
|
123
134
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.6
|
125
136
|
signing_key:
|
126
137
|
specification_version: 3
|
127
138
|
summary: Pure ruby library for read/write, chunk-level access to PNG files
|