-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
717 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,64 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using WebP; | ||
|
||
public class Example : MonoBehaviour | ||
namespace WebP.Example | ||
{ | ||
public RawImage image1; | ||
public RawImage image2; | ||
public RawImage image3; | ||
|
||
void Start() | ||
public class Example : MonoBehaviour | ||
{ | ||
LoadOrigin(image1); | ||
LoadWebp(image2); | ||
LoadWebpUsingPool(image3); | ||
} | ||
public RawImage _img_Origin; | ||
public RawImage _img_Webp; | ||
public RawImage _img_WebpUsingPool; | ||
|
||
void LoadWebpUsingPool(RawImage image) | ||
{ | ||
byte[] bytePool = new byte[1024 * 1024 * 10]; | ||
void Start() | ||
{ | ||
LoadOrigin(_img_Origin); | ||
LoadWebp(_img_Webp); | ||
LoadWebpUsingPool(_img_WebpUsingPool); | ||
} | ||
|
||
var textasset = Resources.Load<TextAsset>("webp"); | ||
var webpBytes = textasset.bytes; | ||
void LoadWebpUsingPool(RawImage image) | ||
{ | ||
byte[] bytePool = new byte[1024 * 1024 * 10]; | ||
|
||
Texture2DExt.GetWebPDimensions(webpBytes, out int width, out int height); | ||
|
||
Texture2D texture = Texture2DExt.CreateWebpTexture2D(width, height, isUseMipmap: true, isLinear: false); | ||
image.texture = texture; | ||
TextAsset textasset = Resources.Load<TextAsset>("webp"); | ||
byte[] webpBytes = textasset.bytes; | ||
|
||
int numBytesRequired = Texture2DExt.GetRequireByteSize(width, height, isUseMipmap: true); | ||
|
||
Debug.Assert(bytePool.Length >= numBytesRequired); | ||
|
||
Texture2DExt.LoadTexture2DFromWebP(webpBytes, texture, lMipmaps: true, lLinear: true, bytePool, numBytesRequired); | ||
} | ||
Texture2DExt.GetWebPDimensions(webpBytes, out int width, out int height); | ||
|
||
void LoadWebp(RawImage image) | ||
{ | ||
var textasset = Resources.Load<TextAsset>("webp"); | ||
var bytes = textasset.bytes; | ||
Texture2D texture = Texture2DExt.CreateWebpTexture2D(width, height, isUseMipmap: true, isLinear: false); | ||
image.texture = texture; | ||
|
||
Texture2D texture = Texture2DExt.CreateTexture2DFromWebP(bytes, lMipmaps: true, lLinear: false, lError: out Error lError); | ||
int numBytesRequired = Texture2DExt.GetRequireByteSize(width, height, isUseMipmap: true); | ||
|
||
if (lError == Error.Success) | ||
{ | ||
image.texture = texture; | ||
Debug.Assert(bytePool.Length >= numBytesRequired); | ||
|
||
Texture2DExt.LoadTexture2DFromWebP(webpBytes, texture, lMipmaps: true, lLinear: true, bytePool, numBytesRequired); | ||
} | ||
else | ||
|
||
void LoadWebp(RawImage image) | ||
{ | ||
Debug.LogError("Webp Load Error : " + lError.ToString()); | ||
TextAsset textasset = Resources.Load<TextAsset>("webp"); | ||
byte[] bytes = textasset.bytes; | ||
|
||
Texture2D texture = Texture2DExt.CreateTexture2DFromWebP(bytes, lMipmaps: true, lLinear: false, lError: out Error lError); | ||
|
||
if (lError == Error.Success) | ||
{ | ||
image.texture = texture; | ||
} | ||
else | ||
{ | ||
Debug.LogError("Webp Load Error : " + lError.ToString()); | ||
} | ||
} | ||
} | ||
|
||
void LoadOrigin(RawImage image) | ||
{ | ||
var textasset = Resources.Load<TextAsset>("origin"); | ||
var bytes = textasset.bytes; | ||
var texture = new Texture2D(512, 512, TextureFormat.RGBA32, mipChain: false, linear: false); | ||
texture.LoadImage(bytes); | ||
image.texture = texture; | ||
void LoadOrigin(RawImage image) | ||
{ | ||
TextAsset textasset = Resources.Load<TextAsset>("origin"); | ||
byte[] bytes = textasset.bytes; | ||
Texture2D texture = new Texture2D(512, 512, TextureFormat.RGBA32, mipChain: false, linear: false); | ||
texture.LoadImage(bytes); | ||
image.texture = texture; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.