Skip to content

Commit

Permalink
feat: create Image/ImageFrame from Texture2D
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Feb 17, 2025
1 parent acbb6ed commit 6587d0c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public Image(ImageFormat.Types.Format format, int width, int height, int widthSt
: this(format, width, height, widthStep, pixelData, _VoidDeleter)
{ }

// TODO: detect format from the texture
public Image(ImageFormat.Types.Format format, Texture2D texture) :
this(format, texture.width, texture.height, format.NumberOfChannels() * texture.width, texture.GetRawTextureData<byte>())
{ }

public Image(Texture2D texture) : this(texture.format.ToImageFormat(), texture) { }

#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
public Image(uint target, uint name, int width, int height, GpuBufferFormat format, GlTextureBuffer.DeletionCallback callback, GlContext glContext) : base()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ public ImageFrame(ImageFormat.Types.Format format, int width, int height, int wi
: this(format, width, height, widthStep, pixelData, _VoidDeleter)
{ }

// TODO: detect format from the texture
public ImageFrame(ImageFormat.Types.Format format, Texture2D texture) :
this(format, texture.width, texture.height, format.NumberOfChannels() * texture.width, texture.GetRawTextureData<byte>())
{ }

public ImageFrame(Texture2D texture) : this(texture.format.ToImageFormat(), texture) { }

protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_ImageFrame__delete(ptr);
Expand Down

0 comments on commit 6587d0c

Please sign in to comment.