public override void LoadRaw() { int trow = 0; int tcol = 0; JHead jh; while (trow < state.raw_height) { int save = (int)state.ifp.Position; if (state.tile_length < int.MaxValue) { state.ifp.Seek(state.ifp.get4(), SeekOrigin.Begin); } jh = new JHead(state, state.ifp, false, state.dng_version); int jwide = jh.wide; if (state.filters != 0) { jwide *= jh.clrs; } jwide /= state.is_raw; int jrow = 0; int row = 0; int col = 0; for (; jrow < jh.high; jrow++) { int rpi = ljpeg_row(jrow, jh); int jcol; for (jcol = 0; jcol < jwide; jcol++) { adobe_copy_pixel(jh.row, trow + row, tcol + col, ref rpi); if (++col >= state.tile_width || col >= state.raw_width) { row += 1 + (col = 0); } } } state.ifp.Seek(save + 4, SeekOrigin.Begin); if ((tcol += (int)state.tile_width) >= state.raw_width) { tcol = 0; trow += (int)state.tile_length + tcol; } //state.Free(jh.row); } }
protected int ljpeg_row(int jrow, JHead jh) { int col; int c; ushort mark = 0; int[] irow = new int[3]; if (jrow * jh.wide % jh.restart == 0) { for (c = 0; c < 4; c++) { jh.vpred[c] = 1 << (jh.bits - 1); } if (jrow != 0) { do { c = state.ifp.ReadByte(); mark = (ushort)((mark << 8) + c); } while (c != -1 && mark >> 4 != 0xffd); } state.InStream.ResetBits(); } for (c = 0; c < 3; c++) { irow[c] = jh.wide * jh.clrs * ((jrow + c) & 1); } for (col = 0; col < jh.wide; col++) { for (c = 0; c < jh.clrs; c++) { int diff = ljpeg_diff(jh.huff[c]); int pred; if ((jh.sraw && c < 2 && ((col | c) != 0))) { pred = jh.row[irow[0] + (c << 1) - 3]; } else if (col != 0) { pred = jh.row[irow[0] - jh.clrs]; } else { pred = (jh.vpred[c] += diff) - diff; } if (jrow != 0 && col != 0) { switch (jh.psv) { case 1: break; case 2: pred = jh.row[irow[1]]; break; case 3: pred = jh.row[irow[1] - jh.clrs]; break; case 4: pred = pred + jh.row[irow[1]] - jh.row[irow[1] - jh.clrs]; break; case 5: pred = pred + ((jh.row[irow[1]] - jh.row[irow[1] - jh.clrs]) >> 1); break; case 6: pred = jh.row[irow[1]] + ((pred - jh.row[irow[1] - jh.clrs]) >> 1); break; case 7: pred = (pred + jh.row[irow[1]]) >> 1; break; default: pred = 0; break; } } jh.row[irow[0]] = (ushort)(pred + diff); if (jh.row[irow[0]] >> jh.bits != 0) { throw new Exception("ljpeg_row: ((jh.row[irow[0]] = (ushort)(pred + diff)) >> jh.bits) != 0"); } irow[0]++; irow[1]++; } } return(irow[2]); }
public override void LoadRaw() { //lossless_jpeg_load_raw() double[] dark = { 0.0, 0.0 }; //struct jhead jh; int min = int.MaxValue; int row = 0; int col = 0; JHead jh = new JHead(state, state.InStream, false, state.dng_version); int jwide = jh.wide * jh.clrs; for (int jrow = 0; jrow < jh.high; jrow++) { int rpi = ljpeg_row(jrow, jh); ushort[] rp = jh.row; for (int jcol = 0; jcol < jwide; jcol++) { int val = rp[rpi++]; if (jh.bits <= 12) { val = state.curve[val & 0xfff]; } if (state.cr2_slice[0] != 0) { int jidx = jrow * jwide + jcol; int i = jidx / (state.cr2_slice[1] * jh.high); bool j = i >= state.cr2_slice[0]; if (j) { i = state.cr2_slice[0]; } jidx -= i * (state.cr2_slice[1] * jh.high); row = jidx / state.cr2_slice[1 + (j ? 1 : 0)]; col = jidx % state.cr2_slice[1 + (j ? 1 : 0)] + i * state.cr2_slice[1]; } if (state.raw_width == 3984 && (col -= 2) < 0) { col += row--; } if ((uint)(row - state.top_margin) < state.height) { if ((uint)(col - state.left_margin) < state.width) { state.BAYER_set(row - state.top_margin, col - state.left_margin, (ushort)val); if (min > val) { min = val; } } else if (col > 1) { dark[(col - state.left_margin) & 1] += val; } } if (++col >= state.raw_width) { col = row++; } } } canon_black(dark); //if (!strcasecmp(make, "KODAK")) // STATE->black = min; }