4 Commits

Author SHA1 Message Date
Ishotihadus 9686bdca95 version 3.9.3 2018-01-15 23:58:53 +09:00
Ishotihadus ad9ee60a5b Edit readme 2018-01-15 23:58:43 +09:00
Ishotihadus 68252ce102 Fix bugs on decoding ETC1 and ETC2 2018-01-15 23:56:56 +09:00
Ishotihadus afd776e836 Fix ASTC partition bug 2018-01-15 23:22:50 +09:00
4 changed files with 30 additions and 32 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ obj.key
You can get png file directly from Texture2D asset. Output object's class is `ChunkyPNG::Image`.
Some basic texture formats (1--5, 7, 9, 13--20, 22, 62, and 63), ETC_RGB4 (34), ETC2 (45, 47), and ASTC (48--59) are available.
Some basic texture formats (15, 7, 9, 1320, 22, 62, and 63), ETC_RGB4 (34), ETC2 (45, 47), and ASTC (4859) are available.
```ruby
require 'mikunyan/decoders'
+13 -17
View File
@@ -345,24 +345,20 @@ module Mikunyan
sh.reverse! if seed & 1 == 0
seeds.map!.with_index{|e, i| e >> sh[i % 2]}
@partition = Array.new(@bw * @bh)
for y in 0...@bh
for x in 0...@bw
idx = x + y * @bw
if small_block
x <<= 1
y <<= 1
end
a = (seeds[0] * x + seeds[1] * y + (rnum >> 14)) & 0x3f
b = (seeds[2] * x + seeds[3] * y + (rnum >> 10)) & 0x3f
c = @part_num < 3 ? 0 : (seeds[4] * x + seeds[5] * y + (rnum >> 6)) & 0x3f
d = @part_num < 4 ? 0 : (seeds[6] * x + seeds[7] * y + (rnum >> 2)) & 0x3f
@partition[idx] = 3 - [d, c, b, a].each_with_index.max[1]
@partition = (0...@bw * @bh).map do |i|
x = i % @bw
y = i / @bw
if small_block
x <<= 1
y <<= 1
end
a = (seeds[0] * x + seeds[1] * y + (rnum >> 14)) & 0x3f
b = (seeds[2] * x + seeds[3] * y + (rnum >> 10)) & 0x3f
c = @part_num < 3 ? 0 : (seeds[4] * x + seeds[5] * y + (rnum >> 6)) & 0x3f
d = @part_num < 4 ? 0 : (seeds[6] * x + seeds[7] * y + (rnum >> 2)) & 0x3f
3 - [d, c, b, a].each_with_index.max[1]
end
end
end
+15 -13
View File
@@ -359,14 +359,14 @@ module Mikunyan
def self.decode_etc1(width, height, bin)
bw = (width + 3) / 4
bh = (height + 3) / 4
ret = ChunkyPNG::Image.new(bw * 4, bh * 4)
ret = ChunkyPNG::Image.new(bh * 4, bw * 4)
bh.times do |by|
bw.times do |bx|
block = decode_etc1_block(BinUtils.get_sint64_be(bin, (bx + by * bw) * 8))
ret.replace!(ChunkyPNG::Image.from_rgb_stream(4, 4, block), bx * 4, by * 4)
ret.replace!(ChunkyPNG::Image.from_rgb_stream(4, 4, block), by * 4, bx * 4)
end
end
ret.crop(0, 0, width, height)
ret.crop(0, 0, height, width).rotate_left
end
# Decode image from ETC2 compressed binary
@@ -377,14 +377,14 @@ module Mikunyan
def self.decode_etc2rgb(width, height, bin)
bw = (width + 3) / 4
bh = (height + 3) / 4
ret = ChunkyPNG::Image.new(bw * 4, bh * 4)
ret = ChunkyPNG::Image.new(bh * 4, bw * 4)
bh.times do |by|
bw.times do |bx|
block = decode_etc2_block(BinUtils.get_sint64_be(bin, (bx + by * bw) * 8))
ret.replace!(ChunkyPNG::Image.from_rgb_stream(4, 4, block), bx * 4, by * 4)
ret.replace!(ChunkyPNG::Image.from_rgb_stream(4, 4, block.join), by * 4, bx * 4)
end
end
ret.crop(0, 0, width, height)
ret.crop(0, 0, height, width).rotate_left
end
# Decode image from ETC2 Alpha8 compressed binary
@@ -395,17 +395,17 @@ module Mikunyan
def self.decode_etc2rgba8(width, height, bin)
bw = (width + 3) / 4
bh = (height + 3) / 4
mem = Fiddle::Pointer.malloc(bw * bh * 64)
ret = ChunkyPNG::Image.new(bh * 4, bw * 4)
bh.times do |by|
bw.times do |bx|
alpha = decode_etc2alpha_block(BinUtils.get_int64_be(bin, (bx + by * bw) * 16))
block = decode_etc2_block(BinUtils.get_int64_be(bin, (bx + by * bw) * 16 + 8))
16.times do |i|
mem[((i / 4 + bx * 4) + (i % 4 + by * 4) * bw * 4) * 4, 4] = block[i] + alpha[i]
end
mem = String.new(capacity: 64)
16.times{|i| mem << block[i] + alpha[i]}
ret.replace!(ChunkyPNG::Image.from_rgba_stream(4, 4, mem), by * 4, bx * 4)
end
end
ChunkyPNG::Image.from_rgba_stream(bw * 4, bh * 4, mem.to_str).crop(0, 0, width, height)
ret.crop(0, 0, height, width).rotate_left
end
# Decode image from ASTC compressed binary
@@ -498,10 +498,12 @@ module Mikunyan
colors[1] = colors[1] | (colors[1] >> 5 & 0x70707)
end
(0...16).map do |i|
mem = Fiddle::Pointer.malloc(48)
16.times do |i|
modifier = Etc1ModifierTable[codes[subblocks[i]]][bin[i]]
etc1colormod(colors[subblocks[i]], bin[i + 16] == 0 ? modifier : -modifier)
mem[i * 3, 3] = etc1colormod(colors[subblocks[i]], bin[i + 16] == 0 ? modifier : -modifier)
end
mem.to_str
end
def self.etc1colormod(color, modifier)
+1 -1
View File
@@ -1,4 +1,4 @@
module Mikunyan
# version string
VERSION = "3.9.2"
VERSION = "3.9.3"
end