javax.imageio.plugins.jpeg.JPEGQTable Java Examples

The following examples show how to use javax.imageio.plugins.jpeg.JPEGQTable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPEGImageWriter.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList<DQTMarkerSegment.Qtable> tables = new ArrayList<>();
    Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(tables.get(i).data);
        }
    }
    return retval;
}
 
Example #2
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #3
Source File: DQTMarkerSegment.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
void print() {
    System.out.println("Table id: " + Integer.toString(tableID));
    System.out.println("Element precision: "
                       + Integer.toString(elementPrecision));

    (new JPEGQTable(data)).toString();
    /*
      for (int i = 0; i < 64; i++) {
      if (i % 8 == 0) {
      System.out.println();
      }
      System.out.print(" " + Integer.toString(data[i]));
      }
      System.out.println();
    */
}
 
Example #4
Source File: DQTMarkerSegment.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #5
Source File: DQTMarkerSegment.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #6
Source File: JPEGImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns <code>true</code> if the write was aborted.
 */
private native boolean writeImage(long structPointer,
                                  byte [] data,
                                  int inCsType, int outCsType,
                                  int numBands,
                                  int [] bandSizes,
                                  int srcWidth,
                                  int destWidth, int destHeight,
                                  int stepX, int stepY,
                                  JPEGQTable [] qtables,
                                  boolean writeDQT,
                                  JPEGHuffmanTable[] DCHuffmanTables,
                                  JPEGHuffmanTable[] ACHuffmanTables,
                                  boolean writeDHT,
                                  boolean optimizeHuffman,
                                  boolean progressive,
                                  int numScans,
                                  int [] scans,
                                  int [] componentIds,
                                  int [] HsamplingFactors,
                                  int [] VsamplingFactors,
                                  int [] QtableSelectors,
                                  boolean haveMetadata,
                                  int restartInterval);
 
Example #7
Source File: JPEGImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #8
Source File: DQTMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #9
Source File: DQTMarkerSegment.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
void print() {
    System.out.println("Table id: " + Integer.toString(tableID));
    System.out.println("Element precision: "
                       + Integer.toString(elementPrecision));

    (new JPEGQTable(data)).toString();
    /*
      for (int i = 0; i < 64; i++) {
      if (i % 8 == 0) {
      System.out.println();
      }
      System.out.print(" " + Integer.toString(data[i]));
      }
      System.out.println();
    */
}
 
Example #10
Source File: DQTMarkerSegment.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void print() {
    System.out.println("Table id: " + Integer.toString(tableID));
    System.out.println("Element precision: "
                       + Integer.toString(elementPrecision));

    (new JPEGQTable(data)).toString();
    /*
      for (int i = 0; i < 64; i++) {
      if (i % 8 == 0) {
      System.out.println();
      }
      System.out.print(" " + Integer.toString(data[i]));
      }
      System.out.println();
    */
}
 
Example #11
Source File: JPEGImageReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns <code>true</code> if the read was aborted.
 */
private native boolean readImage(int imageIndex,
                                 long structPointer,
                                 byte [] buffer,
                                 int numRasterBands,
                                 int [] srcBands,
                                 int [] bandSizes,
                                 int sourceXOffset, int sourceYOffset,
                                 int sourceWidth, int sourceHeight,
                                 int periodX, int periodY,
                                 JPEGQTable [] abbrevQTables,
                                 JPEGHuffmanTable [] abbrevDCHuffmanTables,
                                 JPEGHuffmanTable [] abbrevACHuffmanTables,
                                 int minProgressivePass,
                                 int maxProgressivePass,
                                 boolean wantUpdates);
 
Example #12
Source File: JPEGImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #13
Source File: DQTMarkerSegment.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #14
Source File: DQTMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void print() {
    System.out.println("Table id: " + Integer.toString(tableID));
    System.out.println("Element precision: "
                       + Integer.toString(elementPrecision));

    (new JPEGQTable(data)).toString();
    /*
      for (int i = 0; i < 64; i++) {
      if (i % 8 == 0) {
      System.out.println();
      }
      System.out.print(" " + Integer.toString(data[i]));
      }
      System.out.println();
    */
}
 
Example #15
Source File: JPEGImageReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns <code>true</code> if the read was aborted.
 */
private native boolean readImage(int imageIndex,
                                 long structPointer,
                                 byte [] buffer,
                                 int numRasterBands,
                                 int [] srcBands,
                                 int [] bandSizes,
                                 int sourceXOffset, int sourceYOffset,
                                 int sourceWidth, int sourceHeight,
                                 int periodX, int periodY,
                                 JPEGQTable [] abbrevQTables,
                                 JPEGHuffmanTable [] abbrevDCHuffmanTables,
                                 JPEGHuffmanTable [] abbrevACHuffmanTables,
                                 int minProgressivePass,
                                 int maxProgressivePass,
                                 boolean wantUpdates);
 
Example #16
Source File: JPEGImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList<DQTMarkerSegment.Qtable> tables = new ArrayList<>();
    Iterator<MarkerSegment> iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(tables.get(i).data);
        }
    }
    return retval;
}
 
Example #17
Source File: DQTMarkerSegment.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #18
Source File: JPEGImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #19
Source File: JPEGImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #20
Source File: DQTMarkerSegment.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #21
Source File: DQTMarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #22
Source File: JPEGImageWriter.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns <code>true</code> if the write was aborted.
 */
private native boolean writeImage(long structPointer,
                                  byte [] data,
                                  int inCsType, int outCsType,
                                  int numBands,
                                  int [] bandSizes,
                                  int srcWidth,
                                  int destWidth, int destHeight,
                                  int stepX, int stepY,
                                  JPEGQTable [] qtables,
                                  boolean writeDQT,
                                  JPEGHuffmanTable[] DCHuffmanTables,
                                  JPEGHuffmanTable[] ACHuffmanTables,
                                  boolean writeDHT,
                                  boolean optimizeHuffman,
                                  boolean progressive,
                                  int numScans,
                                  int [] scans,
                                  int [] componentIds,
                                  int [] HsamplingFactors,
                                  int [] VsamplingFactors,
                                  int [] QtableSelectors,
                                  boolean haveMetadata,
                                  int restartInterval);
 
Example #23
Source File: JPEGImageWriter.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #24
Source File: JPEGImageWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds all DQT marker segments and returns all the q
 * tables as a single array of JPEGQTables.
 */
private JPEGQTable [] collectQTablesFromMetadata
    (JPEGMetadata metadata) {
    ArrayList tables = new ArrayList();
    Iterator iter = metadata.markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = (MarkerSegment) iter.next();
        if (seg instanceof DQTMarkerSegment) {
            DQTMarkerSegment dqt =
                (DQTMarkerSegment) seg;
            tables.addAll(dqt.tables);
        }
    }
    JPEGQTable [] retval = null;
    if (tables.size() != 0) {
        retval = new JPEGQTable[tables.size()];
        for (int i = 0; i < retval.length; i++) {
            retval[i] =
                new JPEGQTable(((DQTMarkerSegment.Qtable)tables.get(i)).data);
        }
    }
    return retval;
}
 
Example #25
Source File: JPEGImageReader.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns <code>true</code> if the read was aborted.
 */
private native boolean readImage(int imageIndex,
                                 long structPointer,
                                 byte [] buffer,
                                 int numRasterBands,
                                 int [] srcBands,
                                 int [] bandSizes,
                                 int sourceXOffset, int sourceYOffset,
                                 int sourceWidth, int sourceHeight,
                                 int periodX, int periodY,
                                 JPEGQTable [] abbrevQTables,
                                 JPEGHuffmanTable [] abbrevDCHuffmanTables,
                                 JPEGHuffmanTable [] abbrevACHuffmanTables,
                                 int minProgressivePass,
                                 int maxProgressivePass,
                                 boolean wantUpdates);
 
Example #26
Source File: DQTMarkerSegment.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #27
Source File: DQTMarkerSegment.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
Qtable(boolean wantLuma, float quality) {
    elementPrecision = 0;
    JPEGQTable base = null;
    if (wantLuma) {
        tableID = 0;
        base = JPEGQTable.K1Div2Luminance;
    } else {
        tableID = 1;
        base = JPEGQTable.K2Div2Chrominance;
    }
    if (quality != JPEG.DEFAULT_QUALITY) {
        quality = JPEG.convertToLinearQuality(quality);
        if (wantLuma) {
            base = JPEGQTable.K1Luminance.getScaledInstance
                (quality, true);
        } else {
            base = JPEGQTable.K2Div2Chrominance.getScaledInstance
                (quality, true);
        }
    }
    data = base.getTable();
}
 
Example #28
Source File: DQTMarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
IIOMetadataNode getNativeNode() {
    IIOMetadataNode node = new IIOMetadataNode("dqtable");
    node.setAttribute("elementPrecision",
                      Integer.toString(elementPrecision));
    node.setAttribute("qtableId",
                      Integer.toString(tableID));
    node.setUserObject(new JPEGQTable(data));
    return node;
}
 
Example #29
Source File: JPEG.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return an array of default, visually lossless quantization tables.
 */
static JPEGQTable [] getDefaultQTables() {
    JPEGQTable [] qTables = new JPEGQTable[2];
    qTables[0] = JPEGQTable.K1Div2Luminance;
    qTables[1] = JPEGQTable.K2Div2Chrominance;
    return qTables;
}
 
Example #30
Source File: DQTMarkerSegment.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assuming the given table was generated by scaling the "standard"
 * visually lossless luminance table, extract the scale factor that
 * was used.
 */
Qtable getChromaForLuma(Qtable luma) {
    Qtable newGuy = null;
    // Determine if the table is all the same values
    // if so, use the same table
    boolean allSame = true;
    for (int i = 1; i < luma.QTABLE_SIZE; i++) {
        if (luma.data[i] != luma.data[i-1]) {
            allSame = false;
            break;
        }
    }
    if (allSame) {
        newGuy = (Qtable) luma.clone();
        newGuy.tableID = 1;
    } else {
        // Otherwise, find the largest coefficient less than 255.  This is
        // the largest value that we know did not clamp on scaling.
        int largestPos = 0;
        for (int i = 1; i < luma.QTABLE_SIZE; i++) {
            if (luma.data[i] > luma.data[largestPos]) {
                largestPos = i;
            }
        }
        // Compute the scale factor by dividing it by the value in the
        // same position from the "standard" table.
        // If the given table was not generated by scaling the standard,
        // the resulting table will still be reasonable, as it will reflect
        // a comparable scaling of chrominance frequency response of the
        // eye.
        float scaleFactor = ((float)(luma.data[largestPos]))
            / ((float)(JPEGQTable.K1Div2Luminance.getTable()[largestPos]));
        //    generate a new table
        JPEGQTable jpegTable =
            JPEGQTable.K2Div2Chrominance.getScaledInstance(scaleFactor,
                                                           true);
        newGuy = new Qtable(jpegTable, 1);
    }
    return newGuy;
}