pixelmed
MarkerSegmentSOF.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 MarkerSegmentSOF {
11 
12  private static final String identString = "@(#) $Header: /userland/cvs/codec/com/pixelmed/codec/jpeg/MarkerSegmentSOF.java,v 1.4 2015/10/17 21:20:52 dclunie Exp $";
13 
14  private int marker;
15  private int SamplePrecision;
16  private int nLines;
17  private int nSamplesPerLine;
18  private int nComponentsInFrame;
19  private int[] ComponentIdentifier;
20  private int[] HorizontalSamplingFactor;
21  private int[] VerticalSamplingFactor;
22  private int[] QuantizationTableDestinationSelector;
23 
24  public int getMarker() { return marker; }
25 
26  public int getSamplePrecision() { return SamplePrecision; }
27  public int getNLines() { return nLines; }
28  public int getNSamplesPerLine() { return nSamplesPerLine; }
29  public int getNComponentsInFrame() { return nComponentsInFrame; }
30 
31  public int[] getHorizontalSamplingFactor() { return HorizontalSamplingFactor; }
32  public int[] getVerticalSamplingFactor() { return VerticalSamplingFactor; }
33 
34  public MarkerSegmentSOF(int marker,byte[] b,int length) throws Exception {
35  this.marker = marker;
36 
37  SamplePrecision = Utilities.extract8(b,0);
38  nLines = Utilities.extract16be(b,1);
39  nSamplesPerLine = Utilities.extract16be(b,3);
40  nComponentsInFrame = Utilities.extract8(b,5);
41 
42  int lengthExpected = 6+nComponentsInFrame*3;
43  if (length != lengthExpected) {
44  throw new Exception("Incorrect length of SOF Parameters Marker Segment, expected "+lengthExpected+" (based on nComponentsInFrame "+nComponentsInFrame+") but was "+length);
45  }
46 
47  ComponentIdentifier = new int[nComponentsInFrame];
48  HorizontalSamplingFactor = new int[nComponentsInFrame];
49  VerticalSamplingFactor = new int[nComponentsInFrame];
50  QuantizationTableDestinationSelector= new int[nComponentsInFrame];
51 
52  for (int i=0; i<nComponentsInFrame; ++i) {
53  ComponentIdentifier[i] = Utilities.extract8(b,6+i*3);
54  HorizontalSamplingFactor[i] = Utilities.extract8(b,6+i*3+1) >> 4;
55  VerticalSamplingFactor[i] = Utilities.extract8(b,6+i*3+1) & 0x0f;
56  QuantizationTableDestinationSelector[i] = Utilities.extract8(b,6+i*3+2);
57  }
58  }
59 
60  public String toString() {
61  StringBuffer buf = new StringBuffer();
62  buf.append("\n\t"+Markers.getAbbreviation(marker)+":\n");
63  buf.append("\t\t SamplePrecision = " +SamplePrecision+"\n");
64  buf.append("\t\t nLines = " +nLines+"\n");
65  buf.append("\t\t nSamplesPerLine = " +nSamplesPerLine+"\n");
66  buf.append("\t\t nComponentsInFrame = " +nComponentsInFrame+"\n");
67  for (int i=0; i<nComponentsInFrame; ++i) {
68  buf.append("\t\t component " +i+"\n");
69  buf.append("\t\t\t ComponentIdentifier = " +ComponentIdentifier[i]+"\n");
70  buf.append("\t\t\t HorizontalSamplingFactor = " +HorizontalSamplingFactor[i]+"\n");
71  buf.append("\t\t\t VerticalSamplingFactor = " +VerticalSamplingFactor[i]+"\n");
72  buf.append("\t\t\t QuantizationTableDestinationSelector = " +QuantizationTableDestinationSelector[i]+"\n");
73  }
74  return buf.toString();
75  }
76 
77 }
78 
com.pixelmed.codec.jpeg.Utilities.extract16be
static final int extract16be(byte[] b, int offset)
Definition: Utilities.java:46
com.pixelmed.codec.jpeg.Markers.getAbbreviation
static final String getAbbreviation(int marker)
Definition: Markers.java:379
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getHorizontalSamplingFactor
int[] getHorizontalSamplingFactor()
Definition: MarkerSegmentSOF.java:31
com.pixelmed.codec.jpeg.Utilities.extract8
static final int extract8(byte[] b, int offset)
Definition: Utilities.java:42
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getSamplePrecision
int getSamplePrecision()
Definition: MarkerSegmentSOF.java:26
com.pixelmed.codec.jpeg.MarkerSegmentSOF.MarkerSegmentSOF
MarkerSegmentSOF(int marker, byte[] b, int length)
Definition: MarkerSegmentSOF.java:34
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getVerticalSamplingFactor
int[] getVerticalSamplingFactor()
Definition: MarkerSegmentSOF.java:32
com.pixelmed.codec.jpeg.Markers
Definition: Markers.java:13
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getNLines
int getNLines()
Definition: MarkerSegmentSOF.java:27
com.pixelmed.codec.jpeg.MarkerSegmentSOF
Definition: MarkerSegmentSOF.java:10
com.pixelmed.codec.jpeg.MarkerSegmentSOF.toString
String toString()
Definition: MarkerSegmentSOF.java:60
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getMarker
int getMarker()
Definition: MarkerSegmentSOF.java:24
com.pixelmed.codec.jpeg.Utilities
Definition: Utilities.java:13
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getNSamplesPerLine
int getNSamplesPerLine()
Definition: MarkerSegmentSOF.java:28
com.pixelmed.codec.jpeg.MarkerSegmentSOF.getNComponentsInFrame
int getNComponentsInFrame()
Definition: MarkerSegmentSOF.java:29