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();
 }
 /**
  * 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;
 }