public JpegReadStatusInt DecodeACFirst(JpegBinaryReader stream, float[] zz) { if (stream.eobRun > 0) { stream.eobRun--; return(JpegReadStatusInt.GetSuccess()); } for (int k = spectralStart; k <= spectralEnd; k++) { var status = ACTable.Decode(stream); if (status.Status != Status.Success) { return(status); } int s = status.Result; int r = s >> 4; s &= 15; if (s != 0) { k += r; status = stream.ReadBits(s); if (status.Status != Status.Success) { return(status); } r = status.Result; s = HuffmanTable.Extend(r, s); zz[k] = s << successiveLow; } else { if (r != 15) { stream.eobRun = 1 << r; if (r != 0) { status = stream.ReadBits(r); if (status.Status != Status.Success) { return(status); } stream.eobRun += status.Result; } stream.eobRun--; break; } k += 15; } } return(JpegReadStatusInt.GetSuccess()); }
public JpegReadStatusInt DecodeDCRefine(JpegBinaryReader stream, float[] dest) { var status = stream.ReadBits(1); if (status.Status != Status.Success) { return(status); } if (status.Result == 1) { dest[0] = (int)dest[0] | (1 << successiveLow); } return(JpegReadStatusInt.GetSuccess()); }
/// <summary> /// Generated from text on F-23, F.13 - Huffman decoded of AC coefficients /// on ISO DIS 10918-1. Requirements and Guidelines. /// </summary> internal JpegReadStatusInt decode_ac_coefficients(JpegBinaryReader jpegStream, float[] zz) { var status = new JpegReadStatusInt(); for (int k = 1; k < 64; k++) { status = ACTable.Decode(jpegStream); if (status.Status != Status.Success) { return(status); } int s = status.Result; int r = s >> 4; s &= 15; if (s != 0) { k += r; status = jpegStream.ReadBits(s); if (status.Status != Status.Success) { return(status); } s = HuffmanTable.Extend(status.Result, s); zz[k] = s; } else { if (r != 15) { //throw new JPEGMarkerFoundException(); return(status); } k += 15; } } return(status); }
public JpegReadStatusInt DecodeACRefine(JpegBinaryReader stream, float[] dest) { int p1 = 1 << successiveLow; int m1 = (-1) << successiveLow; int k = spectralStart; if (stream.eobRun == 0) { for (; k <= spectralEnd; k++) { #region Decode and check S var status = ACTable.Decode(stream); if (status.Status != Status.Success) { return(status); } int s = status.Result; int r = s >> 4; s &= 15; if (s != 0) { if (s != 1) { throw new Exception("Decode Error"); } status = stream.ReadBits(1); if (status.Status != Status.Success) { return(status); } s = status.Result == 1 ? p1 : m1; } else { if (r != 15) { stream.eobRun = 1 << r; if (r > 0) { status = stream.ReadBits(r); if (status.Status != Status.Success) { return(status); } stream.eobRun += status.Result; } break; } } // if (s != 0) #endregion // Apply the update do { if (dest[k] != 0) { status = stream.ReadBits(1); if (status.Status != Status.Success) { return(status); } if (status.Result == 1) { if (((int)dest[k] & p1) == 0) { if (dest[k] >= 0) { dest[k] += p1; } else { dest[k] += m1; } } } } else { if (--r < 0) { break; } } k++; } while (k <= spectralEnd); if ((s != 0) && k < 64) { dest[k] = s; } } // for k = start ... end } if (stream.eobRun > 0) { for (; k <= spectralEnd; k++) { if (dest[k] != 0) { var status = stream.ReadBits(1); if (status.Status != Status.Success) { return(status); } if (status.Result == 1) { if (((int)dest[k] & p1) == 0) { if (dest[k] >= 0) { dest[k] += p1; } else { dest[k] += m1; } } } } } stream.eobRun--; } return(JpegReadStatusInt.GetSuccess()); }