Lossless JBIG2 Encoder Windows Dynamic Libary

bases on Jbig2, modified and distributed by a Chinese developer, for windows execute version, please visit JBig2enc Win32 version.

download Lossless JBIG2 Encoder Windows Dynamic Libary

P.S.

This page only offer Window dynamic version jbig2 Encoder, for more solutions, please visit Open Source Jbig2 Encoder and Decoder.

usage example of C#:

///<summary>JBIG2 Lossless Encoder Wrapper</summary>
public static class JBig2Encoder
{
    static uint White = 0x00FFFFFF;

    public static byte[] Encode (Bitmap bmp, bool zeroIsWhite) {
        var bits = bmp.LockBits (new System.Drawing.Rectangle (0, 0, bmp.Width, bmp.Height)
                               , System.Drawing.Imaging.ImageLockMode.ReadOnly
                               , System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
        var bytes = Encode (bmp.Width, bmp.Height, bits.Stride, zeroIsWhite, bits.Scan0);
        bmp.UnlockBits (bits);
        return bytes;
    }

    private static byte[] Encode (int width, int height, int stride, bool zeroIsWhite, IntPtr b) {
        int l = 0;
        var r = NativeMethods.jbig2_encode (width, height, stride, zeroIsWhite, b, ref l);
        byte[] result = new byte[l];
        Marshal.Copy (r, result, 0, l);
        NativeMethods.release (r);
        return result;
    }

    class NativeMethods
    {
        [DllImport ("jbig2enc.dll")]
        internal static extern IntPtr jbig2_encode (int width, int height, int stride
                                                   , bool zeroIsWhite, IntPtr data, ref int length);
        [DllImport ("jbig2enc.dll")]
        internal static extern IntPtr release (IntPtr data);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *