Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9686bdca95 | |||
| ad9ee60a5b | |||
| 68252ce102 | |||
| afd776e836 |
@@ -104,7 +104,7 @@ obj.key
|
|||||||
|
|
||||||
You can get png file directly from Texture2D asset. Output object's class is `ChunkyPNG::Image`.
|
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 (1–5, 7, 9, 13–20, 22, 62, and 63), ETC_RGB4 (34), ETC2 (45, 47), and ASTC (48–59) are available.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require 'mikunyan/decoders'
|
require 'mikunyan/decoders'
|
||||||
|
|||||||
@@ -345,24 +345,20 @@ module Mikunyan
|
|||||||
sh.reverse! if seed & 1 == 0
|
sh.reverse! if seed & 1 == 0
|
||||||
seeds.map!.with_index{|e, i| e >> sh[i % 2]}
|
seeds.map!.with_index{|e, i| e >> sh[i % 2]}
|
||||||
|
|
||||||
@partition = Array.new(@bw * @bh)
|
@partition = (0...@bw * @bh).map do |i|
|
||||||
|
x = i % @bw
|
||||||
for y in 0...@bh
|
y = i / @bw
|
||||||
for x in 0...@bw
|
if small_block
|
||||||
idx = x + y * @bw
|
x <<= 1
|
||||||
|
y <<= 1
|
||||||
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]
|
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -359,14 +359,14 @@ module Mikunyan
|
|||||||
def self.decode_etc1(width, height, bin)
|
def self.decode_etc1(width, height, bin)
|
||||||
bw = (width + 3) / 4
|
bw = (width + 3) / 4
|
||||||
bh = (height + 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|
|
bh.times do |by|
|
||||||
bw.times do |bx|
|
bw.times do |bx|
|
||||||
block = decode_etc1_block(BinUtils.get_sint64_be(bin, (bx + by * bw) * 8))
|
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
|
||||||
end
|
end
|
||||||
ret.crop(0, 0, width, height)
|
ret.crop(0, 0, height, width).rotate_left
|
||||||
end
|
end
|
||||||
|
|
||||||
# Decode image from ETC2 compressed binary
|
# Decode image from ETC2 compressed binary
|
||||||
@@ -377,14 +377,14 @@ module Mikunyan
|
|||||||
def self.decode_etc2rgb(width, height, bin)
|
def self.decode_etc2rgb(width, height, bin)
|
||||||
bw = (width + 3) / 4
|
bw = (width + 3) / 4
|
||||||
bh = (height + 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|
|
bh.times do |by|
|
||||||
bw.times do |bx|
|
bw.times do |bx|
|
||||||
block = decode_etc2_block(BinUtils.get_sint64_be(bin, (bx + by * bw) * 8))
|
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
|
||||||
end
|
end
|
||||||
ret.crop(0, 0, width, height)
|
ret.crop(0, 0, height, width).rotate_left
|
||||||
end
|
end
|
||||||
|
|
||||||
# Decode image from ETC2 Alpha8 compressed binary
|
# Decode image from ETC2 Alpha8 compressed binary
|
||||||
@@ -395,17 +395,17 @@ module Mikunyan
|
|||||||
def self.decode_etc2rgba8(width, height, bin)
|
def self.decode_etc2rgba8(width, height, bin)
|
||||||
bw = (width + 3) / 4
|
bw = (width + 3) / 4
|
||||||
bh = (height + 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|
|
bh.times do |by|
|
||||||
bw.times do |bx|
|
bw.times do |bx|
|
||||||
alpha = decode_etc2alpha_block(BinUtils.get_int64_be(bin, (bx + by * bw) * 16))
|
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))
|
block = decode_etc2_block(BinUtils.get_int64_be(bin, (bx + by * bw) * 16 + 8))
|
||||||
16.times do |i|
|
mem = String.new(capacity: 64)
|
||||||
mem[((i / 4 + bx * 4) + (i % 4 + by * 4) * bw * 4) * 4, 4] = block[i] + alpha[i]
|
16.times{|i| mem << block[i] + alpha[i]}
|
||||||
end
|
ret.replace!(ChunkyPNG::Image.from_rgba_stream(4, 4, mem), by * 4, bx * 4)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
# Decode image from ASTC compressed binary
|
# Decode image from ASTC compressed binary
|
||||||
@@ -498,10 +498,12 @@ module Mikunyan
|
|||||||
colors[1] = colors[1] | (colors[1] >> 5 & 0x70707)
|
colors[1] = colors[1] | (colors[1] >> 5 & 0x70707)
|
||||||
end
|
end
|
||||||
|
|
||||||
(0...16).map do |i|
|
mem = Fiddle::Pointer.malloc(48)
|
||||||
|
16.times do |i|
|
||||||
modifier = Etc1ModifierTable[codes[subblocks[i]]][bin[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
|
end
|
||||||
|
mem.to_str
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.etc1colormod(color, modifier)
|
def self.etc1colormod(color, modifier)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module Mikunyan
|
module Mikunyan
|
||||||
# version string
|
# version string
|
||||||
VERSION = "3.9.2"
|
VERSION = "3.9.3"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user