pixelmed
MarkerSegmentSOS.java
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015, David A. Clunie DBA Pixelmed Publishing. All rights reserved. */
2 
3 package com.pixelmed.codec.jpeg;
4 
10 public class MarkerSegmentSOS {
11 
12  private static final String identString = "@(#) $Header: /userland/cvs/codec/com/pixelmed/codec/jpeg/MarkerSegmentSOS.java,v 1.3 2015/10/17 21:20:52 dclunie Exp $";
13 
14  private int nComponentsPerScan;
15  private int[] ScanComponentSelector;
16  private int[] DCEntropyCodingTableSelector;
17  private int[] ACEntropyCodingTableSelector;
18  private int[] MappingTableSelector; // LS
19  private int StartOfSpectralOrPredictorSelection;
20  private int EndOfSpectralSelection;
21  private int SuccessiveApproximationBitPositionHigh;
22  private int SuccessiveApproximationBitPositionLowOrPointTransform;
23 
24  public int getNComponentsPerScan() { return nComponentsPerScan; }
25  public int[] getDCEntropyCodingTableSelector() { return DCEntropyCodingTableSelector; }
26  public int[] getACEntropyCodingTableSelector() { return ACEntropyCodingTableSelector; }
27  public int getStartOfSpectralOrPredictorSelection() { return StartOfSpectralOrPredictorSelection; }
28  public int getSuccessiveApproximationBitPositionLowOrPointTransform() { return SuccessiveApproximationBitPositionLowOrPointTransform; }
29 
30  public MarkerSegmentSOS(byte[] b,int length) throws Exception {
31  nComponentsPerScan=Utilities.extract8(b,0);
32  int lengthExpected = 1+nComponentsPerScan*2+3;
33  if (length != lengthExpected) {
34  throw new Exception("Incorrect length of SOS Parameters Marker Segment, expected "+lengthExpected+" (based on nComponentsPerScan "+nComponentsPerScan+") but was "+length);
35  }
36  ScanComponentSelector =new int[nComponentsPerScan];
37  DCEntropyCodingTableSelector=new int[nComponentsPerScan];
38  ACEntropyCodingTableSelector=new int[nComponentsPerScan];
39  MappingTableSelector =new int[nComponentsPerScan]; // LS
40  for (int i=0; i<nComponentsPerScan; ++i) {
41  ScanComponentSelector[i] =Utilities.extract8(b,1+i*2);
42  DCEntropyCodingTableSelector[i]=Utilities.extract8(b,1+i*2+1) >> 4;
43  ACEntropyCodingTableSelector[i]=Utilities.extract8(b,1+i*2+1) & 0x0f;
44  MappingTableSelector[i] =Utilities.extract8(b,1+i*2+1); // LS
45  }
46  StartOfSpectralOrPredictorSelection =Utilities.extract8(b,1+nComponentsPerScan*2);
47  EndOfSpectralSelection =Utilities.extract8(b,1+nComponentsPerScan*2+1);
48  SuccessiveApproximationBitPositionHigh =Utilities.extract8(b,1+nComponentsPerScan*2+2) >> 4;
49  SuccessiveApproximationBitPositionLowOrPointTransform=Utilities.extract8(b,1+nComponentsPerScan*2+2) & 0x0f;
50  }
51 
52  public String toString() {
53  StringBuffer buf = new StringBuffer();
54  buf.append("\n\tSOS:\n");
55  buf.append("\t\t nComponentsPerScan = "+nComponentsPerScan+"\n");
56  for (int i=0; i<nComponentsPerScan; ++i) {
57  buf.append("\t\t component "+i+"\n");
58  buf.append("\t\t\t ScanComponentSelector = "+ScanComponentSelector[i]+"\n");
59  buf.append("\t\t\t DCEntropyCodingTableSelector = "+DCEntropyCodingTableSelector[i]+"\n");
60  buf.append("\t\t\t ACEntropyCodingTableSelector = "+ACEntropyCodingTableSelector[i]+"\n");
61  buf.append("\t\t\t MappingTableSelector(LS) = "+MappingTableSelector[i]+"\n"); // LS
62  }
63  buf.append("\t\t StartOfSpectralOrPredictorSelection/NearLosslessDifferenceBound(LS) = "+StartOfSpectralOrPredictorSelection+"\n");
64  buf.append("\t\t EndOfSpectralSelection/InterleaveMode(LS) = "+EndOfSpectralSelection+"\n");
65  buf.append("\t\t SuccessiveApproximationBitPositionHigh = "+SuccessiveApproximationBitPositionHigh+"\n");
66  buf.append("\t\t SuccessiveApproximationBitPositionLowOrPointTransform = "+SuccessiveApproximationBitPositionLowOrPointTransform+"\n");
67  return buf.toString();
68  }
69 
70 }
71 
static final int extract8(byte[] b, int offset)
Definition: Utilities.java:42