Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public static BytePtr PDJPG_EncodeEndLayeredCtx(
     PDJPG_Context ctx, BytePtr ct)
 {
     ct.emit(0xFF);
     ct.emit(JPG.JPG_EOI);
     return ct;
 }