Skip to content

Commit

Permalink
refactor: naming & scene
Browse files Browse the repository at this point in the history
  • Loading branch information
netpyoung committed Oct 15, 2023
1 parent c9f5eee commit 07678f3
Show file tree
Hide file tree
Showing 11 changed files with 717 additions and 488 deletions.
92 changes: 47 additions & 45 deletions unity_project/Assets/Samples/example/Example.cs
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;
}
}
}
}
14 changes: 7 additions & 7 deletions unity_project/Assets/Samples/example/scene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Camera:
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_BackGroundColor: {r: 0.41176474, g: 0.38431376, b: 0.3647059, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
Expand Down Expand Up @@ -245,7 +245,7 @@ GameObject:
- component: {fileID: 170373109}
- component: {fileID: 170373108}
m_Layer: 5
m_Name: image3
m_Name: img_WebpUsingPool
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -318,7 +318,7 @@ GameObject:
- component: {fileID: 651955352}
- component: {fileID: 651955351}
m_Layer: 5
m_Name: image2
m_Name: img_Webp
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -423,9 +423,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6da470d719fc649fd97cbb35f6f5cf88, type: 3}
m_Name:
m_EditorClassIdentifier:
image1: {fileID: 1018053774}
image2: {fileID: 651955351}
image3: {fileID: 170373108}
_img_Origin: {fileID: 1018053774}
_img_Webp: {fileID: 651955351}
_img_WebpUsingPool: {fileID: 170373108}
--- !u!1 &1018053772
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -438,7 +438,7 @@ GameObject:
- component: {fileID: 1018053775}
- component: {fileID: 1018053774}
m_Layer: 5
m_Name: image1
m_Name: img_Origin
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down
Loading

0 comments on commit 07678f3

Please sign in to comment.