Beispiel #1
0
        private void DecodeBlock(Component *c, byte *outv)
        {
            byte code = 0;
            int  value, coef = 0;

            FillMem((long *)block, 0, 64 / 2);            // use long instead of int
            c->dcpred += GetVLC(&vlctab[c->dctabsel][0], null);
            block[0]   = (c->dcpred) * qtab[c->qtsel][0];
            do
            {
                value = GetVLC(&vlctab[c->actabsel][0], &code);
                if (code == 0)
                {
                    break;                      // EOB
                }
                if ((code & 0x0F) == 0 && code != 0xF0)
                {
                    //
                }
                coef += (code >> 4) + 1;
                if (coef > 63)
                {
                    //
                }
                block[AntiZigZag[coef]] = value * qtab[c->qtsel][coef];
            } while (coef < 63);
            for (coef = 0; coef < 64; coef += 8)
            {
                RowIDCT(&block[coef]);
            }
            for (coef = 0; coef < 8; ++coef)
            {
                ColIDCT(&block[coef], &outv[coef], c->stride);
            }
        }
Beispiel #2
0
 private static void FillMem(Component *block, Component value, int count)
 {
     for (int i = 0; i < count; i++)
     {
         block[i] = value;
     }
 }
Beispiel #3
0
        private void DecodeBlock(Component *c, byte *outv)
        {
            byte code = 0;
            int  value, coef = 0;

            FillMem((long *)block, 0, 64 / 2);//use long instead of int
            c->dcpred    += GetVLC(&this.vlctab[c->dctabsel][0], null);
            this.block[0] = (c->dcpred) * this.qtab[c->qtsel][0];
            do
            {
                value = GetVLC(&this.vlctab[c->actabsel][0], &code);
                if (code == 0)
                {
                    break;             // EOB
                }
                if ((code & 0x0F) == 0 && code != 0xF0)
                {
                    throw new NJException(NJErrorCode.SyntaxError);
                }
                coef += (code >> 4) + 1;
                if (coef > 63)
                {
                    throw new NJException(NJErrorCode.SyntaxError);
                }
                this.block[(int)njZZ[coef]] = value * this.qtab[c->qtsel][coef];
            } while (coef < 63);
            for (coef = 0; coef < 64; coef += 8)
            {
                RowIDCT(&this.block[coef]);
            }
            for (coef = 0; coef < 8; ++coef)
            {
                ColIDCT(&this.block[coef], &outv[coef], c->stride);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new instance of the <see cref="NJImage"/> class
        /// </summary>
        public NJImage()
        {
            comp  = (Component *)Marshal.AllocHGlobal(3 * Marshal.SizeOf(typeof(Component)));
            block = (int *)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(int)));

            FillMem(comp, new Component(), 3);

            qtab   = (byte **)Marshal.AllocHGlobal(4 * IntPtr.Size);
            vlctab = (VLCCode **)Marshal.AllocHGlobal(4 * IntPtr.Size);
            for (int i = 0; i < 4; i++)
            {
                qtab[i]   = (byte *)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(byte)));
                vlctab[i] = (VLCCode *)Marshal.AllocHGlobal(65536 * Marshal.SizeOf(typeof(VLCCode)));

                FillMem((long *)qtab[i], 0, 64 / 8);      //use long instead of byte
                FillMem((long *)vlctab[i], 0, 65536 / 4); //use long instead of VLCCode (length=2)
            }
        }
Beispiel #5
0
        private void UpsampleH(Component *c)
        {
            int   xmax = c->width - 3;
            byte *outv, lin, lout;
            int   x, y;

            try
            {
                outv = (byte *)Marshal.AllocHGlobal((c->width * c->height) << 1);
                lin  = c->pixels;
                lout = outv;
                for (y = c->height; y != 0; --y)
                {
                    lout[0] = CF(CF2A * lin[0] + CF2B * lin[1]);
                    lout[1] = CF(CF3X * lin[0] + CF3Y * lin[1] + CF3Z * lin[2]);
                    lout[2] = CF(CF3A * lin[0] + CF3B * lin[1] + CF3C * lin[2]);

                    for (x = 0; x < xmax; ++x)
                    {
                        lout[(x << 1) + 3] = CF(CF4A * lin[x] + CF4B * lin[x + 1] + CF4C * lin[x + 2] + CF4D * lin[x + 3]);
                        lout[(x << 1) + 4] = CF(CF4D * lin[x] + CF4C * lin[x + 1] + CF4B * lin[x + 2] + CF4A * lin[x + 3]);
                    }

                    lin  += c->stride;
                    lout += c->width << 1;

                    lout[-3] = CF(CF3A * lin[-1] + CF3B * lin[-2] + CF3C * lin[-3]);
                    lout[-2] = CF(CF3X * lin[-1] + CF3Y * lin[-2] + CF3Z * lin[-3]);
                    lout[-1] = CF(CF2A * lin[-1] + CF2B * lin[-2]);
                }
                c->width <<= 1;
                c->stride  = c->width;
            }
            finally
            {
                if (c->pixels != null)
                {
                    Marshal.FreeHGlobal((IntPtr)c->pixels);
                }
            }
            c->pixels = outv;
        }
Beispiel #6
0
        private void UpsampleV(Component *c)
        {
            int   w = c->width, s1 = c->stride, s2 = s1 + s1;
            byte *outv, cin, cout;
            int   x, y;

            try
            {
                outv = (byte *)Marshal.AllocHGlobal((c->width * c->height) << 1);
                for (x = 0; x < w; ++x)
                {
                    cin  = &c->pixels[x];
                    cout = &outv[x];
                    *cout = CF(CF2A * cin[0] + CF2B * cin[s1]); cout += w;
                    *cout = CF(CF3X * cin[0] + CF3Y * cin[s1] + CF3Z * cin[s2]); cout += w;
                    *cout = CF(CF3A * cin[0] + CF3B * cin[s1] + CF3C * cin[s2]); cout += w;
                    cin += s1;
                    for (y = c->height - 3; y != 0; --y)
                    {
                        *cout = CF(CF4A * cin[-s1] + CF4B * cin[0] + CF4C * cin[s1] + CF4D * cin[s2]); cout += w;
                        *cout = CF(CF4D * cin[-s1] + CF4C * cin[0] + CF4B * cin[s1] + CF4A * cin[s2]); cout += w;
                        cin += s1;
                    }
                    cin += s1;
                    *cout = CF(CF3A * cin[0] + CF3B * cin[-s1] + CF3C * cin[-s2]); cout += w;
                    *cout = CF(CF3X * cin[0] + CF3Y * cin[-s1] + CF3Z * cin[-s2]); cout += w;
                    *cout = CF(CF2A * cin[0] + CF2B * cin[-s1]);
                }
                c->height <<= 1;
                c->stride   = c->width;
            }
            finally
            {
                if (c->pixels != null)
                {
                    Marshal.FreeHGlobal((IntPtr)c->pixels);
                }
            }
            c->pixels = outv;
        }
Beispiel #7
0
        public Jpeg(MainForm fm, string filename)
        {
            this.mf = fm;

            comp  = (Component *)Marshal.AllocHGlobal(3 * Marshal.SizeOf(typeof(Component)));
            block = (int *)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(int)));

            FillMem(comp, new Component(), 3);

            qtab   = (byte **)Marshal.AllocHGlobal(4 * IntPtr.Size);
            vlctab = (VLCCode **)Marshal.AllocHGlobal(4 * IntPtr.Size);
            for (int i = 0; i < 4; i++)
            {
                qtab[i]   = (byte *)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(byte)));
                vlctab[i] = (VLCCode *)Marshal.AllocHGlobal(65536 * Marshal.SizeOf(typeof(VLCCode)));

                FillMem((long *)qtab[i], 0, 64 / 8);                // use long instead of byte
                FillMem((long *)vlctab[i], 0, 65536 / 4);           // use long instead of VLCCode (length=2)
            }

            Decode(filename);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="NJImage"/> class
        /// </summary>
        public NJImage()
        {
            comp = (Component*)Marshal.AllocHGlobal(3 * Marshal.SizeOf(typeof(Component)));
            block = (int*)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(int)));

            FillMem(comp, new Component(), 3);

            qtab = (byte**)Marshal.AllocHGlobal(4 * IntPtr.Size);
            vlctab = (VLCCode**)Marshal.AllocHGlobal(4 * IntPtr.Size);
            for (int i = 0; i < 4; i++)
            {
                qtab[i] = (byte*)Marshal.AllocHGlobal(64 * Marshal.SizeOf(typeof(byte)));
                vlctab[i] = (VLCCode*)Marshal.AllocHGlobal(65536 * Marshal.SizeOf(typeof(VLCCode)));

                FillMem((long*)qtab[i], 0, 64 / 8);//use long instead of byte
                FillMem((long*)vlctab[i], 0, 65536 / 4);//use long instead of VLCCode (length=2)
            }
        }