예제 #1
0
        public static void WriteImgData(ref Cjpeg cj, ref BinaryWriter bw)
        {
            byte v_len;
            byte zero_run;
            int code;
            int v_code;
            int l_code;
            int EOB_idx;
            CBitWriter cbw = new CBitWriter(ref bw);
            //ブロック長ループ
            for (int i = 0; i < cj.cb.b_len; i++)
            {
                //色ループ
                for (int j = 0; j < 3; j++)
                {
                            if (i == 4095)
                            {
                                int aaaaa;
                            }

                    EOB_idx = SearchEOBStart(ref cj, j, i);
                    //DC
                    v_len = GetValueLength(cj.cb.data[j][i][0]);
                    GetCode(ref cj, v_len, j, DC, out v_code,out l_code);
                    cbw.WriteBit(v_code, l_code);
                    cbw.WriteBit(cj.cb.data[j][i][0], v_len);

                    //AC
                    zero_run = 0;
                    for (int k = 1; k < 64; k++)
                    {
                        if (k == EOB_idx)
                        {
                            GetCode(ref cj, EOB, j, AC, out v_code, out l_code);
                            cbw.WriteBit(v_code, l_code);

                            break;
                        }

                        else if (cj.cb.data[j][i][k] == 0)
                        {
                            zero_run++;
                            if (zero_run == 16)
                            {
                                GetCode(ref cj, ZRL, j, AC, out v_code, out l_code);
                                cbw.WriteBit(v_code, l_code);
                                zero_run = 0;
                            }
                        }
                        else
                        {
                            v_len = (byte)((zero_run << 4) + GetValueLength(cj.cb.data[j][i][k]));
                            GetCode(ref cj, v_len, j, AC, out v_code, out l_code);
                            cbw.WriteBit(v_code, l_code);
                            cbw.WriteBit(cj.cb.data[j][i][k], v_len&0x0f);
                            zero_run = 0;
                        }
                    }
                }
            }
            cbw.WriteFinal();
        }
예제 #2
0
 public CJpegEncoder(ref Cjpeg cjpeg, string path)
 {
     cj = cjpeg;
     bw = new BinaryWriter(File.Open(path, FileMode.Create));
     cbw = new CBitWriter(ref bw);
 }