コード例 #1
0
ファイル: opcode.c.cs プロジェクト: weimingtom/KopiLuaCompare
        private static int do_protectedmain()
        {
            BytePtr code = null;
            int     status;
            StkId   oldCBase   = CBase;
            jmp_buf myErrorJmp = new jmp_buf();
            jmp_buf oldErr     = errorJmp;

            errorJmp = myErrorJmp;
            try             //if (setjmp(myErrorJmp) == 0)
            {
                Object_ f = new Object_();
                lua_parse(ref code);
                tag(f, lua_Type.LUA_T_FUNCTION); bvalue(f, code);
                do_call(f, CBase, 0, CBase);
                status = 0;
            }
            catch (LongjmpException) {             //else {
                status = 1;
            }
            if (code != null)
            {
                luaI_free_BytePtr(ref code);
            }
            errorJmp = oldErr;
            CBase    = oldCBase;
            top      = new ObjectRef(stack, CBase);
            return(status);
        }
コード例 #2
0
ファイル: decoder.cs プロジェクト: cr88192/bgbtech_engine
        public static BytePtr PDJPG_Decode(BytePtr buf, int sz, out int xs, out int ys)
        {
            PDJPG_Context ctx;
            BytePtr obuf;
            BytePtr otbuf, otbuf2;
            BytePtr csl;
            int i, n, sz1;

            ctx = PDJPG_AllocContext();
            obuf = PDJPG_DecodeCtx(ctx, buf, sz, out xs, out ys);
            //	ctx.jpg_imgbuf=null;

            csl = PDJPG_DecodeScanForComponentLayer(buf, sz, "Alpha");
            if (!csl.isNull)
            {
                sz1 = sz - ((BytePtr)csl - buf);
                otbuf = (BytePtr)PDJPG_DecodeLDatCtx(ctx, (BytePtr)csl, sz1, out xs, out ys);

                otbuf2 = (BytePtr)obuf;
                n = ctx.xs * ctx.ys;
                for (i = 0; i < n; i++)
                {
                    otbuf2[i * 4 + 3] = otbuf[i * 4 + 1];
                }
            }

            PDJPG_FreeContext(ctx);
            return (obuf);
        }
コード例 #3
0
ファイル: CLib.cs プロジェクト: weimingtom/KopiLuaCompare
 public static BytePtr memcpy(BytePtr ptr1, BytePtr ptr2, uint size)
 {
     for (int i = 0; i < size; i++)
     {
         ptr1[i] = ptr2[i];
     }
     return(ptr1);
 }
コード例 #4
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public void set(Value v)
 {
     this.f        = v.f;
     this.n        = v.n;
     this.s        = v.s;
     this.b        = v.b;
     this.a        = v.a;
     this.u        = v.u;
     this.__name__ = v.__name__;
 }
コード例 #5
0
 public void set(YYSTYPE s)
 {
     this.vInt   = s.vInt;
     this.vLong  = s.vLong;
     this.vFloat = s.vFloat;
     this.vWord  = s.vWord;
     if (s.pByte != null)
     {
         this.pByte = new BytePtr(s.pByte);
     }
     else
     {
         this.pByte = null;
     }
 }
コード例 #6
0
ファイル: CLib.cs プロジェクト: weimingtom/KopiLuaCompare
 public static BytePtr realloc_BytePtr(BytePtr obj, uint size)
 {
     byte[] ret = new byte[size];
     for (int i = 0; i < size; ++i)
     {
         if (i < obj.chars.Length)
         {
             ret[i] = obj[i];
         }
         else
         {
             ret[i] = (Byte)0;
         }
     }
     if (obj.index != 0)
     {
         throw new Exception("realloc_BytePtr not zero index");
     }
     return(new BytePtr(ret, obj.index));
 }
コード例 #7
0
ファイル: Code.cs プロジェクト: cr88192/bgbtech_engine
        protected void LoadDocumentLayer(Document doc, BytePtr ibuf, int sz, string name)
        {
            BitmapLayer layer;
            Bitmap bmp;
            PDJPG_LayerInfo linf;
            byte[] rgba;
            byte[] norm;
            byte[] spec;
            byte[] luma;
            int xs, ys, ox, oy, ln, fl;
//            int i, j;

            rgba = new byte[4096 * 4096 * 4];
            norm = new byte[4096 * 4096 * 4];
            spec = new byte[4096 * 4096 * 4];
            luma = new byte[4096 * 4096 * 4];

            PDJPG.PDJPG_DecodeComponent(ibuf, sz, rgba, norm, spec, luma, out xs, out ys, out linf);
            fl = linf.flags;

            //PDJPG_DecodeHasComponent()

            ln = doc.Layers.Count;
            //doc.Layers.Insert(ln, null);

            if (true)
            {
                //layer = new BitmapLayer(xs, ys);
                layer = new BitmapLayer(doc.Width, doc.Height);
                layer.Name = name;
                layer.Opacity = linf.alpha;
                layer.Visible = true;

                if((fl&PDJPG.PDJPG_BCSFL_LAYER_HIDDEN)!=0)
                    layer.Visible = false;

                if ((fl & PDJPG.PDJPG_BCSFL_ALPHACYAN) != 0)
                {
                    BlendByteBufferInverseTransparentColor(rgba, xs, ys);
                }

                //bmp = BitmapFromByteBuffer(rgba, xs, ys);
                bmp = BitmapFromByteBuffer(rgba, xs, ys, doc.Width, doc.Height, linf.orgx, linf.orgy);
                layer.Surface.CopyFromGdipBitmap(bmp, false);
                doc.Layers.Insert(ln++, layer);
            }

            if (PDJPG.PDJPG_DecodeHasComponent(ibuf, sz, "XYZ"))
            {
                //layer = new BitmapLayer(xs, ys);
                layer = new BitmapLayer(doc.Width, doc.Height);
                layer.Name = name + "::Normal";
                layer.Opacity = linf.alpha;
                layer.Visible = false;

                //bmp = BitmapFromByteBufferRGB(norm, xs, ys);
                bmp = BitmapFromByteBufferRGB(norm, xs, ys, doc.Width, doc.Height, linf.orgx, linf.orgy);
                layer.Surface.CopyFromGdipBitmap(bmp, false);
                doc.Layers.Insert(ln++, layer);
            }

            if (PDJPG.PDJPG_DecodeHasComponent(ibuf, sz, "SpRGB"))
            {
                //layer = new BitmapLayer(xs, ys);
                layer = new BitmapLayer(doc.Width, doc.Height);
                layer.Name = name + "::Specular";
                layer.Opacity = linf.alpha;
                layer.Visible = false;

                //bmp = BitmapFromByteBufferRGB(spec, xs, ys);
                bmp = BitmapFromByteBufferRGB(spec, xs, ys, doc.Width, doc.Height, linf.orgx, linf.orgy);
                layer.Surface.CopyFromGdipBitmap(bmp, false);
                doc.Layers.Insert(ln++, layer);
            }

            if (PDJPG.PDJPG_DecodeHasComponent(ibuf, sz, "LuRGB"))
            {
                //layer = new BitmapLayer(xs, ys);
                layer = new BitmapLayer(doc.Width, doc.Height);
                layer.Name = name + "::Luma";
                layer.Opacity = linf.alpha;
                layer.Visible = false;

                //bmp = BitmapFromByteBufferRGB(luma, xs, ys);
                bmp = BitmapFromByteBufferRGB(luma, xs, ys, doc.Width, doc.Height, linf.orgx, linf.orgy);
                layer.Surface.CopyFromGdipBitmap(bmp, false);
                doc.Layers.Insert(ln++, layer);
            }

        }
コード例 #8
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
 public static BytePtr PDJPG_EncodeEndLayeredCtx(
     PDJPG_Context ctx, BytePtr ct)
 {
     ct.emit(0xFF);
     ct.emit(JPG.JPG_EOI);
     return ct;
 }
コード例 #9
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
 public static int PDJPG_EncodeComponentCtx(
     PDJPG_Context ctx,
     byte[] rgba, byte[] norm, byte[] spec, byte[] luma,
     BytePtr obuf, int xs, int ys, int qf)
 {
     return (PDJPG_EncodeComponentCtxI(ctx,
         rgba, norm, spec, luma, null,
         obuf, xs, ys, qf));
 }
コード例 #10
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeComponentCtxI2(
            PDJPG_Context ctx,
            byte[] rgba, byte[] norm, byte[] spec, byte[] luma, byte[] lebe,
            BytePtr obuf, int xs, int ys, int qf, string tlname, PDJPG_LayerInfo linf)
        {
            byte[] tbuf;
            BytePtr ct;
            int i, j, k, n;

            if (rgba == null) return (-1);

            if (linf != null)
            {
                ctx.bcst_orgx = linf.orgx;
                ctx.bcst_orgy = linf.orgy;
                ctx.bcst_alpha = linf.alpha;
                ctx.bcst_blend = linf.blend;
                ctx.bcst_flags = (uint)linf.flags;

                ctx.bcst_minx = linf.minx;
                ctx.bcst_miny = linf.miny;
                ctx.bcst_maxx = linf.maxx;
                ctx.bcst_maxy = linf.maxy;
            }
            else
            {
                ctx.bcst_orgx = 0;
                ctx.bcst_orgy = 0;
                ctx.bcst_alpha = 255;
                ctx.bcst_blend = 0;
                ctx.bcst_flags = 0;

                ctx.bcst_minx = 0;
                ctx.bcst_miny = 0;
                ctx.bcst_maxx = 0;
                ctx.bcst_maxy = 0;
            }

            n = xs * ys;
            tbuf = new byte[xs * ys * 4];

            ct = obuf;

            //ct.emit(0xFF);
            //ct.emit(JPG.JPG_SOI);

            //ct = PDJPG_EmitMarkerJFIF(ctx, ct);

            if (tlname != null)
            {
                ct = PDJPG_EmitTagLayer(ctx, ct, tlname);
                ct = PDJPG_EmitComponentLayer(ctx, ct, "RGB");
                i = PDJPG_EncodeLDatCtx(ctx, rgba, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }
            else
            {
                ct = PDJPG_EmitComponentLayer(ctx, ct, "RGB");
                //	i=PDJPG_EncodeCtx(ctx, rgba, ct, xs, ys, qf, 0);
                i = PDJPG_EncodeBaseCtx(ctx, rgba, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }
            //	if((ct[-2]==0xFF) && (ct[-2]==JPG_EOI))
            //		{ ct-=2; }

            if (norm != null)
            {
                for (i = 0; i < n; i++)
                {
                    tbuf[i * 4 + 0] = norm[i * 4 + 0];
                    tbuf[i * 4 + 1] = norm[i * 4 + 2];
                    tbuf[i * 4 + 2] = norm[i * 4 + 1];
                    tbuf[i * 4 + 3] = 255;
                }

                ct = PDJPG_EmitComponentLayer(ctx, ct, "XYZ");
                i = PDJPG_EncodeLDatCtx(ctx, tbuf, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }

            if (spec != null)
            {
                ct = PDJPG_EmitComponentLayer(ctx, ct, "SpRGB");
                i = PDJPG_EncodeLDatCtx(ctx, spec, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }

            if ((norm != null) || (spec != null))
            {
                for (i = 0; i < n; i++)
                {
                    j = rgba[i * 4 + 3];
                    tbuf[i * 4 + 0] = (byte)((norm != null) ? norm[i * 4 + 3] : j);
                    tbuf[i * 4 + 1] = rgba[i * 4 + 3];
                    tbuf[i * 4 + 2] = (byte)((spec != null) ? spec[i * 4 + 3] : j);
                    tbuf[i * 4 + 3] = 255;
                }

                ct = PDJPG_EmitComponentLayer(ctx, ct, "DASe");
                i = PDJPG_EncodeLDatCtx(ctx, tbuf, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }
            else
            {
                k = 0;
                for (i = 0; i < n; i++)
                {
                    j = rgba[i * 4 + 3];
                    if (j != 255) k = 1;
                    tbuf[i * 4 + 0] = (byte)j;
                    tbuf[i * 4 + 1] = (byte)j;
                    tbuf[i * 4 + 2] = (byte)j;
                    tbuf[i * 4 + 3] = 255;
                }

                if (k != 0)
                {
                    ct = PDJPG_EmitComponentLayer(ctx, ct, "Alpha");
                    i = PDJPG_EncodeLDatCtx(ctx, tbuf, ct, xs, ys, qf, PDJPG_YYYA);
                    if (i < 0) { return (i); }
                    ct += i;
                }
            }

            if (luma != null)
            {
                ct = PDJPG_EmitComponentLayer(ctx, ct, "LuRGB");
                i = PDJPG_EncodeLDatCtx(ctx, luma, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }

            if (lebe != null)
            {
                ct = PDJPG_EmitComponentLayer(ctx, ct, "LeBe");
                i = PDJPG_EncodeLDatCtx(ctx, lebe, ct, xs, ys, qf, 0);
                if (i < 0) { return (i); }
                ct += i;
            }

            //ct.emit(0xFF);
            //ct.emit(JPG.JPG_EOI);

            //free(tbuf);
            return (ct - obuf);
        }
コード例 #11
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_Encode(
            byte[] ibuf, BytePtr obuf, int xs, int ys, int qf)
        {
            PDJPG_Context ctx;
            int sz;

            ctx = PDJPG_AllocContext();
            sz = PDJPG_EncodeCtx(ctx, ibuf, obuf, xs, ys, qf, 0);
            PDJPG_FreeContext(ctx);
            return (sz);
        }
コード例 #12
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static BytePtr PDJPG_EncodeBeginLayeredCtx(
            PDJPG_Context ctx, BytePtr ct, int xs, int ys, int qf)
        {
            ct.emit(0xFF);
            ct.emit(JPG.JPG_SOI);

            ct = PDJPG_EmitMarkerJFIF(ctx, ct);
            return ct;
        }
コード例 #13
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_ConvertImageYUV(PDJPG_Context ctx,
            BytePtr ibuf, int xs, int ys, int pf,
            int xs2, int ys2, int xs3, int ys3)
        {
            //	void (*getPixel2)(BytePtr rgb,
            //		int *ra, int *ga, int *ba,
            //		int *rb, int *gb, int *bb);
            BytePtr cse;
            ShortPtr ctu, ctv;
            BytePtr cs1, cs2;
            ShortPtr cty1, cty2;

            int cr, cg, cb, ca, cy, cu, cv;

            int cra, cga, cba, caa, cya, cua, cva;
            int crb, cgb, cbb, cab, cyb, cub, cvb;
            int crc, cgc, cbc, cac, cyc, cuc, cvc;
            int crd, cgd, cbd, cad, cyd, cud, cvd;
            int psz, psz2;

            int i, k, l, n;

            if ((pf == PDJPG_RGBA) && (ctx.alphaClr == 0))
            {
                n = (ys + 1) / 2;
                for (i = 0; i < n; i++)
                {
                    k = ((ys - (2 * i + 1)) * xs) * 4;
                    cs1 = ibuf + k; cse = cs1 + xs * 4;
                    l = ((ys - (2 * i + 2)) * xs) * 4;
                    cs2 = ibuf + l;

                    cty1 = new ShortPtr(ctx.yb, (2 * i + 0) * xs2);
                    cty2 = new ShortPtr(ctx.yb, (2 * i + 1) * xs2);

                    l = i * xs3;
                    ctu = new ShortPtr(ctx.ub, l);
                    ctv = new ShortPtr(ctx.vb, l);

                    while (cs1 < cse)
                    {
                        cra = cs1[0]; cga = cs1[1]; cba = cs1[2];
                        crb = cs1[4]; cgb = cs1[5]; cbb = cs1[6];
                        crc = cs2[0]; cgc = cs2[1]; cbc = cs2[2];
                        crd = cs2[4]; cgd = cs2[5]; cbd = cs2[6];

                        cya = 19595 * cra + 38470 * cga + 7471 * cba;
                        cyb = 19595 * crb + 38470 * cgb + 7471 * cbb;
                        cyc = 19595 * crc + 38470 * cgc + 7471 * cbc;
                        cyd = 19595 * crd + 38470 * cgd + 7471 * cbd;
                        cty1.emit(cya >> 16);
                        cty1.emit(cyb >> 16);
                        cty2.emit(cyc >> 16);
                        cty2.emit(cyd >> 16);

                        cr = (cra + crb + crc + crd) >> 2;
                        cg = (cga + cgb + cgc + cgd) >> 2;
                        cb = (cba + cbb + cbc + cbd) >> 2;

                        cu = -11056 * cr - 21712 * cg + 32768 * cb;
                        cv = 32768 * cr - 27440 * cg - 5328 * cb;
                        ctu.emit((cu >> 16) + 128);
                        ctv.emit((cv >> 16) + 128);

                        cs1 += 8; cs2 += 8;
                    }
                }
            }
            else
                if ((pf == PDJPG_RGBA) || (pf == PDJPG_RGB) ||
                    (pf == PDJPG_BGRA) || (pf == PDJPG_BGR))
                {
                    switch (pf)
                    {
                        case PDJPG_RGBA:
                        case PDJPG_BGRA:
                            psz = 4; break;
                        case PDJPG_RGB:
                        case PDJPG_BGR:
                            psz = 3; break;
                        default: psz = 4; break;
                    }
                    psz2 = psz * 2;

                    n = (ys + 1) / 2;
                    for (i = 0; i < n; i++)
                    {
                        k = ((ys - (2 * i + 1)) * xs) * psz;
                        cs1 = ibuf + k; cse = cs1 + xs * psz;
                        l = ((ys - (2 * i + 2)) * xs) * psz;
                        cs2 = ibuf + l;

                        cty1 = new ShortPtr(ctx.yb, (2 * i + 0) * xs2);
                        cty2 = new ShortPtr(ctx.yb, (2 * i + 1) * xs2);

                        l = i * xs3;
                        ctu = new ShortPtr(ctx.ub, l);
                        ctv = new ShortPtr(ctx.vb, l);

                        while (cs1 < cse)
                        {
                            //				getPixel2(cs1, &cra, &cga, &cba, &crb, &cgb, &cbb);
                            //				getPixel2(cs2, &crc, &cgc, &cbc, &crd, &cgd, &cbd);

                            switch (pf)
                            {
                                case PDJPG_RGBA:
                                    cra = cs1[0]; cga = cs1[1]; cba = cs1[2]; caa = cs1[3];
                                    crb = cs1[4]; cgb = cs1[5]; cbb = cs1[6]; cab = cs1[7];
                                    crc = cs2[0]; cgc = cs2[1]; cbc = cs2[2]; cac = cs2[3];
                                    crd = cs2[4]; cgd = cs2[5]; cbd = cs2[6]; cad = cs2[7];
                                    psz = 8; break;
                                case PDJPG_BGRA:
                                    cra = cs1[2]; cga = cs1[1]; cba = cs1[0]; caa = cs1[3];
                                    crb = cs1[6]; cgb = cs1[5]; cbb = cs1[4]; cab = cs1[7];
                                    crc = cs2[2]; cgc = cs2[1]; cbc = cs2[0]; cac = cs2[3];
                                    crd = cs2[6]; cgd = cs2[5]; cbd = cs2[4]; cad = cs2[7];
                                    psz = 8; break;
                                case PDJPG_RGB:
                                    cra = cs1[0]; cga = cs1[1]; cba = cs1[2]; caa = 255;
                                    crb = cs1[3]; cgb = cs1[4]; cbb = cs1[5]; cab = 255;
                                    crc = cs2[0]; cgc = cs2[1]; cbc = cs2[2]; cac = 255;
                                    crd = cs2[3]; cgd = cs2[4]; cbd = cs2[5]; cad = 255;
                                    psz = 6; break;
                                case PDJPG_BGR:
                                    cra = cs1[2]; cga = cs1[1]; cba = cs1[0]; caa = 255;
                                    crb = cs1[5]; cgb = cs1[4]; cbb = cs1[3]; cab = 255;
                                    crc = cs2[2]; cgc = cs2[1]; cbc = cs2[0]; cac = 255;
                                    crd = cs2[5]; cgd = cs2[4]; cbd = cs2[3]; cad = 255;
                                    psz = 6; break;
                                default:
                                    cra = 0; crb = 0; crc = 0; crd = 0;
                                    cga = 0; cgb = 0; cgc = 0; cgd = 0;
                                    cba = 0; cbb = 0; cbc = 0; cbd = 0;
                                    caa = 0; cab = 0; cac = 0; cad = 0;
                                    break;
                            }

                            if (ctx.alphaClr != 0)
                            {
                                ca = (caa + cab + cac + cad) >> 2;
                                if (ca < ctx.alphaClrA)
                                {
                                    cy = ctx.alphaClrY;
                                    cu = ctx.alphaClrU;
                                    cv = ctx.alphaClrV;
                                    cty1.emit(cy); cty1.emit(cy);
                                    cty2.emit(cy); cty2.emit(cy);
                                    ctu.emit(cu); ctv.emit(cv);
                                    continue;
                                }
                            }

                            cya = 19595 * cra + 38470 * cga + 7471 * cba;
                            cyb = 19595 * crb + 38470 * cgb + 7471 * cbb;
                            cyc = 19595 * crc + 38470 * cgc + 7471 * cbc;
                            cyd = 19595 * crd + 38470 * cgd + 7471 * cbd;
                            cty1.emit(cya >> 16);
                            cty1.emit(cyb >> 16);
                            cty2.emit(cyc >> 16);
                            cty2.emit(cyd >> 16);

                            cr = (cra + crb + crc + crd) >> 2;
                            cg = (cga + cgb + cgc + cgd) >> 2;
                            cb = (cba + cbb + cbc + cbd) >> 2;

                            cu = -11056 * cr - 21712 * cg + 32768 * cb;
                            cv = 32768 * cr - 27440 * cg - 5328 * cb;
                            ctu.emit((cu >> 16) + 128);
                            ctv.emit((cv >> 16) + 128);

                            cs1 += psz2; cs2 += psz2;
                        }
                    }
                }
                else
                {
                    switch (pf)
                    {
                        case PDJPG_YUVA: psz = 4; psz2 = 8; break;
                        case PDJPG_YUV: psz = 3; psz2 = 6; break;
                        case PDJPG_YUV422: psz = 2; psz2 = 4; break;
                        case PDJPG_YUV420: psz = 3; psz2 = 3; break;
                        case PDJPG_YA: psz = 2; psz2 = 4; break;
                        case PDJPG_Y: psz = 1; psz2 = 2; break;
                        case PDJPG_YYYA: psz = 4; psz2 = 8; break;
                        default: psz = 4; psz2 = 8; break;
                    }

                    n = (ys + 1) / 2;
                    for (i = 0; i < n; i++)
                    {
                        if (pf == PDJPG_YUV420)
                        {
                            k = (((ys - (2 * i + 1)) * xs2) * psz2) >> 1;
                            cs1 = ibuf + k; cse = cs1 + ((xs * psz2) >> 1);
                            l = (((ys - (2 * i + 2)) * xs2) * psz2) >> 1;
                            cs2 = ibuf + l;
                        }
                        else
                        {
                            k = ((ys - (2 * i + 1)) * xs) * psz;
                            cs1 = ibuf + k; cse = cs1 + xs * psz;
                            l = ((ys - (2 * i + 2)) * xs) * psz;
                            cs2 = ibuf + l;
                        }

                        cty1 = new ShortPtr(ctx.yb, (2 * i + 0) * xs2);
                        cty2 = new ShortPtr(ctx.yb, (2 * i + 1) * xs2);

                        l = i * xs3;
                        ctu = new ShortPtr(ctx.ub, l);
                        ctv = new ShortPtr(ctx.vb, l);

                        while (cs1 < cse)
                        {
                            //				getPixel2(cs1, &cra, &cga, &cba, &crb, &cgb, &cbb);
                            //				getPixel2(cs2, &crc, &cgc, &cbc, &crd, &cgd, &cbd);

                            switch (pf)
                            {
                                case PDJPG_YUVA:
                                    cya = cs1[0]; cua = cs1[1]; cva = cs1[2];
                                    cyb = cs1[4]; cub = cs1[5]; cvb = cs1[6];
                                    cyc = cs2[0]; cuc = cs2[1]; cvc = cs2[2];
                                    cyd = cs2[4]; cud = cs2[5]; cvd = cs2[6];
                                    cu = (cua + cub + cuc + cud) >> 2;
                                    cv = (cva + cvb + cvc + cvd) >> 2;
                                    break;
                                case PDJPG_YUV:
                                    cya = cs1[0]; cua = cs1[1]; cva = cs1[2];
                                    cyb = cs1[3]; cub = cs1[4]; cvb = cs1[5];
                                    cyc = cs2[0]; cuc = cs2[1]; cvc = cs2[2];
                                    cyd = cs2[3]; cud = cs2[4]; cvd = cs2[5];
                                    cu = (cua + cub + cuc + cud) >> 2;
                                    cv = (cva + cvb + cvc + cvd) >> 2;
                                    break;
                                case PDJPG_YUV422:
                                    cya = cs1[0]; cua = cs1[1]; cyb = cs1[2]; cva = cs1[3];
                                    cyc = cs2[0]; cuc = cs2[1]; cyd = cs2[2]; cvc = cs2[3];
                                    cu = (cua + cuc) >> 1; cv = (cva + cvc) >> 1;
                                    break;
                                case PDJPG_YUV420:
                                    cya = cs1[0]; cyb = cs1[1]; cu = cs1[2];
                                    cyc = cs2[0]; cyd = cs2[1]; cv = cs2[2];
                                    break;
                                case PDJPG_YA:
                                    cya = cs1[0]; cyb = cs1[2];
                                    cyc = cs2[0]; cyd = cs2[2];
                                    cu = 0; cv = 0;
                                    break;
                                case PDJPG_Y:
                                    cya = cs1[0]; cyb = cs1[1];
                                    cyc = cs2[0]; cyd = cs2[1];
                                    cu = 0; cv = 0;
                                    break;

                                case PDJPG_YYYA:
                                    cya = cs1[1]; cyb = cs1[5];
                                    cyc = cs2[1]; cyd = cs2[5];
                                    cu = 0; cv = 0;
                                    break;
                                default:
                                    cya = 0; cyb = 0; cyc = 0; cyd = 0;
                                    cua = 0; cub = 0; cuc = 0; cud = 0;
                                    cva = 0; cvb = 0; cvc = 0; cvd = 0;
                                    caa = 0; cab = 0; cac = 0; cad = 0;
                                    cu = 0; cv = 0;
                                    break;
                            }

                            cty1.emit(cya); cty1.emit(cyb);
                            cty2.emit(cyc); cty2.emit(cyd);
                            ctu.emit(cu); ctv.emit(cv);

                            cs1 += psz2; cs2 += psz2;
                        }
                    }
                }
        }
コード例 #14
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static BytePtr PDJPG_EmitMarkerJFIF(PDJPG_Context ctx, BytePtr ct)
        {
            BytePtr ctt;
            int i;

            if (ctx.jpg_clrtrans != PDJPG_CLRS_YCBCR)
                return (ct);

            //ctx.huff.ct = ct; ctx.huff.win = 0; ctx.huff.pos = 0;
            //ctx.huff.InitOutputStream(ctx, ct);

            ct.emit(0xFF);
            ct.emit(JPG.JPG_APP0);
            ctt = ct;
            ct.emit(0x00);
            ct.emit(0x00);
            ct.EmitString("JFIF");
            //PDJPG_WriteString(ctx, "JFIF");

            ct.emit(0x01);		//version high
            ct.emit(0x02);		//version low

            ct.emit(0x00);		//no units

            ct.emit(0x00);		//X density
            ct.emit(0x01);

            ct.emit(0x00);		//Y density
            ct.emit(0x01);

            ct.emit(0x00);		//thumbnail
            ct.emit(0x00);

            //	ctx.huff.WriteString(ctx, name);
            i = ct - ctt;
            ctt[0] = (i >> 8) & 0xFF; ctt[1] = i & 0xFF;
            return (ct);
        }
コード例 #15
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeCtx_MegablockInner(
            PDJPG_Context ctx, BytePtr obuf, int xs, int ys, int qfl)
        {
            //	static BytePtr yb=null, *ub, *vb;
            //	static short *ydb=null, *udb, *vdb;
            //	static int lxs=0, lys=0;

            IntPtr dcs = new IntPtr(256);
            IntPtr acs = new IntPtr(256);
            IntPtr dcsuv = new IntPtr(256);
            IntPtr acsuv = new IntPtr(256);
            ShortPtr tp;
            int xs2, ys2, xs3, ys3, qf;
            //	int cr, cg, cb, cy, cu, cv;
            int i, j, k, l;

            qf = qfl & 255;

            xs2 = ctx.xs2;
            ys2 = ctx.ys2;
            xs3 = ctx.xs3;
            ys3 = ctx.ys3;

            //	printf("M1\n");

            //	if(qf==110)
            if (ctx.jpg_rdct)
            {
                //		printf("PDJPG_EncodeCtx: Lossless Detect\n");

                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.yb), new ShortPtr(ctx.ydb), xs2, ys2, 128);
                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.ub), new ShortPtr(ctx.udb), xs3, ys3, 128);
                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.vb), new ShortPtr(ctx.vdb), xs3, ys3, 128);
            }
            else
            {
                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.yb), new ShortPtr(ctx.ydb), xs2, ys2, 128);
                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.ub), new ShortPtr(ctx.udb), xs3, ys3, 128);
                PDJPG_FilterImageMegablockRDCT(new ShortPtr(ctx.vb), new ShortPtr(ctx.vdb), xs3, ys3, 128);

                //PDJPG_FilterImageDCT(new ShortPtr(ctx.yb), new ShortPtr(ctx.ydb), xs2, ys2, 128);
                //PDJPG_FilterImageDCT(new ShortPtr(ctx.ub), new ShortPtr(ctx.udb), xs3, ys3, 128);
                //PDJPG_FilterImageDCT(new ShortPtr(ctx.vb), new ShortPtr(ctx.vdb), xs3, ys3, 128);
            }

            j = (xs2 / 64) * (ys2 / 64);
            PDJPG_MakeMegaQuantTabInputY(ctx.ydb, j, new BytePtr(ctx.jpg_qt, 0 * 256), qf / 100.0);

            j = (xs3 / 64) * (ys3 / 64);
            PDJPG_MakeMegaQuantTabInputUV(ctx.udb, j, new BytePtr(ctx.jpg_qt, 1 * 256), qf / 100.0);
            PDJPG_MakeMegaQuantTabInputUV(ctx.vdb, j, new BytePtr(ctx.jpg_qt, 2 * 256), qf / 100.0);
            for (i = 0; i < 128; i++) ctx.jpg_qt[1 * 256 + i] = (byte)((ctx.jpg_qt[1 * 256 + i] + ctx.jpg_qt[2 * 256 + i]) / 2);

            PDJPG_SetupQuantTabDivFP(ctx, 0);
            PDJPG_SetupQuantTabDivFP(ctx, 1);

            //	free(yb);
            //	free(ub);
            //	free(vb);

            if (ctx.jpg_mono || !ctx.jpg_is420)
            {
                j = (xs2 / 64) * (ys2 / 64); k = 0;
                for (i = 0; i < j; i++)
                {
                    ctx.block.QuantMegaBlock(ctx, new ShortPtr(ctx.ydb, i * 4096), new ShortPtr(ctx.ydb, i * 4096), 0);
                    ctx.ydb[i * 4096 + 0] -= (short)k; k = ctx.ydb[i * 4096 + 0] + k;
                }
            }

            if (!ctx.jpg_mono && ctx.jpg_is420)
            {
                l = 0;
                for (i = 0; i <= (ys3 / 64); i++)
                    for (j = 0; j < (xs3 / 64); j++)
                    {
                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 64) + j * 2 + 0) * 4096);
                        ctx.block.QuantMegaBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 64) + j * 2 + 1) * 4096);
                        ctx.block.QuantMegaBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 64) + j * 2 + 0) * 4096);
                        ctx.block.QuantMegaBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 64) + j * 2 + 1) * 4096);
                        ctx.block.QuantMegaBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;
                    }
            }

            j = (xs3 / 64) * (ys3 / 64); k = 0; l = 0;
            for (i = 0; i < j; i++)
            {
                ctx.block.QuantMegaBlock(ctx, new ShortPtr(ctx.udb, i * 4096), new ShortPtr(ctx.udb, i * 4096), 1);
                ctx.block.QuantMegaBlock(ctx, new ShortPtr(ctx.vdb, i * 4096), new ShortPtr(ctx.vdb, i * 4096), 1);
                ctx.udb[i * 4096 + 0] -= (short)k; k = ctx.udb[i * 4096 + 0] + k;
                ctx.vdb[i * 4096 + 0] -= (short)l; l = ctx.vdb[i * 4096 + 0] + l;
            }

            if (ctx.jpg_yuvw)
            {
                j = (xs3 / 64) * (ys3 / 64); k = 0;
                for (i = 0; i < j; i++)
                {
                    ctx.block.QuantMegaBlock(ctx, new ShortPtr(ctx.wdb, i * 4096), new ShortPtr(ctx.wdb, i * 4096), 1);
                    ctx.wdb[i * 4096 + 0] -= (short)k; k = ctx.wdb[i * 4096 + 0] + k;
                }
            }

            //	printf("M2\n");

            for (i = 0; i < 256; i++) dcs[i] = 0;
            for (i = 0; i < 256; i++) acs[i] = 0;
            for (i = 0; i < 256; i++) dcsuv[i] = 0;
            for (i = 0; i < 256; i++) acsuv[i] = 0;

            j = (xs2 / 64) * (ys2 / 64);
            k = (xs3 / 64) * (ys3 / 64);
            for (i = 0; i < j; i++) ctx.block.StatMegaBlock(new ShortPtr(ctx.ydb, i * 4096), dcs, acs);
            for (i = 0; i < k; i++) ctx.block.StatMegaBlock(new ShortPtr(ctx.udb, i * 4096), dcsuv, acsuv);
            for (i = 0; i < k; i++) ctx.block.StatMegaBlock(new ShortPtr(ctx.vdb, i * 4096), dcsuv, acsuv);

            if (ctx.jpg_yuvw)
            { for (i = 0; i < k; i++)ctx.block.StatMegaBlock(new ShortPtr(ctx.wdb, i * 4096), dcsuv, acsuv); }

            //	ctx.huff.BuildLengths(dcs, 256, ctx.huff.len+0*256, 16);
            //	ctx.huff.BuildLengths(acs, 256, ctx.huff.len+1*256, 16);
            //	ctx.huff.BuildLengths(dcsuv, 256, ctx.huff.len+2*256, 16);
            //	ctx.huff.BuildLengths(acsuv, 256, ctx.huff.len+3*256, 16);

            //ctx.huff.BuildLengthsAdjust(dcs, 256, new BytePtr(ctx.huff.len, 0 * 256), 16);
            //ctx.huff.BuildLengthsAdjust(acs, 256, new BytePtr(ctx.huff.len, 1 * 256), 16);
            //ctx.huff.BuildLengthsAdjust(dcsuv, 256, new BytePtr(ctx.huff.len, 2 * 256), 16);
            //ctx.huff.BuildLengthsAdjust(acsuv, 256, new BytePtr(ctx.huff.len, 3 * 256), 16);

            ctx.huff.BuildTable(dcs, 0);
            ctx.huff.BuildTable(acs, 1);
            ctx.huff.BuildTable(dcsuv, 2);
            ctx.huff.BuildTable(acsuv, 3);

            //ctx.huff.ct = obuf;
            //ctx.huff.win = 0;
            //ctx.huff.pos = 0;
            ctx.huff.InitOutputStream(ctx, obuf);

            if ((qfl & PDJPG_QFL_NOSOI) == 0)
            {
                ctx.huff.ct.emit(0xFF);
                ctx.huff.ct.emit(JPG.JPG_SOI);
            }

            PDJPG_EmitMarkerBCST(ctx);

            PDJPG_EmitDQT(ctx, 0);
            if (!ctx.jpg_mono) PDJPG_EmitDQT(ctx, 1);

            PDJPG_EmitSOF(ctx, xs, ys);

            ctx.huff.EmitDHT(ctx, 0);
            ctx.huff.EmitDHT(ctx, 1);
            if (!ctx.jpg_mono)
            {
                ctx.huff.EmitDHT(ctx, 2);
                ctx.huff.EmitDHT(ctx, 3);
            }

            PDJPG_EmitSOS(ctx);

            ctx.huff.InitOutputStream(ctx, ctx.huff.ct);

            //ctx.huff.win = 0;
            //ctx.huff.pos = 0;

            if (ctx.jpg_mono)
            {
                j = (xs2 / 64) * (ys2 / 64);
                for (i = 0; i < j; i++) ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.ydb, i * 4096), 0, 1);
            }
            else if (ctx.jpg_is420)
            {
                for (i = 0; i <= (ys3 / 64); i++)
                    for (j = 0; j < (xs3 / 64); j++)
                    {
                        ctx.block.EncodeMegaBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 64) + j * 2 + 0) * 4096), 0, 1);
                        ctx.block.EncodeMegaBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 64) + j * 2 + 1) * 4096), 0, 1);
                        ctx.block.EncodeMegaBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 64) + j * 2 + 0) * 4096), 0, 1);
                        ctx.block.EncodeMegaBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 64) + j * 2 + 1) * 4096), 0, 1);

                        k = i * (xs3 / 64) + j;
                        ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.udb, k * 4096), 2, 3);
                        ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.vdb, k * 4096), 2, 3);
                        if (ctx.jpg_yuvw)
                        { ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.wdb, k * 4096), 2, 3); }
                    }
            }
            else
            {
                j = (xs2 / 64) * (ys2 / 64);
                for (i = 0; i < j; i++)
                {
                    ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.ydb, i * 4096), 0, 1);
                    ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.udb, i * 4096), 2, 3);
                    ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.vdb, i * 4096), 2, 3);
                    if (ctx.jpg_yuvw)
                    { ctx.block.EncodeMegaBlock(ctx, new ShortPtr(ctx.wdb, i * 4096), 2, 3); }
                }
            }

            ctx.huff.FlushBits(ctx);

            if ((qfl & PDJPG_QFL_NOSOI) == 0)
            {
                ctx.huff.ct.emit(0xFF);
                ctx.huff.ct.emit(JPG.JPG_EOI);
            }

            //	printf("M3\n");

            i = ctx.huff.ct - obuf;

            return (i);
        }
コード例 #16
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeFastCtx(PDJPG_Context ctx,
            BytePtr ibuf, BytePtr obuf, int xs, int ys, int qf, int pf)
        {
            char[] tb = new char[256];
            ShortPtr tp;
            int xs2, ys2, xs3, ys3;
            BytePtr ctt;

            int i, j, k, l;

            xs2 = ((xs + 7) / 8) * 8;
            ys2 = ((ys + 7) / 8) * 8;
            xs3 = ((xs + 15) / 16) * 8;
            ys3 = ((ys + 15) / 16) * 8;

            ctx.jpg_mono = ctx.huff.;

            if (ctx.jpg_tabcacheframe == 0)
            {
                //full quality
                for (i = 0; i < 64; i++) ctx.jpg_qt[0 * 64 + i] = 1;
                for (i = 0; i < 64; i++) ctx.jpg_qt[1 * 64 + i] = 1;
            }

            if ((ctx.yb == null) || (xs != ctx.lxs) || (ys != ctx.lys))
            {
            #if false
            if(ctx.yb)
            {
            free(ctx.yb);
            free(ctx.ub);
            free(ctx.vb);
            free(ctx.ydb);
            free(ctx.udb);
            free(ctx.vdb);
            }
            #endif

                ctx.yb = new short[xs2 * ys2];
                ctx.ub = new short[xs2 * ys2];
                ctx.vb = new short[xs2 * ys2];

                ctx.ydb = new short[(xs2 + 8) * (ys2 + 16)];
                ctx.udb = new short[(xs3 + 8) * (ys3 + 8)];
                ctx.vdb = new short[(xs3 + 8) * (ys3 + 8)];

                ctx.lxs = xs;
                ctx.lys = ys;

                ShortPtr.memset(ctx.yb, 128, xs2 * ys2);
                ShortPtr.memset(ctx.ub, 128, xs2 * ys2);
                ShortPtr.memset(ctx.vb, 128, xs2 * ys2);

                ShortPtr.memset(ctx.ydb, 0, xs2 * (ys2 + 8));
                ShortPtr.memset(ctx.udb, 0, xs3 * (ys3 + 8));
                ShortPtr.memset(ctx.vdb, 0, xs3 * (ys3 + 8));

                ctx.jpg_tabcacheframe = 0;	//force rebuild
            }

            PDJPG_ConvertImageYUV(ctx,
                ibuf, xs, ys, pf,
                xs2, ys2, xs3, ys3);

            PDJPG_FilterImageDCT(new ShortPtr(ctx.yb), new ShortPtr(ctx.ydb), xs2, ys2, 128);
            PDJPG_FilterImageDCT(new ShortPtr(ctx.ub), new ShortPtr(ctx.udb), xs3, ys3, 128);
            PDJPG_FilterImageDCT(new ShortPtr(ctx.vb), new ShortPtr(ctx.vdb), xs3, ys3, 128);

            if (ctx.jpg_tabcacheframe <= 0)
            {
                j = (xs2 / 8) * (ys2 / 8);
                PDJPG_MakeQuantTabInputFast(ctx.ydb, j, new BytePtr(ctx.jpg_qt, 0 * 64), qf / 100.0);

                j = (xs3 / 8) * (ys3 / 8);
                PDJPG_MakeQuantTabInputFast(ctx.udb, j, new BytePtr(ctx.jpg_qt, 1 * 64), qf / 100.0);
                PDJPG_MakeQuantTabInputFast(ctx.vdb, j, new BytePtr(ctx.jpg_qt, 2 * 64), qf / 100.0);
                for (i = 0; i < 64; i++)
                    ctx.jpg_qt[1 * 64 + i] = (byte)((ctx.jpg_qt[1 * 64 + i] + ctx.jpg_qt[2 * 64 + i]) / 2);

                PDJPG_SetupQuantTabDivFP(ctx, 0);
                PDJPG_SetupQuantTabDivFP(ctx, 1);
            }

            if (ctx.jpg_mono)
            {
                j = (xs2 / 8) * (ys2 / 8); k = 0;
                for (i = 0; i < j; i++)
                {
                    ctx.huff.QuantBlock(ctx, new ShortPtr(ctx.ydb, i * 64), new ShortPtr(ctx.ydb, i * 64), 0);
                    ctx.ydb[i * 64 + 0] -= (short)k;
                    k = ctx.ydb[i * 64 + 0] + k;
                }
            }

            if (!ctx.jpg_mono)
            {
                l = 0;
                for (i = 0; i <= (ys3 / 8); i++)
                    for (j = 0; j < (xs3 / 8); j++)
                    {
                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 8) + j * 2 + 0) * 64);
                        ctx.huff.QuantBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 8) + j * 2 + 1) * 64);
                        ctx.huff.QuantBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 8) + j * 2 + 0) * 64);
                        ctx.huff.QuantBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;

                        tp = new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 8) + j * 2 + 1) * 64);
                        ctx.huff.QuantBlock(ctx, tp, tp, 0);
                        tp[0] -= l; l = tp[0] + l;
                    }
            }

            j = (xs3 / 8) * (ys3 / 8); k = 0; l = 0;
            for (i = 0; i < j; i++)
            {
                ctx.huff.QuantBlock(ctx, new ShortPtr(ctx.udb, i * 64), new ShortPtr(ctx.udb, i * 64), 1);
                ctx.huff.QuantBlock(ctx, new ShortPtr(ctx.vdb, i * 64), new ShortPtr(ctx.vdb, i * 64), 1);
                ctx.udb[i * 64 + 0] -= (short)k; k = ctx.udb[i * 64 + 0] + k;
                ctx.vdb[i * 64 + 0] -= (short)l; l = ctx.vdb[i * 64 + 0] + l;
            }

            //	printf("M2\n");

            if (ctx.jpg_tabcacheframe <= 0)
            {
                for (i = 0; i < 256; i++) ctx.dcs[i] = 1;
                for (i = 0; i < 256; i++) ctx.acs[i] = 1;
                for (i = 0; i < 256; i++) ctx.dcsuv[i] = 1;
                for (i = 0; i < 256; i++) ctx.acsuv[i] = 1;

                j = (xs2 / 8) * (ys2 / 8);
                k = (xs3 / 8) * (ys3 / 8);
                for (i = 0; i < j; i++)
                    ctx.huff.StatBlock(new ShortPtr(ctx.ydb, i * 64), new IntPtr(ctx.dcs), new IntPtr(ctx.acs));
                for (i = 0; i < k; i++)
                    ctx.huff.StatBlock(new ShortPtr(ctx.udb, i * 64), new IntPtr(ctx.dcsuv), new IntPtr(ctx.acsuv));
                for (i = 0; i < k; i++)
                    ctx.huff.StatBlock(new ShortPtr(ctx.vdb, i * 64), new IntPtr(ctx.dcsuv), new IntPtr(ctx.acsuv));

                //		ctx.huff.BuildLengths(ctx.dcs, 256, ctx.huff.len+0*256, 16);
                //		ctx.huff.BuildLengths(ctx.acs, 256, ctx.huff.len+1*256, 16);
                //		ctx.huff.BuildLengths(ctx.dcsuv, 256, ctx.huff.len+2*256, 16);
                //		ctx.huff.BuildLengths(ctx.acsuv, 256, ctx.huff.len+3*256, 16);

                ctx.huff.BuildLengthsAdjust(
                    new IntPtr(ctx.dcs), 256, new BytePtr(ctx.huff.len, 0 * 256), 16);
                ctx.huff.BuildLengthsAdjust(
                    new IntPtr(ctx.acs), 256, new BytePtr(ctx.huff.len, 1 * 256), 16);
                ctx.huff.BuildLengthsAdjust(
                    new IntPtr(ctx.dcsuv), 256, new BytePtr(ctx.huff.len, 2 * 256), 16);
                ctx.huff.BuildLengthsAdjust(
                    new IntPtr(ctx.acsuv), 256, new BytePtr(ctx.huff.len, 3 * 256), 16);
            }

            ctx.huff.ct = obuf;
            ctx.huff.win = 0;
            ctx.huff.pos = 0;

            ctx.huff.ct.emit(0xFF);
            ctx.huff.ct.emit(JPG.JPG_SOI);

            if ((ctx.alphaClr != 0) && (ctx.alphaClr != ctx.oldAlphaClr))
            {
                //		sprintf_s(tb, "%d %d %d %d",
                //			(ctx.alphaClr&0xFF),
                //			((ctx.alphaClr>>8)&0xFF),
                //			((ctx.alphaClr>>16)&0xFF),
                //			((ctx.alphaClr>>24)&0xFF));

                ctx.huff.ct.emit(0xFF);
                ctx.huff.ct.emit(JPG.JPG_APP11);
                ctt = ctx.huff.ct;
                ctx.huff.ct.emit(0x00);
                ctx.huff.ct.emit(0x00);
                ctx.huff.WriteString(ctx, "AlphaColor");
                //		ctx.huff.WriteString(ctx, tb);
                ctx.huff.WriteString(ctx, "");
                i = (ctx.huff.ct - ctt);
                ctt[0] = (i >> 8) & 0xFF; ctt[1] = i & 0xFF;
            }

            if (ctx.jpg_tabcacheframe <= 0)
            {
                PDJPG_EmitDQT(ctx, 0);
                if (!ctx.jpg_mono) PDJPG_EmitDQT(ctx, 1);
            }

            PDJPG_EmitSOF(ctx, xs, ys);

            //	if(ctx.jpg_tabcacheframe<=0)
            if (true)
            {
                ctx.huff.EmitDHT(ctx, 0);
                ctx.huff.EmitDHT(ctx, 1);
                if (!ctx.jpg_mono)
                {
                    ctx.huff.EmitDHT(ctx, 2);
                    ctx.huff.EmitDHT(ctx, 3);
                }
            }

            PDJPG_EmitSOS(ctx);

            ctx.huff.win = 0;
            ctx.huff.pos = 0;

            if (ctx.jpg_mono)
            {
                j = (xs2 / 8) * (ys2 / 8);
                for (i = 0; i < j; i++) ctx.huff.EncodeBlock(ctx, new ShortPtr(ctx.ydb, i * 64), 0, 1);
            }
            else
            {
                for (i = 0; i <= ((ys3) / 8); i++)
                    for (j = 0; j < (xs3 / 8); j++)
                    {
                        ctx.huff.EncodeBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 8) + j * 2 + 0) * 64), 0, 1);
                        ctx.huff.EncodeBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 0) * (xs2 / 8) + j * 2 + 1) * 64), 0, 1);
                        ctx.huff.EncodeBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 8) + j * 2 + 0) * 64), 0, 1);
                        ctx.huff.EncodeBlock(ctx,
                            new ShortPtr(ctx.ydb, ((i * 2 + 1) * (xs2 / 8) + j * 2 + 1) * 64), 0, 1);

                        k = i * (xs3 / 8) + j;
                        ctx.huff.EncodeBlock(ctx, new ShortPtr(ctx.udb, k * 64), 2, 3);
                        ctx.huff.EncodeBlock(ctx, new ShortPtr(ctx.vdb, k * 64), 2, 3);
                    }
            }

            ctx.huff.FlushBits(ctx);

            ctx.huff.ct.emit(0xFF);
            ctx.huff.ct.emit(JPG.JPG_EOI);

            if (ctx.jpg_tabcacheframe <= 0)
            {
                //		ctx.jpg_tabcacheframe=16;
                ctx.jpg_tabcacheframe = 8;
            }
            else
            {
                ctx.jpg_tabcacheframe--;
            }

            //	printf("M3\n");

            i = ctx.huff.ct - obuf;

            return (i);
        }
コード例 #17
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public static void bvalue(Object_ o, BytePtr b)
 {
     o.value.b = (b != null ? new BytePtr(b) : null);
 }
コード例 #18
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public static void s_bvalue(int i, BytePtr ptr)
 {
     bvalue(s_object(i), ptr);
 }
コード例 #19
0
ファイル: opcode.c.cs プロジェクト: weimingtom/KopiLuaCompare
        /*
        ** Execute the given opcode, until a RET. Parameters are between
        ** [stack+base,top). Returns n such that the the results are between
        ** [stack+n,top).
        */
        private static StkId lua_execute(BytePtr pc, StkId @base)
        {
            //pc = new BytePtr(pc);
            lua_checkstack(STACKGAP + MAX_TEMPS + @base);
            while (true)
            {
#if MY_DEBUG
                //printf(">>> %d,", ObjectRef.minus(top, stack));
#endif
                OpCode opcode;
                opcode = (OpCode)pc[0]; pc.inc();
                switch (opcode)
                {
                case OpCode.PUSHNIL: tag(top.get(), lua_Type.LUA_T_NIL); top.inc(); break;

                case OpCode.PUSH0:
                case OpCode.PUSH1:
                case OpCode.PUSH2:
                    tag(top.get(), lua_Type.LUA_T_NUMBER);
                    nvalue(top.get(), opcode - OpCode.PUSH0); top.inc();
                    break;

                case OpCode.PUSHBYTE: tag(top.get(), lua_Type.LUA_T_NUMBER); nvalue(top.get(), pc[0]); top.inc(); pc.inc(); break;

                case OpCode.PUSHWORD:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    tag(top.get(), lua_Type.LUA_T_NUMBER); nvalue(top.get(), code.w); top.inc();
                }
                break;

                case OpCode.PUSHFLOAT:
                {
                    CodeFloat code = new CodeFloat();
                    get_float(code, pc);
                    tag(top.get(), lua_Type.LUA_T_NUMBER); nvalue(top.get(), code.f); top.inc();
                }
                break;

                case OpCode.PUSHSTRING:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    tag(top.get(), lua_Type.LUA_T_STRING); tsvalue(top.get(), lua_constant[code.w]); top.inc();
                }
                break;

                case OpCode.PUSHFUNCTION:
                {
                    CodeCode code = new CodeCode();
                    get_code(code, pc);
                    tag(top.get(), lua_Type.LUA_T_FUNCTION); bvalue(top.get(), new BytePtr(code.b, 0)); top.inc();
                }
                break;

                case OpCode.PUSHLOCAL0:
                case OpCode.PUSHLOCAL1:
                case OpCode.PUSHLOCAL2:
                case OpCode.PUSHLOCAL3:
                case OpCode.PUSHLOCAL4:
                case OpCode.PUSHLOCAL5:
                case OpCode.PUSHLOCAL6:
                case OpCode.PUSHLOCAL7:
                case OpCode.PUSHLOCAL8:
                case OpCode.PUSHLOCAL9: top.get().set(stack[(@base) + (int)(opcode - OpCode.PUSHLOCAL0)]); top.inc(); break;

                case OpCode.PUSHLOCAL: top.get().set(stack[(@base) + pc[0]]); top.inc(); pc.inc(); break;

                case OpCode.PUSHGLOBAL:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.get().set(s_object(code.w)); top.inc();
                }
                break;

                case OpCode.PUSHINDEXED:
                    pushsubscript();
                    break;

                case OpCode.PUSHSELF:
                {
                    Object_  receiver = top.get(-1);
                    CodeWord code     = new CodeWord();
                    get_word(code, pc);
                    tag(top.get(), lua_Type.LUA_T_STRING); tsvalue(top.get(), lua_constant[code.w]); top.inc();
                    pushsubscript();
                    top.get().set(receiver); top.inc();
                    break;
                }

                case OpCode.STORELOCAL0:
                case OpCode.STORELOCAL1:
                case OpCode.STORELOCAL2:
                case OpCode.STORELOCAL3:
                case OpCode.STORELOCAL4:
                case OpCode.STORELOCAL5:
                case OpCode.STORELOCAL6:
                case OpCode.STORELOCAL7:
                case OpCode.STORELOCAL8:
                case OpCode.STORELOCAL9:
                    top.dec();
                    stack[(@base) + (int)(opcode - OpCode.STORELOCAL0)].set(top.get());
                    break;

                case OpCode.STORELOCAL: top.dec(); stack[(@base) + pc[0]].set(top.get()); pc.inc(); break;

                case OpCode.STOREGLOBAL:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    s_object(code.w, top.get(0));
                }
                break;

                case OpCode.STOREINDEXED0:
                    storesubscript();
                    break;

                case OpCode.STOREINDEXED:
                {
                    int n = pc[0]; pc.inc();
                    if (tag(top.get(-3 - n)) != lua_Type.LUA_T_ARRAY)
                    {
                        top.get(+1).set(top.get(-1));
                        top.get().set(top.get(-2 - n));
                        top.get(-1).set(top.get(-3 - n));
                        top.add(2);
                        do_call(luaI_fallBacks[FB_SETTABLE].function, ObjectRef.minus(top, stack) - 3, 0, ObjectRef.minus(top, stack) - 3);
                    }
                    else
                    {
                        Object_ h = lua_hashdefine(avalue(top.get(-3 - n)), top.get(-2 - n));
                        h.set(top.get(-1));
                        top.dec();
                    }
                }
                break;

                case OpCode.STORELIST0:
                case OpCode.STORELIST:
                {
                    int     m, n;
                    Object_ arr;
                    if (opcode == OpCode.STORELIST0)
                    {
                        m = 0;
                    }
                    else
                    {
                        m = pc[0] * FIELDS_PER_FLUSH; pc.inc();
                    }
                    n   = pc[0]; pc.inc();
                    arr = top.get(-n - 1);
                    while (n != 0)
                    {
                        tag(top.get(), lua_Type.LUA_T_NUMBER); nvalue(top.get(), n + m);
                        lua_hashdefine(avalue(arr), top.get()).set(top.get(-1));
                        top.dec();
                        n--;
                    }
                }
                break;

                case OpCode.STORERECORD:
                {
                    int     n   = pc[0]; pc.inc();
                    Object_ arr = top.get(-n - 1);
                    while (n != 0)
                    {
                        CodeWord code = new CodeWord();
                        get_word(code, pc);
                        tag(top.get(), lua_Type.LUA_T_STRING); tsvalue(top.get(), lua_constant[code.w]);
                        lua_hashdefine(avalue(arr), top.get()).set(top.get(-1));
                        top.dec();
                        n--;
                    }
                }
                break;

                case OpCode.ADJUST0:
                    adjust_top(@base);
                    break;

                case OpCode.ADJUST:
                    adjust_top(@base + pc[0]); pc.inc();
                    break;

                case OpCode.CREATEARRAY:
                {
                    CodeWord size = new CodeWord();
                    get_word(size, pc);
                    avalue(top.get(), lua_createarray(size.w));
                    tag(top.get(), lua_Type.LUA_T_ARRAY);
                    top.inc();
                }
                break;

                case OpCode.EQOP:
                {
                    int res = lua_equalObj(top.get(-2), top.get(-1));
                    top.dec();
                    tag(top.get(-1), res != 0 ? lua_Type.LUA_T_NUMBER : lua_Type.LUA_T_NIL);
                    nvalue(top.get(-1), 1);
                }
                break;

                case OpCode.LTOP:
                    comparison(lua_Type.LUA_T_NUMBER, lua_Type.LUA_T_NIL, lua_Type.LUA_T_NIL, "lt");
                    break;

                case OpCode.LEOP:
                    comparison(lua_Type.LUA_T_NUMBER, lua_Type.LUA_T_NUMBER, lua_Type.LUA_T_NIL, "le");
                    break;

                case OpCode.GTOP:
                    comparison(lua_Type.LUA_T_NIL, lua_Type.LUA_T_NIL, lua_Type.LUA_T_NUMBER, "gt");
                    break;

                case OpCode.GEOP:
                    comparison(lua_Type.LUA_T_NIL, lua_Type.LUA_T_NUMBER, lua_Type.LUA_T_NUMBER, "ge");
                    break;

                case OpCode.ADDOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        call_arith("add");
                    }
                    else
                    {
                        nvalue(l, nvalue(l) + nvalue(r));
                        top.dec();
                    }
                }
                break;

                case OpCode.SUBOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        call_arith("sub");
                    }
                    else
                    {
                        nvalue(l, nvalue(l) - nvalue(r));
                        top.dec();
                    }
                }
                break;

                case OpCode.MULTOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        call_arith("mul");
                    }
                    else
                    {
                        nvalue(l, nvalue(l) * nvalue(r));
                        top.dec();
                    }
                }
                break;

                case OpCode.DIVOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        call_arith("div");
                    }
                    else
                    {
                        nvalue(l, nvalue(l) / nvalue(r));
                        top.dec();
                    }
                }
                break;

                case OpCode.POWOP:
                    call_arith("pow");
                    break;

                case OpCode.CONCOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tostring(r) || tostring(l))
                    {
                        do_call(luaI_fallBacks[FB_CONCAT].function, ObjectRef.minus(top, stack) - 2, 1, ObjectRef.minus(top, stack) - 2);
                    }
                    else
                    {
                        tsvalue(l, lua_createstring(lua_strconc(svalue(l), svalue(r))));
                        top.dec();
                    }
                }
                break;

                case OpCode.MINUSOP:
                    if (tonumber(top.get(-1)))
                    {
                        tag(top.get(), lua_Type.LUA_T_NIL); top.inc();
                        call_arith("unm");
                    }
                    else
                    {
                        nvalue(top.get(-1), -nvalue(top.get(-1)));
                    }
                    break;

                case OpCode.NOTOP:
                    tag(top.get(-1), (tag(top.get(-1)) == lua_Type.LUA_T_NIL) ? lua_Type.LUA_T_NUMBER : lua_Type.LUA_T_NIL);
                    nvalue(top.get(-1), 1);
                    break;

                case OpCode.ONTJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    if (tag(top.get(-1)) != lua_Type.LUA_T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.ONFJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    if (tag(top.get(-1)) == lua_Type.LUA_T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.JMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    pc += code.w;
                }
                break;

                case OpCode.UPJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    pc -= code.w;
                }
                break;

                case OpCode.IFFJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    if (tag(top.get()) == lua_Type.LUA_T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.IFFUPJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    if (tag(top.get()) == lua_Type.LUA_T_NIL)
                    {
                        pc -= code.w;
                    }
                }
                break;

                case OpCode.POP: top.dec(); break;

                case OpCode.CALLFUNC:
                {
                    int     nParams  = pc[0]; pc.inc();
                    int     nResults = pc[0]; pc.inc();
                    Object_ func     = top.get(-1 - nParams);                               /* function is below parameters */
                    StkId   newBase  = ObjectRef.minus(top, stack) - nParams;
                    do_call(func, newBase, nResults, newBase - 1);
                }
                break;

                case OpCode.RETCODE0:
                    return(@base);

                case OpCode.RETCODE:
                    return(@base + pc[0]);

                case OpCode.SETFUNCTION:
                {
                    CodeCode file = new CodeCode();
                    CodeWord func = new CodeWord();
                    get_code(file, pc);
                    get_word(func, pc);
                    lua_pushfunction(new CharPtr(file.b), func.w);
                }
                break;

                case OpCode.SETLINE:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    lua_debugline = code.w;
                }
                break;

                case OpCode.RESET:
                    lua_popfunction();
                    break;

                default:
                    lua_error("internal error - opcode doesn't match");
                    break;
                }
            }
        }
コード例 #20
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public static void get_word(CodeWord code, BytePtr pc)
 {
     code.m.c1 = (Byte)pc[0]; pc.inc(); code.m.c2 = (Byte)pc[0]; pc.inc();
 }
コード例 #21
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public static void get_float(CodeFloat code, BytePtr pc)
 {
     code.m.c1 = (Byte)pc[0]; pc.inc(); code.m.c2 = (Byte)pc[0]; pc.inc();
     code.m.c3 = (Byte)pc[0]; pc.inc(); code.m.c4 = (Byte)pc[0]; pc.inc();
 }
コード例 #22
0
ファイル: opcode.h.cs プロジェクト: weimingtom/KopiLuaCompare
 public static void get_code(CodeCode code, BytePtr pc)
 {
     code.m.c1 = (Byte)pc[0]; pc.inc(); code.m.c2 = (Byte)pc[0]; pc.inc();
     code.m.c3 = (Byte)pc[0]; pc.inc(); code.m.c4 = (Byte)pc[0]; pc.inc();
 }
コード例 #23
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeFloatComponentCtx(PDJPG_Context ctx,
            float[] rgba, float[] norm, float[] spec, float[] luma,
            BytePtr obuf, int xs, int ys, int qf)
        {
            byte[] trgba, tnorm, tspec, tluma, tlebe;
            int i, j, n;
            double f;

            n = xs * ys;
            if (ctx.imgbuf_rgba == null)
                ctx.imgbuf_rgba = new byte[4 * n];
            if (ctx.imgbuf_norm == null)
                ctx.imgbuf_norm = new byte[4 * n];
            if (ctx.imgbuf_spec == null)
                ctx.imgbuf_spec = new byte[4 * n];
            if (ctx.imgbuf_luma == null)
                ctx.imgbuf_luma = new byte[4 * n];

            if (ctx.imgbuf_lebe == null)
            {
                ctx.imgbuf_lebe = new byte[4 * n];
                BytePtr.memset(ctx.imgbuf_lebe, 192, 4 * n);
            }

            trgba = ctx.imgbuf_rgba;
            tnorm = ctx.imgbuf_norm;
            tspec = ctx.imgbuf_spec;
            tluma = ctx.imgbuf_luma;
            tlebe = ctx.imgbuf_lebe;

            if (rgba != null)
            {
                for (i = 0; i < n; i++)
                {
                    PDJPG_EncodeFloatPixel(new FloatPtr(rgba, i * 4), new BytePtr(trgba, i * 4), new BytePtr(tlebe, i * 4 + 0));
                }
            }

            if (norm != null)
            {
                for (i = 0; i < n; i++)
                {
                    //			f=(1.0/256)*pdjpg_scltab[tlebe[i*4+0]];
                    j = PDJPG_CalcComponentValueExponent(norm[i * 4 + 3]);
                    f = 255 / pdjpg_scltab[j];
                    tnorm[i * 4 + 0] = (byte)(norm[i * 4 + 0] * 255);
                    tnorm[i * 4 + 1] = (byte)(norm[i * 4 + 1] * 255);
                    tnorm[i * 4 + 2] = (byte)(norm[i * 4 + 2] * 255);
                    tnorm[i * 4 + 3] = (byte)(norm[i * 4 + 3] * f);
                    tlebe[i * 4 + 3] = (byte)j;
                }
            }

            if (spec != null)
            {
                for (i = 0; i < n; i++)
                {
                    tspec[i * 4 + 0] = (byte)(spec[i * 4 + 0] * 255);
                    tspec[i * 4 + 1] = (byte)(spec[i * 4 + 1] * 255);
                    tspec[i * 4 + 2] = (byte)(spec[i * 4 + 2] * 255);
                    tspec[i * 4 + 3] = (byte)(spec[i * 4 + 3] * 255);
                }
            }

            if (luma != null)
            {
                for (i = 0; i < n; i++)
                {
                    PDJPG_EncodeFloatPixel(new FloatPtr(luma, i * 4), new BytePtr(tluma, i * 4), new BytePtr(tlebe, i * 4 + 1));
                }
            }

            i = PDJPG_EncodeComponentCtxI(ctx,
                trgba, tnorm, tspec, tluma, tlebe,
                obuf, xs, ys, qf);
            return (i);
        }
コード例 #24
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        //static void pdjpg_getPixel2_RGBA(BytePtr rgb,
        //        int *ra, int *ga, int *ba,
        //        int *rb, int *gb, int *bb)
        //{
        //    *ra=rgb[0]; *ga=rgb[1]; *ba=rgb[2];
        //    *ra=rgb[4]; *ga=rgb[5]; *ba=rgb[6];
        //}

        #endif

        #if false

        public static int PDJPG_EncodeFast(
            BytePtr ibuf, BytePtr obuf, int xs, int ys, int qf)
        {
            int sz;

            if (st_ctx == null) st_ctx = PDJPG_AllocContext();
            sz = PDJPG_EncodeFastCtx(st_ctx, ibuf, obuf, xs, ys, qf, 0);
            //	PDJPG_FreeContext(ctx);
            return (sz);
        }
コード例 #25
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_EncodeFloatPixel(FloatPtr ipix, BytePtr opix, BytePtr oexp)
        {
            double f, g;
            int i, j, k;

            if ((ipix[0] >= 0) && (ipix[0] <= 1) &&
                (ipix[1] >= 0) && (ipix[1] <= 1) &&
                (ipix[2] >= 0) && (ipix[2] <= 1))
            {
                oexp[0] = 192;
                opix[0] = (byte)(ipix[0] * 255);
                opix[1] = (byte)(ipix[1] * 255);
                opix[2] = (byte)(ipix[2] * 255);
                return;
            }

            f = ipix[1];
            if (Math.Abs(ipix[0]) > Math.Abs(f)) f = ipix[0];
            if (Math.Abs(ipix[2]) > Math.Abs(f)) f = ipix[2];

            if (f >= 0)
            {
                f = Math.Log(f) / Math.Log(2.0);
                i = (int)(pdjpg_ssqrt(f * 240) + 0.5);
                if (i > 63) i = 63;
                if (i < (-63)) i = -63;
                j = 192 + i;
                g = pdjpg_scltab[j];

                oexp[0] = (byte)j;
                f = 255 / g;
                k = (int)(ipix[0] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[0] = (byte)k;
                k = (int)(ipix[1] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[1] = (byte)k;
                k = (int)(ipix[2] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[2] = (byte)k;
                return;
            }
            else
            {
                f = Math.Log(-f) / Math.Log(2.0);
                i = (int)(pdjpg_ssqrt(f * 240) + 0.5);
                if (i > 63) i = 63;
                if (i < (-63)) i = -63;
                j = 63 - i;
                g = pdjpg_scltab[j];

                oexp[0] = (byte)j;
                f = 255 / g;
                k = (int)(ipix[0] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[0] = (byte)k;
                k = (int)(ipix[1] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[1] = (byte)k;
                k = (int)(ipix[2] * f); k = (k < 0) ? 0 : ((k <= 255) ? k : 255); opix[2] = (byte)k;
                return;
            }
        }
コード例 #26
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_EmitMarkerDMLT_DHT(PDJPG_Context ctx, int tab)
        {
            BytePtr tbuf, ct1;
            int i;

            tbuf = new BytePtr(65536);
            ct1 = ctx.huff.EmitMiniHufftabBuf(ctx, tbuf, tab);
            i = ct1 - tbuf;
            ctx.huff.ct.emit(PDJPG_DMLT_DHT0 + tab);
            ctx.huff.ct.EmitUVLI((ulong)i);
            BytePtr.memcpy(ctx.huff.ct, tbuf, i);
            ctx.huff.ct += i;
        }
コード例 #27
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeLDatCtx(
            PDJPG_Context ctx, byte[] ibuf, BytePtr obuf,
            int xs, int ys, int qf, int pf)
        {
            BytePtr tbuf, cts;
            int i, j, sz, tsz;

            //	if(!ctx)ctx=PDJPG_AllocContext();

            tbuf = new BytePtr(1 << 20);
            sz = PDJPG_EncodeCtx(ctx, ibuf, tbuf, xs, ys, qf, pf);

            sz = PDJPG_EscapeEncodeSingleBuffer(tbuf, sz);

            cts = tbuf; tsz = sz;
            //ctx.huff.ct = obuf; ctx.huff.win = 0; ctx.huff.pos = 0;
            ctx.huff.InitOutputStream(ctx, obuf);

            while (tsz >= 65528)
            {
                i = 65529;
                if (cts[i - 1] == 0xFF) i--;
                j = i + 6;
                ctx.huff.ct.emit(0xFF);
                ctx.huff.ct.emit(JPG.JPG_APP12);
                ctx.huff.ct.emit((j >> 8) & 0xFF);
                ctx.huff.ct.emit(j & 0xFF);

                ctx.huff.ct.emit('L');
                ctx.huff.ct.emit('D');
                ctx.huff.ct.emit('A');
                ctx.huff.ct.emit('T');

                BytePtr.memcpy(ctx.huff.ct, cts, i);
                cts += i; ctx.huff.ct += i;
                tsz -= i;
            }

            if ((tsz > 0) && (tsz < 65528))
            {
                i = tsz + 6;
                ctx.huff.ct.emit(0xFF);
                ctx.huff.ct.emit(JPG.JPG_APP12);
                ctx.huff.ct.emit((i >> 8) & 0xFF);
                ctx.huff.ct.emit(i & 0xFF);

                ctx.huff.ct.emit('L');
                ctx.huff.ct.emit('D');
                ctx.huff.ct.emit('A');
                ctx.huff.ct.emit('T');

                BytePtr.memcpy(ctx.huff.ct, cts, tsz);
                ctx.huff.ct += tsz;
            }

            sz = ctx.huff.ct - obuf;
            //free(tbuf);

            return (sz);
        }
コード例 #28
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_EmitMarkerDMLT_DQT(PDJPG_Context ctx, int n)
        {
            BytePtr tbuf, ct1, ct2;
            int i, j, k, l, nb;

            #if false
            nb = 1;
            for (i = 0; i < 64; i++)
            {
                j=ctx.jpg_qt[n * 64 + i];
                while (j >= (1 << nb)) nb++;
            }
            #endif

            nb = 4;

            tbuf = new BytePtr(65536);

            ct2 = ctx.huff.ct;
            ctx.huff.InitOutputStream(ctx, tbuf);

            ctx.huff.WriteNBits(ctx, 0, 4);      //reserved
            ctx.huff.WriteNBits(ctx, nb, 4);     //DQT bits

            l = 0;
            for (i = 0; i < 64; i++)
            {
                //ctx.huff.WriteNBits(ctx, ctx.jpg_qt[n * 64 + pdjpg_zigzag2[i]], nb);
                k = ctx.jpg_qt[n * 64 + pdjpg_zigzag2[i]];
                ((PDJHUFF)ctx.huff).WriteSRice(ctx, k - l, nb);
                l = k;
            }

            //            WriteNBits(ctx, 1, 4);
            //            WriteNBits(ctx, 2, 4);
            //            BSXRP_EncodeCodeLengths(ctx, new BytePtr(len, tab * 256), 256);

            ctx.huff.FlushBits(ctx);
            ct1 = ctx.huff.ct;
            ctx.huff.ct = ct2;

            i = ct1 - tbuf;
            ctx.huff.ct.emit(PDJPG_DMLT_DQT0 + n);
            ctx.huff.ct.EmitUVLI((ulong)i);
            BytePtr.memcpy(ctx.huff.ct, tbuf, i);
            ctx.huff.ct += i;
        }
コード例 #29
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EscapeDecodeSingleBuffer(BytePtr buf, int sz)
        {
            BytePtr cs, ct, cse, cte;

            cs = buf; cse = buf + sz;
            ct = buf; cte = buf + sz;

            while ((cs < cse) && (ct < cte))
            {
                if ((cs[0] == 0xFF) && (cs[1] == 0x00))
                { cs += 2; ct.emit(0xFF); continue; }
                if ((cs[0] == 0xFF) && (cs[1] <= 0x0F))
                { ct.emit(0xFF); ct.emit(cs[1] - 1); cs += 2; continue; }
                ct.emit(cs.next());
            }
            if (ct >= cte) return (-1);
            return (ct - buf);
        }
コード例 #30
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static BytePtr PDJPG_EmitTagLayer(PDJPG_Context ctx, 
            BytePtr ct, string name)
        {
            BytePtr ctt;
            int i;

            //ctx.huff.ct = ct; ctx.huff.win = 0; ctx.huff.pos = 0;
            //ctx.huff.InitOutputStream(ctx, ct);

            ct.emit(0xFF);
            ct.emit(JPG.JPG_APP11);
            ctt = ct;
            ct.emit(0x00);
            ct.emit(0x00);
            ct.EmitString("TagLayer");
            ct.EmitString(name);
            i = ct - ctt;
            ctt[0] = (i >> 8) & 0xFF; ctt[1] = i & 0xFF;
            return (ct);
        }
コード例 #31
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EscapeEncodeBuffer(BytePtr ibuf, int isz,
            BytePtr obuf, int osz)
        {
            BytePtr cs, ct, cse, cte;

            cs = ibuf; cse = ibuf + isz;
            ct = obuf; cte = obuf + osz;

            while ((cs < cse) && (ct < cte))
            {
                if (cs[0] == 0xFF)
                {
                    cs++;
                    ct.emit(0xFF);
                    ct.emit(0x00);
                    continue;
                }

                ct.emit(cs.next());
            }

            if (ct >= cte) return (-1);
            return (ct - obuf);
        }
コード例 #32
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeBaseCtx(
            PDJPG_Context ctx, byte[] ibuf, BytePtr obuf,
            int xs, int ys, int qf, int pf)
        {
            BytePtr tbuf, cs, cse, ct;
            int sz;

            tbuf = new BytePtr(1 << 24);
            sz = PDJPG_EncodeCtx(ctx, ibuf, tbuf, xs, ys, qf, pf);

            cs = tbuf; cse = tbuf + sz; ct = obuf;
            if ((cs[0] == 0xFF) && (cs[1] == JPG.JPG_SOI))
                cs += 2;
            while (cs < cse)
            {
                if ((cs[0] == 0xFF) && (cs[1] == JPG.JPG_EOI))
                    break;
                ct.emit(cs.next());
            }

            //free(tbuf);
            return (ct - obuf);
        }
コード例 #33
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EscapeEncodeSingleBuffer(BytePtr buf, int sz)
        {
            BytePtr tbuf;
            int i;

            tbuf = new BytePtr(sz * 2);
            i = PDJPG_EscapeEncodeBuffer(buf, sz, tbuf, sz * 2);
            if (i < 0) return (i);
            BytePtr.memcpy(buf, tbuf, i);
            //	free(tbuf);
            return (i);
        }
コード例 #34
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeComponent(
            byte[] rgba, byte[] norm, byte[] spec, byte[] luma,
            BytePtr obuf, int xs, int ys, int qf)
        {
            PDJPG_Context ctx;
            int sz;

            ctx = PDJPG_AllocContext();
            sz = PDJPG_EncodeComponentCtx(ctx,
                rgba, norm, spec, luma,
                obuf, xs, ys, qf);
            PDJPG_FreeContext(ctx);
            return (sz);
        }
コード例 #35
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_MakeQuantTabFastIJG_Y(
            short[] inv, int cnt, BytePtr tab, double qf)
        {
            double s, q;
            int i, j;

            q = (qf * 100);
            s = (q < 50) ? 5000 / q : (200 - 2 * q);
            for (i = 0; i < 64; i++)
            {
                j = (int)((s * pdjpg_ijg_qtab_y[i] + 50) / 100);
                j = (j < 1) ? 1 : ((j < 256) ? j : 255);
                tab[i] = j;
            }
        }
コード例 #36
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_EncodeComponentCtxI(PDJPG_Context ctx,
            byte[] rgba, byte[] norm, byte[] spec, byte[] luma, byte[] lebe,
            BytePtr obuf, int xs, int ys, int qf)
        {
            int i;
            BytePtr ct;

            ct = obuf;

            ct = PDJPG_EncodeBeginLayeredCtx(ctx, ct, xs, ys, qf);
            i = PDJPG_EncodeComponentCtxI2(ctx, rgba, norm, spec, luma, lebe, ct, xs, ys, qf, null, null);
            ct += i;

            ct = PDJPG_EncodeEndLayeredCtx(ctx, ct);

            //free(tbuf);
            return (ct - obuf);
        }
コード例 #37
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
 public static void PDJPG_MakeQuantTabInput(short[] inv, int cnt, BytePtr tab, double q)
 {
     PDJPG_MakeQuantTabInput_AA(inv, cnt, tab, q);
 }
コード例 #38
0
 public static void luaI_free_BytePtr(ref BytePtr block)
 {
     block = null;            //*((int *)block) = -1;  /* to catch errors */
     //free(block);
 }
コード例 #39
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_MakeQuantTabInputFast(
            short[] inv, int cnt, BytePtr tab, double q)
        {
            int i;
            //	PDJPG_MakeQuantTabInput(in, cnt, tab, q);

            i = cnt / 16;
            if (i < 1) i = 1;
            PDJPG_MakeQuantTabInput(inv, i, tab, q);
        }
コード例 #40
0
ファイル: CLib.cs プロジェクト: weimingtom/KopiLuaCompare
//			public CharPtr(string str)
//			{
//				this.chars = (str + '\0').ToCharArray();
//				this.index = 0;
//			}

            public BytePtr(BytePtr ptr)
            {
                this.chars = ptr.chars;
                this.index = ptr.index;
            }
コード例 #41
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_MakeQuantTabInput_AA(short[] inv, int cnt, BytePtr tab, double q)
        {
            //	static double deltas[DCTSZ2];
            double[] deltas = new double[DCTSZ2];
            double f, g, te;
            int i, j, k;

            if (q >= 1)
            {
                for (i = 0; i < DCTSZ2; i++)
                    tab[i] = 1;
                return;
            }

            for (j = 0; j < DCTSZ2; j++)
                deltas[j] = 0;
            #if false
            for (i = 0; i < cnt; i++)
                for (j = 0; j < DCTSZ2; j++)
                    deltas[j] += Math.Abs(inv[i * DCTSZ2 + j] * 1.0);
            for (j = 0; j < DCTSZ2; j++)
                deltas[j] /= cnt;
            #endif

            #if true
            for (i = 0; i < cnt; i++)
                for (j = 0; j < DCTSZ2; j++)
                {
                    k = inv[i * DCTSZ2 + j];
                    deltas[j] += k*k;
                }
            for (j = 0; j < DCTSZ2; j++)
            {
                deltas[j] = Math.Sqrt(deltas[j] / cnt);
            }
            #endif

            te = 0;
            for (j = 0; j < DCTSZ2; j++)
                te += deltas[j];

            for (i = 0; i < DCTSZ; i++)
            {
                for (j = 0; j < DCTSZ; j++)
                {
                    f = deltas[i * DCTSZ + j];

                    f = f / te;
                    if (f < 0.00001) f = 0.00001;
                    g = (1.0 - q);
                    f = 10 * g * g * g / f;
                    k = (int)f;
                    if (k < 1) k = 1;
                    if (k > 255) k = 255;

                    //			printf("%f/%f %d\n", deltas[i*DCTSZ+j], te, k);

                    //			if(f<1)f=1;
                    //			if(f>255)f=255;
                    tab[i * DCTSZ + j] = (byte)k;
                }
            }

            #if false
            if (tab[DCTSZ2 - 3] > 1)
                tab[DCTSZ2 - 3] = (byte)(tab[DCTSZ2 - 3] * 0.75);
            if (tab[DCTSZ2 - 2] > 1)
                tab[DCTSZ2 - 2] = (byte)(tab[DCTSZ2 - 2] * 0.75);
            if (tab[DCTSZ2 - 1] > 1)
                tab[DCTSZ2 - 1] = (byte)(tab[DCTSZ2 - 1] * 0.5);
            #endif
        }
コード例 #42
0
ファイル: CLib.cs プロジェクト: weimingtom/KopiLuaCompare
 public BytePtr(BytePtr ptr, int index)
 {
     this.chars = ptr.chars;
     this.index = index;
 }
コード例 #43
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static int PDJPG_GetImgBlk(char *blk, int xo, int yo, BytePtr img, int xs, int ys)
        {
            BytePtr cs;
            char *ct;
            int i, j, k;

            cs=img+(yo*xs+xo); ct=blk;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); ct+=8; cs+=xs;
            memcpy8(ct, cs); // ct+=8; cs+=xs;
            return(0);
        }
コード例 #44
0
        /*
        ** Execute the given opcode. Return 0 in success or 1 on error.
        */
        public static int lua_execute(BytePtr pc)
        {
            ObjectRef oldbase = new ObjectRef(@base);

            @base = new ObjectRef(top);
            while (true)
            {
                OpCode opcode;
                opcode = (OpCode)pc[0]; pc.inc();
                switch (opcode)
                {
                case OpCode.PUSHNIL:
                    tag(top.get(), Type.T_NIL);
                    top.inc();
                    break;

                case OpCode.PUSH0:
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), 0);
                    top.inc();
                    break;

                case OpCode.PUSH1:
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), 1);
                    top.inc();
                    break;

                case OpCode.PUSH2:
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), 2);
                    top.inc();
                    break;

                case OpCode.PUSHBYTE:
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), pc[0]); pc.inc();
                    top.inc();
                    break;

                case OpCode.PUSHWORD:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), code.w);
                    top.inc();
                }
                break;

                case OpCode.PUSHFLOAT:
                {
                    CodeFloat code = new CodeFloat();
                    get_float(code, pc);
                    tag(top.get(), Type.T_NUMBER);
                    nvalue(top.get(), code.f);
                    top.inc();
                }
                break;

                case OpCode.PUSHSTRING:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    tag(top.get(), Type.T_STRING);
                    svalue(top.get(), lua_constant[code.w]);
                    top.inc();
                }
                break;

                case OpCode.PUSHLOCAL0:
                case OpCode.PUSHLOCAL1:
                case OpCode.PUSHLOCAL2:
                case OpCode.PUSHLOCAL3:
                case OpCode.PUSHLOCAL4:
                case OpCode.PUSHLOCAL5:
                case OpCode.PUSHLOCAL6:
                case OpCode.PUSHLOCAL7:
                case OpCode.PUSHLOCAL8:
                case OpCode.PUSHLOCAL9:
                    top.set(0, @base.get((int)(opcode - OpCode.PUSHLOCAL0)));
                    top.inc();
                    break;

                case OpCode.PUSHLOCAL:
                    top.set(0, @base.get(pc[0]));
                    top.inc();
                    pc.inc();
                    break;

                case OpCode.PUSHGLOBAL:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.set(0, s_object(code.w));
                    top.inc();
                }
                break;

                case OpCode.PUSHINDEXED:
                    top.dec();
                    if (tag(top.get(-1)) != Type.T_ARRAY)
                    {
                        lua_reportbug("indexed expression not a table");
                        return(1);
                    }
                    {
                        Object_ h = lua_hashdefine(avalue(top.get(-1)), top.get());
                        if (h == null)
                        {
                            return(1);
                        }
                        top.set(-1, h);
                    }
                    break;

                case OpCode.PUSHMARK:
                    tag(top.get(), Type.T_MARK);
                    top.inc();
                    break;

                case OpCode.PUSHOBJECT:
                    top.set(0, top.get(-3));
                    top.inc();
                    break;

                case OpCode.STORELOCAL0:
                case OpCode.STORELOCAL1:
                case OpCode.STORELOCAL2:
                case OpCode.STORELOCAL3:
                case OpCode.STORELOCAL4:
                case OpCode.STORELOCAL5:
                case OpCode.STORELOCAL6:
                case OpCode.STORELOCAL7:
                case OpCode.STORELOCAL8:
                case OpCode.STORELOCAL9:
                    top.dec();
                    @base.set((int)(opcode - OpCode.STORELOCAL0), top.get());
                    break;

                case OpCode.STORELOCAL:
                    top.dec();
                    @base.set(pc[0], top.get());
                    pc.inc();
                    break;

                case OpCode.STOREGLOBAL:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    s_object(code.w, top.get());
                }
                break;

                case OpCode.STOREINDEXED0:
                    if (tag(top.get(-3)) != Type.T_ARRAY)
                    {
                        lua_reportbug("indexed expression not a table");
                        return(1);
                    }
                    {
                        Object_ h = lua_hashdefine(avalue(top.get(-3)), top.get(-2));
                        if (h == null)
                        {
                            return(1);
                        }
                        h.set(top.get(-1));
                    }
                    top.add(-3);
                    break;

                case OpCode.STOREINDEXED:
                {
                    int n = pc[0]; pc.inc();
                    if (tag(top.get(-3 - n)) != Type.T_ARRAY)
                    {
                        lua_reportbug("indexed expression not a table");
                        return(1);
                    }
                    {
                        Object_ h = lua_hashdefine(avalue(top.get(-3 - n)), top.get(-2 - n));
                        if (h == null)
                        {
                            return(1);
                        }
                        h.set(top.get(-1));
                    }
                    top.dec();
                }
                break;

                case OpCode.STORELIST0:
                case OpCode.STORELIST:
                {
                    int     m, n;
                    Object_ arr;
                    if (opcode == OpCode.STORELIST0)
                    {
                        m = 0;
                    }
                    else
                    {
                        m = pc[0] * FIELDS_PER_FLUSH; pc.inc();
                    }
                    n   = pc[0]; pc.inc();
                    arr = top.get(-n - 1);
                    if (tag(arr) != Type.T_ARRAY)
                    {
                        lua_reportbug("internal error - table expected");
                        return(1);
                    }
                    while (n != 0)
                    {
                        tag(top.get(), Type.T_NUMBER); nvalue(top.get(), n + m);
                        lua_hashdefine(avalue(arr), top.get()).set(top.get(-1));
                        top.dec();
                        n--;
                    }
                }
                break;

                case OpCode.STORERECORD:
                {
                    int     n   = pc[0]; pc.inc();
                    Object_ arr = top.get(-n - 1);
                    if (tag(arr) != Type.T_ARRAY)
                    {
                        lua_reportbug("internal error - table expected");
                        return(1);
                    }
                    while (n != 0)
                    {
                        CodeWord code = new CodeWord();
                        get_word(code, pc);
                        tag(top.get(), Type.T_STRING); svalue(top.get(), lua_constant[code.w]);
                        (lua_hashdefine(avalue(arr), top.get())).set(top.get(-1));
                        top.dec();
                        n--;
                    }
                }
                break;

                case OpCode.ADJUST:
                {
                    ObjectRef newtop = @base.getRef(pc[0]); pc.inc();
                    while (top.isLessThan(newtop.get()))
                    {
                        tag(top.get(), Type.T_NIL); top.inc();
                    }
                    top = newtop;                          /* top could be bigger than newtop */
                }
                break;

                case OpCode.CREATEARRAY:
                    if (tag(top.get(-1)) == Type.T_NIL)
                    {
                        nvalue(top.get(-1), 101);
                    }
                    else
                    {
                        if (tonumber(top.get(-1)))
                        {
                            return(1);
                        }
                        if (nvalue(top.get(-1)) <= 0)
                        {
                            nvalue(top.get(-1), 101);
                        }
                    }
                    avalue(top.get(-1), (Hash)lua_createarray((int)nvalue(top.get(-1))));
                    if (avalue(top.get(-1)) == null)
                    {
                        return(1);
                    }
                    tag(top.get(-1), Type.T_ARRAY);
                    break;

                case OpCode.EQOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    top.dec();
                    if (tag(l) != tag(r))
                    {
                        tag(top.get(-1), Type.T_NIL);
                    }
                    else
                    {
                        switch (tag(l))
                        {
                        case Type.T_NIL:
                            tag(top.get(-1), Type.T_NUMBER);
                            break;

                        case Type.T_NUMBER:
                            tag(top.get(-1), (nvalue(l) == nvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_ARRAY:
                            tag(top.get(-1), (avalue(l) == avalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_FUNCTION:
                            tag(top.get(-1), (bvalue(l) == bvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_CFUNCTION:
                            tag(top.get(-1), (fvalue(l) == fvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_USERDATA:
                            tag(top.get(-1), (uvalue(l) == uvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_STRING:
                            tag(top.get(-1), (strcmp(svalue(l), svalue(r)) == 0) ? Type.T_NUMBER : Type.T_NIL);
                            break;

                        case Type.T_MARK:
                            return(1);
                        }
                    }
                    nvalue(top.get(-1), 1);
                }
                break;

                case OpCode.LTOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    top.dec();
                    if (tag(l) == Type.T_NUMBER && tag(r) == Type.T_NUMBER)
                    {
                        tag(top.get(-1), (nvalue(l) < nvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                    }
                    else
                    {
                        if (tostring(l) || tostring(r))
                        {
                            return(1);
                        }
                        tag(top.get(-1), (strcmp(svalue(l), svalue(r)) < 0) ? Type.T_NUMBER : Type.T_NIL);
                    }
                    nvalue(top.get(-1), 1);
                }
                break;

                case OpCode.LEOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    top.dec();
                    if (tag(l) == Type.T_NUMBER && tag(r) == Type.T_NUMBER)
                    {
                        tag(top.get(-1), (nvalue(l) <= nvalue(r)) ? Type.T_NUMBER : Type.T_NIL);
                    }
                    else
                    {
                        if (tostring(l) || tostring(r))
                        {
                            return(1);
                        }
                        tag(top.get(-1), (strcmp(svalue(l), svalue(r)) <= 0) ? Type.T_NUMBER : Type.T_NIL);
                    }
                    nvalue(top.get(-1), 1);
                }
                break;

                case OpCode.ADDOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        return(1);
                    }
                    nvalue(l, nvalue(l) + nvalue(r));
                    top.dec();
                }
                break;

                case OpCode.SUBOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        return(1);
                    }
                    nvalue(l, nvalue(l) - nvalue(r));
                    top.dec();
                }
                break;

                case OpCode.MULTOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        return(1);
                    }
                    nvalue(l, nvalue(l) * nvalue(r));
                    top.dec();
                }
                break;

                case OpCode.DIVOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tonumber(r) || tonumber(l))
                    {
                        return(1);
                    }
                    nvalue(l, nvalue(l) / nvalue(r));
                    top.dec();
                }
                break;

                case OpCode.CONCOP:
                {
                    Object_ l = top.get(-2);
                    Object_ r = top.get(-1);
                    if (tostring(r) || tostring(l))
                    {
                        return(1);
                    }
                    svalue(l, lua_createstring(lua_strconc(svalue(l), svalue(r))));
                    if (svalue(l) == null)
                    {
                        return(1);
                    }
                    top.dec();
                }
                break;

                case OpCode.MINUSOP:
                    if (tonumber(top.get(-1)))
                    {
                        return(1);
                    }
                    nvalue(top.get(-1), -nvalue(top.get(-1)));
                    break;

                case OpCode.NOTOP:
                    tag(top.get(-1), tag(top.get(-1)) == Type.T_NIL ? Type.T_NUMBER : Type.T_NIL);
                    break;

                case OpCode.ONTJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    if (tag(top.get(-1)) != Type.T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.ONFJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    if (tag(top.get(-1)) == Type.T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.JMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    pc += code.w;
                }
                break;

                case OpCode.UPJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    pc -= code.w;
                }
                break;

                case OpCode.IFFJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    if (tag(top.get()) == Type.T_NIL)
                    {
                        pc += code.w;
                    }
                }
                break;

                case OpCode.IFFUPJMP:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    top.dec();
                    if (tag(top.get()) == Type.T_NIL)
                    {
                        pc -= code.w;
                    }
                }
                break;

                case OpCode.POP:
                    top.dec();
                    break;

                case OpCode.CALLFUNC:
                {
//				        if (pc.chars != code.chars && pc.index == 4454)
//				        {
//				            Console.WriteLine("=================");
//				        }
                    BytePtr   newpc;
                    ObjectRef b_ = top.getRef(-1);
                    while (tag(b_.get()) != Type.T_MARK)
                    {
                        b_.dec();
                    }
//						if (b_.obj == stack)
//						{
//							Console.WriteLine("================");
//						}
                    if (tag(b_.get(-1)) == Type.T_FUNCTION)
                    {
                        lua_debugline = 0;                                                      /* always reset debug flag */
                        newpc         = bvalue(b_.get(-1));
                        bvalue(b_.get(-1), pc);                                                 /* store return code */
                        nvalue(b_.get(), @base.minus(stack));                                   /* store base value */
                        @base = b_.getRef(+1);
                        pc    = new BytePtr(newpc);
                        if (MAXSTACK - @base.minus(stack) < STACKGAP)
                        {
                            lua_error("stack overflow");
                            return(1);
                        }
                    }
                    else if (tag(b_.get(-1)) == Type.T_CFUNCTION)
                    {
                        int nparam;
                        lua_debugline = 0;                                 // always reset debug flag
                        nvalue(b_.get(), @base.minus(stack));              // store base value
                        @base  = b_.getRef(+1);
                        nparam = top.minus(@base);                         // number of parameters
                        (fvalue(b_.get(-1)))();                            // call C function

                        /* shift returned values */
                        {
                            int i;
                            int nretval = top.minus(@base) - nparam;
                            top   = @base.getRef(-2);
                            @base = new ObjectRef(stack, (int)nvalue(@base.get(-1)));
                            for (i = 0; i < nretval; i++)
                            {
                                top.get().set(top.get(nparam + 2));
                                top.inc();
                            }
                        }
                    }
                    else
                    {
                        lua_reportbug("call expression not a function");
                        return(1);
                    }
                }
                break;

                case OpCode.RETCODE:
                {
                    int i;
                    int shift   = pc[0]; pc.inc();
                    int nretval = top.minus(@base) - shift;
                    top.setRef(@base.get(-2));
                    pc    = bvalue(@base.get(-2));
                    @base = new ObjectRef(stack, (int)nvalue(@base.get(-1)));                              //FIXME:???new ObjectRef???
                    for (i = 0; i < nretval; i++)
                    {
                        top.get().set(top.get(shift + 2));
                        top.inc();
                    }
                }
                break;

                case OpCode.HALT:
                    @base = new ObjectRef(oldbase);
                    return(0);                    // success

                case OpCode.SETFUNCTION:
                {
                    CodeWord file = new CodeWord(), func = new CodeWord();
                    get_word(file, pc);
                    get_word(func, pc);
                    if (0 != lua_pushfunction(file.w, func.w))
                    {
                        return(1);
                    }
                }
                break;

                case OpCode.SETLINE:
                {
                    CodeWord code = new CodeWord();
                    get_word(code, pc);
                    lua_debugline = code.w;
                }
                break;

                case OpCode.RESET:
                    lua_popfunction();
                    break;

                default:
                    lua_error("internal error - opcode didn't match");
                    return(1);
                }
            }
        }
コード例 #45
0
ファイル: encoder.cs プロジェクト: cr88192/bgbtech_engine
        public static void PDJPG_MakeMegaQuantTabInputY(short[] inv, int cnt, BytePtr tab, double q)
        {
            BytePtr taba, tabb;
            int i;

            //PDJPG_MakeQuantTabInput_AA(inv, cnt, tab, q);
            //PDJPG_MakeQuantTabFastIJG_Y(inv, cnt, tab, q);

            taba = new BytePtr(64);
            tabb = new BytePtr(64);
            PDJPG_MakeQuantTabInput_AA(inv, cnt*64, taba, q);
            PDJPG_MakeQuantTabFastIJG_Y(inv, cnt*64, tabb, q);
            for (i = 0; i < 64; i++)
                tab[i] = (taba[i] + tabb[i]) / 2;
            for (i = 0; i < 64; i++)
                tab[64+i] = (taba[i] + tabb[i]) / 2;
        }