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

Compressonator.NET Samples #7

Open
ProbablePrime opened this issue Jan 27, 2025 · 0 comments
Open

Compressonator.NET Samples #7

ProbablePrime opened this issue Jan 27, 2025 · 0 comments
Labels
community help welcome help wanted Extra attention is needed

Comments

@ProbablePrime
Copy link
Member

A library without samples, isn't that desirable. I'm setting up a sample project in #6 but I dont actually know how to use this library or the underlying Native library.

Here's some code from an abandonned conversion sample, that didn't work for 3 hours :D, just in case it is useful for the next person through.

 var sourceTexture = new CMP_Texture();

 var width = 512;
 var height = 512;
 var bitsPerPixel = 4 * 8;

 sourceTexture.width = (uint)width;
 sourceTexture.height = (uint)height;
 sourceTexture.pitch = (uint)BitsToBytes(width * bitsPerPixel);
 sourceTexture.format = CMP_FORMAT.RGB_888;

 sourceTexture.CalculateDataSize();

 var destTexture = new CMP_Texture();

 destTexture.width = sourceTexture.width;
 destTexture.height = sourceTexture.height;
 destTexture.pitch = sourceTexture.pitch;
 destTexture.format = CMP_FORMAT.BC6H;

 destTexture.CalculateDataSize();


 FrameworkNativeMethods.CMP_LoadTexture("input.bmp", )


 var options = new CMP_CompressOptions();

 options.quality =  0.5f;
 options.numThreads = (uint)1;

 var fileBytes = File.ReadAllBytes("input.bmp");
 var outputBytes = new byte[destTexture.dataSize];

 unsafe
 {
     fixed (void* src = fileBytes)
     fixed (void* dst = outputBytes)
     {
         sourceTexture.data = new IntPtr(src);
         destTexture.data = new IntPtr(dst);

         var result = SDK_NativeMethods.CMP_ConvertTexture(sourceTexture, destTexture, options, IntPtr.Zero);

         if (result != CMP_ERROR.CMP_OK)
             throw new Exception("Conversion error: " + result);
     }
 }

 File.WriteAllBytes("output.bmp", outputBytes);
@ProbablePrime ProbablePrime added the help wanted Extra attention is needed label Jan 27, 2025
@ProbablePrime ProbablePrime changed the title Samples Compressonator.NET Samples Jan 27, 2025
@ProbablePrime ProbablePrime mentioned this issue Jan 28, 2025
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community help welcome help wanted Extra attention is needed
Projects
Status: Todo
Development

No branches or pull requests

1 participant