Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
 private static extern bool LibslDecode(ref LibslImage image);
Exemplo n.º 4
0
 private static extern bool LibslEncode(ref LibslImage image, bool lossless);
Exemplo n.º 5
0
 private static extern bool LibslFree(ref LibslImage image);
Exemplo n.º 6
0
 private static extern bool LibslAllocDecoded(ref LibslImage image);