mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0038a5184 | ||
|
|
6665fab8d9 | ||
|
|
6998127fe8 | ||
|
|
8f68931c40 | ||
|
|
eb9536456e |
No files matched your search
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Astc
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class AstcDecoder
|
||||
{
|
||||
private unsafe struct BlockData
|
||||
@@ -31,6 +32,15 @@ namespace TextureDecoder.Astc
|
||||
public int nonbits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="blockWidth"></param>
|
||||
/// <param name="blockHeight"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecodeASTC(byte[] input, int width, int height, int blockWidth, int blockHeight)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -38,6 +48,15 @@ namespace TextureDecoder.Astc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="blockWidth"></param>
|
||||
/// <param name="blockHeight"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecodeASTC(byte[] input, int width, int height, int blockWidth, int blockHeight, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -49,6 +68,15 @@ namespace TextureDecoder.Astc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="blockWidth"></param>
|
||||
/// <param name="blockHeight"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecodeASTC(byte* input, int width, int height, int blockWidth, int blockHeight, byte* output)
|
||||
{
|
||||
int bcw = (width + blockWidth - 1) / blockWidth;
|
||||
|
||||
@@ -3,8 +3,18 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Atc
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class AtcDecoder
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressAtcRgb4(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -12,6 +22,13 @@ namespace TextureDecoder.Atc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressAtcRgb4(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -23,6 +40,13 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressAtcRgb4(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -47,6 +71,13 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressAtcRgba8(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -54,6 +85,13 @@ namespace TextureDecoder.Atc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressAtcRgba8(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -65,6 +103,13 @@ namespace TextureDecoder.Atc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressAtcRgba8(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
|
||||
@@ -3,8 +3,18 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Dxt
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class DxtDecoder
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void DecompressDXT1(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int offset = 0;
|
||||
@@ -49,7 +59,13 @@ namespace TextureDecoder.Dxt
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void DecompressDXT3(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int offset = 0;
|
||||
@@ -104,6 +120,13 @@ namespace TextureDecoder.Dxt
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void DecompressDXT5(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Etc
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class EtcDecoder
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressETC(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -12,6 +21,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -23,6 +39,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -47,6 +70,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressETC2(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -54,6 +84,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -65,6 +102,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -89,6 +133,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressETC2A1(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -96,6 +147,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2A1(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -107,6 +165,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2A1(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int width4 = width * 4;
|
||||
@@ -132,6 +197,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressETC2A8(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -139,6 +211,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2A8(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -150,6 +229,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressETC2A8(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -175,6 +261,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressEACRUnsigned(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -182,6 +275,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRUnsigned(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -193,6 +293,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRUnsigned(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -221,6 +328,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressEACRSigned(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -228,6 +342,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRSigned(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -239,6 +360,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRSigned(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -267,6 +395,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressEACRGUnsigned(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -274,6 +409,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRGUnsigned(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -285,6 +427,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRGUnsigned(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
@@ -314,6 +463,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressEACRGSigned(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -321,6 +477,13 @@ namespace TextureDecoder.Etc
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRGSigned(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
fixed (byte* inputPtr = input)
|
||||
@@ -332,6 +495,13 @@ namespace TextureDecoder.Etc
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public unsafe static void DecompressEACRGSigned(byte* input, int width, int height, byte* output)
|
||||
{
|
||||
int bcw = (width + 3) / 4;
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
#define ASSUME_IMAGE_TILING
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Pvrtc
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class PvrtcDecoder
|
||||
{
|
||||
private struct AmtcBlock
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Rgb
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class RgbConverter
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] A8ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -11,6 +22,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void A8ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -29,6 +47,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ARGB16ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -36,6 +61,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void ARGB16ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -54,6 +86,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGB24ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -61,6 +100,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGB24ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -79,6 +125,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGBA32ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -86,6 +139,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGBA32ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -104,6 +164,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ARGB32ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -111,6 +178,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void ARGB32ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -129,6 +203,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGB16ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -136,6 +217,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGB16ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -157,6 +245,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] R16ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -164,6 +259,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void R16ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -182,6 +284,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGBA16ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -189,6 +298,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGBA16ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -207,6 +323,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RG16ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -214,6 +337,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RG16ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -232,6 +362,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] R8ToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -239,6 +376,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void R8ToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -257,6 +401,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RHalfToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -264,6 +415,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RHalfToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -272,7 +430,7 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(ToHalf(input, io) * 255f));
|
||||
byte r = ClampByte(ToHalf(input, io) * 255f);
|
||||
output[oo + 0] = 0; // b
|
||||
output[oo + 1] = 0; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -283,6 +441,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGHalfToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -290,6 +455,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGHalfToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -298,8 +470,8 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(ToHalf(input, io + 0) * 255f));
|
||||
byte g = Convert.ToByte(Math.Round(ToHalf(input, io + 2) * 255f));
|
||||
byte r = ClampByte(ToHalf(input, io + 0) * 255f);
|
||||
byte g = ClampByte(ToHalf(input, io + 2) * 255f);
|
||||
output[oo + 0] = 0; // b
|
||||
output[oo + 1] = g; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -310,6 +482,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGBAHalfToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -317,6 +496,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGBAHalfToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -325,10 +511,10 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(ToHalf(input, io + 0) * 255f));
|
||||
byte g = Convert.ToByte(Math.Round(ToHalf(input, io + 2) * 255f));
|
||||
byte b = Convert.ToByte(Math.Round(ToHalf(input, io + 4) * 255f));
|
||||
byte a = Convert.ToByte(Math.Round(ToHalf(input, io + 6) * 255f));
|
||||
byte r = ClampByte(ToHalf(input, io + 0) * 255f);
|
||||
byte g = ClampByte(ToHalf(input, io + 2) * 255f);
|
||||
byte b = ClampByte(ToHalf(input, io + 4) * 255f);
|
||||
byte a = ClampByte(ToHalf(input, io + 6) * 255f);
|
||||
output[oo + 0] = b; // b
|
||||
output[oo + 1] = g; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -339,6 +525,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RFloatToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -346,6 +539,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RFloatToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -354,7 +554,7 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io) * 255f));
|
||||
byte r = ClampByte(ToSingle(input, io) * 255f);
|
||||
output[oo + 0] = 0; // b
|
||||
output[oo + 1] = 0; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -365,6 +565,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGFloatToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -372,6 +579,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGFloatToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -380,8 +594,8 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 0) * 255f));
|
||||
byte g = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 4) * 255f));
|
||||
byte r = ClampByte(ToSingle(input, io + 0) * 255f);
|
||||
byte g = ClampByte(ToSingle(input, io + 4) * 255f);
|
||||
output[oo + 0] = 0; // b
|
||||
output[oo + 1] = g; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -392,6 +606,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGBAFloatToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -399,6 +620,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGBAFloatToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -407,10 +635,10 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
byte r = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 0) * 255f));
|
||||
byte g = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 4) * 255f));
|
||||
byte b = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 8) * 255f));
|
||||
byte a = Convert.ToByte(Math.Round(BitConverter.ToSingle(input, io + 12) * 255f));
|
||||
byte r = ClampByte(ToSingle(input, io + 0));
|
||||
byte g = ClampByte(ToSingle(input, io + 4));
|
||||
byte b = ClampByte(ToSingle(input, io + 8));
|
||||
byte a = ClampByte(ToSingle(input, io + 12));
|
||||
output[oo + 0] = b; // b
|
||||
output[oo + 1] = g; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -421,6 +649,13 @@ namespace TextureDecoder.Rgb
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] RGB9e5FloatToBGRA32(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
@@ -428,6 +663,13 @@ namespace TextureDecoder.Rgb
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void RGB9e5FloatToBGRA32(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int io = 0;
|
||||
@@ -438,9 +680,9 @@ namespace TextureDecoder.Rgb
|
||||
{
|
||||
uint value = BitConverter.ToUInt32(input, io);
|
||||
double scale = Math.Pow(2, unchecked((int)(value >> 27) - 24));
|
||||
byte r = Convert.ToByte(Math.Round((value >> 0 & 0x1FF) * scale * 255.0));
|
||||
byte g = Convert.ToByte(Math.Round((value >> 9 & 0x1FF) * scale * 255.0));
|
||||
byte b = Convert.ToByte(Math.Round((value >> 18 & 0x1FF) * scale * 255.0));
|
||||
byte r = ClampByte((value >> 0 & 0x1FF) * scale * 255.0);
|
||||
byte g = ClampByte((value >> 9 & 0x1FF) * scale * 255.0);
|
||||
byte b = ClampByte((value >> 18 & 0x1FF) * scale * 255.0);
|
||||
output[oo + 0] = b; // b
|
||||
output[oo + 1] = g; // g
|
||||
output[oo + 2] = r; // r
|
||||
@@ -464,5 +706,29 @@ namespace TextureDecoder.Rgb
|
||||
return (float)Half.ToHalf(input, offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static float ToSingle(byte[] input, int offset)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return System.Buffers.Binary.BinaryPrimitives.ReadSingleLittleEndian(input.AsSpan(offset, 4));
|
||||
#else
|
||||
if (BitConverter.IsLittleEndian)
|
||||
return BitConverter.ToSingle(input, offset);
|
||||
else
|
||||
return BitConverter.ToSingle(new byte[] { input[offset + 3], input[offset + 2], input[offset + 1], input[offset] }, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static byte ClampByte(float x)
|
||||
{
|
||||
return byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? (byte)x : byte.MinValue);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static byte ClampByte(double x)
|
||||
{
|
||||
return byte.MaxValue < x ? byte.MaxValue : (x > byte.MinValue ? (byte)x : byte.MinValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<Version>1.0.2.0</Version>
|
||||
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
||||
<PackageId>TextureDecoder</PackageId>
|
||||
<PackageTags>C# Texture</PackageTags>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/TextureDecoder</RepositoryUrl>
|
||||
|
||||
@@ -2,8 +2,18 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace TextureDecoder.Yuy2
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class Yuy2Decoder
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] DecompressYUY2(byte[] input, int width, int height)
|
||||
{
|
||||
byte[] output = new byte[width * height * sizeof(uint)];
|
||||
@@ -11,6 +21,13 @@ namespace TextureDecoder.Yuy2
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="output"></param>
|
||||
public static void DecompressYUY2(byte[] input, int width, int height, byte[] output)
|
||||
{
|
||||
int p = 0;
|
||||
|
||||
Reference in new issue
Block a user