Exemple #1
0
        public static byte[] Decode(byte[] encoded, out int width, out int height, out int components)
        {
            LibslImage image = new LibslImage();

            // allocate and copy to input buffer
            image.length = encoded.Length;
            LibslAllocEncoded(ref image);
            Marshal.Copy(encoded, 0, image.encoded, encoded.Length);

            // codec will allocate output buffer
            LibslDecode(ref image);

            // copy output buffer
            byte[] decoded = new byte[image.width * image.height * image.components];
            Marshal.Copy(image.decoded, decoded, 0, image.width * image.height * image.components);

            // copy image dimensions
            width = image.width;
            height = image.height;
            components = image.components;

            // free buffers
            LibslFree(ref image);

            return decoded;
        }
Exemple #2
0
        // encode 
        public static byte[] Encode(byte[] decoded, int width, int height, int components, bool lossless)
        {
            if (decoded.Length != width * height * components)
                throw new ArgumentException("Length of decoded buffer does not match parameters");
            
            LibslImage image = new LibslImage();

            // allocate and copy to input buffer
            image.width = width;
            image.height = height;
            image.components = components;
            LibslAllocDecoded(ref image);
            Marshal.Copy(decoded, 0, image.decoded, width * height * components);

            // codec will allocate output buffer
            LibslEncode(ref image, lossless);

            // copy output buffer
            byte[] encoded = new byte[image.length];
            Marshal.Copy(image.encoded, encoded, 0, image.length);

            // free buffers
            LibslFree(ref image);

            return encoded;
        }
Exemple #3
0
 private static extern bool LibslDecode(ref LibslImage image);
Exemple #4
0
 private static extern bool LibslEncode(ref LibslImage image, bool lossless);
Exemple #5
0
 private static extern bool LibslFree(ref LibslImage image);
Exemple #6
0
 private static extern bool LibslAllocDecoded(ref LibslImage image);