Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create Image/ImageFrame from Texture2D #1329

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading