Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

WSQ to BMP converter

, 7 Feb 2013 CPOL
A WSQ to BMP converter.
Wsq2Bmp-noexe.zip
Wsq2Bmp
test
Properties
Wsq2Bmp
Properties
Wsq2Bmp.csproj.user
Wsq2Bmp.zip
bin
Debug
test.exe
test.vshost.exe
Wsq2Bmp.dll
bin
Debug
Wsq2Bmp.dll
Wsq2Bmp.csproj.user
using System;
using System.Collections.Generic;
using System.Text;

namespace Wsq2Bmp
{
    public class WsqHelper 
    {
        /*used to "mask out" n number of bits from data stream*/
        public static int[] BITMASK = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };

        public const int MAX_DHT_TABLES = 8;
        public const int MAX_HUFFBITS = 16;
        public const int MAX_HUFFCOUNTS_WSQ = 256;

        public const int W_TREELEN = 20;
        public const int Q_TREELEN = 64;

        /* WSQ Marker Definitions */
        public const int SOI_WSQ = 0xffa0;
        public const int EOI_WSQ = 0xffa1;
        public const int SOF_WSQ = 0xffa2;
        public const int SOB_WSQ = 0xffa3;
        public const int DTT_WSQ = 0xffa4;
        public const int DQT_WSQ = 0xffa5;
        public const int DHT_WSQ = 0xffa6;
        public const int DRT_WSQ = 0xffa7;
        public const int COM_WSQ = 0xffa8;

        public const int STRT_SUBBAND_2 = 19;
        public const int STRT_SUBBAND_3 = 52;
        public const int MAX_SUBBANDS = 64;
        public const int NUM_SUBBANDS = 60;
        public const int STRT_SUBBAND_DEL = NUM_SUBBANDS;
        public const int STRT_SIZE_REGION_2 = 4;
        public const int STRT_SIZE_REGION_3 = 51;

        /* Case for getting ANY marker. */
        public const int ANY_WSQ = 0xffff;
        public const int TBLS_N_SOF = 2;
        public const int TBLS_N_SOB = TBLS_N_SOF + 2;
    }

    public class WavletTree
    {
        public int x;
        public int y;
        public int lenx;
        public int leny;
        public int invrw;
        public int invcl;
    }

    public class TableDTT
    {
        public float[] lofilt;
        public float[] hifilt;
        public int losz;
        public int hisz;
        public int lodef;
        public int hidef;
    }

    public class HuffCode
    {
        public int size;
        public int code;
    }

    public class HeaderFrm
    {
        public int black;
        public int white;
        public int width;
        public int height;
        public float mShift;
        public float rScale;
        public int wsqEncoder;
        public int software;
    }

    public class HuffmanTable
    {
        public int tableLen;
        public int bytesLeft;
        public int tableId;
        public int[] huffbits;
        public int[] huffvalues;
    }

    public class TableDHT
    {
        private const int MAX_HUFFBITS = 16; /*DO NOT CHANGE THIS CONSTANT!! */
        private const int MAX_HUFFCOUNTS_WSQ = 256; /* Length of code table: change as needed */

        public byte tabdef;
        public int[] huffbits = new int[MAX_HUFFBITS];
        public int[] huffvalues = new int[MAX_HUFFCOUNTS_WSQ + 1];
    }

    public class Table_DQT
    {
        public const int MAX_SUBBANDS = 64;
        public float binCenter;
        public float[] qBin = new float[MAX_SUBBANDS];
        public float[] zBin = new float[MAX_SUBBANDS];
        public int dqtDef;
    }

    public class QuantTree
    {
        public int x;    /* UL corner of block */
        public int y;
        public int lenx;  /* block size */
        public int leny;  /* block size */
    }

    public class IntRef
    {
        public int value;


        public IntRef()
        {
        }

        public IntRef(int value)
        {
            this.value = value;
        }
    }

    public class Token
    {
        public TableDHT[] tableDHT;
        public TableDTT tableDTT;
        public Table_DQT tableDQT;

        public WavletTree[] wtree;
        public QuantTree[] qtree;


        public byte[] buffer;
        public int pointer;

        public Token(byte[] buffer)
        {
            this.buffer = buffer;
            this.pointer = 0;
        }

        public void initialize()
        {
            tableDTT = new TableDTT();
            tableDQT = new Table_DQT();

            /* Init DHT Tables to 0. */
            tableDHT = new TableDHT[WsqHelper.MAX_DHT_TABLES];
            for (int i = 0; i < WsqHelper.MAX_DHT_TABLES; i++)
            {
                tableDHT[i] = new TableDHT();
                tableDHT[i].tabdef = 0;
            }
        }

        public long readInt()
        {
            byte byte1 = buffer[pointer++];
            byte byte2 = buffer[pointer++];
            byte byte3 = buffer[pointer++];
            byte byte4 = buffer[pointer++];

            return (0xffL & byte1) << 24 | (0xffL & byte2) << 16 | (0xffL & byte3) << 8 | (0xffL & byte4);
        }

        public int readShort()
        {
            int byte1 = buffer[pointer++];
            int byte2 = buffer[pointer++];

            return (0xff & byte1) << 8 | (0xff & byte2);
        }

        public int readByte()
        {
            byte byte1 = buffer[pointer++];

            return 0xff & byte1;
        }

        public byte[] readBytes(int size)
        {
            byte[] bytes = new byte[size];

            for (int i = 0; i < size; i++)
            {
                bytes[i] = buffer[pointer++];
            }

            return bytes;
        }
    }

    //public class Bitmap
    //{
    //    private int width;
    //    private int height;
    //    private int ppi;
    //    private int depth;
    //    private int lossyflag;

    //    private byte[] pixels;
    //    private int length;

    //    public Bitmap(byte[] pixels, int width, int height, int ppi, int depth, int lossyflag) 
    //    {
    //        this.pixels = pixels;
    //        this.length = pixels != null ? pixels.Length : 0;

    //        this.width = width;
    //        this.height = height;
    //        this.ppi = ppi;
    //        this.depth = depth;
    //        this.lossyflag = lossyflag;
    //    }


    //    public int getWidth() 
    //    {
    //        return width;
    //    }

    //    public int getHeight() 
    //    {
    //        return height;
    //    }

    //    public int getPpi() 
    //    {
    //        return ppi;
    //    }

    //    public byte[] getPixels() 
    //    {
    //        return pixels;
    //    }

    //    public int getLength() 
    //    {
    //        return length;
    //    }

    //    public int getDepth() 
    //    {
    //        return depth;
    //    }

    //    public int getLossyflag() 
    //    {
    //        return lossyflag;
    //    }
    //}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

J.F. Sebastian
Software Developer (Senior)
Serbia Serbia
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141030.1 | Last Updated 7 Feb 2013
Article Copyright 2012 by J.F. Sebastian
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid