org.eclipse.swt.win32.win32.x86_3.7.2.v3740f

rn new ImageData[] { imageData };
  }
  
  static final class bitread_perm_state
  {
    int get_buffer;
    int bits_left;
  }
  
  static final class bitread_working_state
  {
    byte[] buffer;
    int bytes_offset;
    int bytes_in_buffer;
    int get_buffer;
    int bits_left;
    JPEGDecoder.jpeg_decompress_struct cinfo;
  }
  
  static final class jpeg_color_deconverter
  {
    int color_convert;
    int[] Cr_r_tab;
    int[] Cb_b_tab;
    int[] Cr_g_tab;
    int[] Cb_g_tab;
    
    void start_pass(JPEGDecoder.jpeg_decompress_struct cinfo) {}
  }
  
  static final class jpeg_component_info
  {
    int component_id;
    int component_index;
    int h_samp_factor;
    int v_samp_factor;
    int quant_tbl_no;
    int dc_tbl_no;
    int ac_tbl_no;
    int width_in_blocks;
    int height_in_blocks;
    int DCT_scaled_size;
    int downsampled_width;
    int downsampled_height;
    boolean component_needed;
    int MCU_width;
    int MCU_height;
    int MCU_blocks;
    int MCU_sample_width;
    int last_col_width;
    int last_row_height;
    JPEGDecoder.JQUANT_TBL quant_table;
    int[] dct_table;
  }
  
  static final class jpeg_decomp_master
  {
    boolean is_dummy_pass;
    int pass_number;
    boolean using_merged_upsample;
    JPEGDecoder.jpeg_color_quantizer quantizer_1pass;
    JPEGDecoder.jpeg_color_quantizer quantizer_2pass;
  }
  
  static final class jpeg_input_controller
  {
    int consume_input;
    boolean has_multiple_scans;
    boolean eoi_reached;
    boolean inheaders;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.internal.image.JPEGDecoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.internal.image;

final class JPEGEndOfImage
  extends JPEGFixedSizeSegment
{
  public JPEGEndOfImage() {}
  
  public JPEGEndOfImage(byte[] reference)
  {
    super(reference);
  }
  
  public int signature()
  {
    return 65497;
  }
  
  public int fixedSize()
  {
    return 2;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.internal.image.JPEGEndOfImage
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.internal.image;

import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.ImageLoaderEvent;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;

public final class JPEGFileFormat
  extends FileFormat
{
  int restartInterval;
  JPEGFrameHeader frameHeader;
  int imageWidth;
  int imageHeight;
  int interleavedMcuCols;
  int interleavedMcuRows;
  int maxV;
  int maxH;
  boolean progressive;
  int samplePrecision;
  int nComponents;
  int[][] frameComponents;
  int[] componentIds;
  byte[][] imageComponents;
  int[] dataUnit;
  int[][][] dataUnits;
  int[] precedingDCs;
  JPEGScanHeader scanHeader;
  byte[] dataBuffer;
  int currentBitCount;
  int bufferCurrentPosition;
  int restartsToGo;
  int nextRestartNumber;
  JPEGHuffmanTable[] acHuffmanTables;
  JPEGHuffmanTable[] dcHuffmanTables;
  int[][] quantizationTables;
  int currentByte;
  int encoderQFactor = 75;
  int eobrun = 0;
  public static final int DCTSIZE = 8;
  public static final int DCTSIZESQR = 64;
  public static final int FIX_0_899976223 = 7373;
  public static final int FIX_1_961570560 = 16069;
  public static final int FIX_2_053119869 = 16819;
  public static final int FIX_0_298631336 = 2446;
  public static final int FIX_1_847759065 = 15137;
  public static final int FIX_1_175875602 = 9633;
  public static final int FIX_3_072711026 = 25172;
  public static final int FIX_0_765366865 = 6270;
  public static final int FIX_2_562915447 = 20995;
  public static final int FIX_0_541196100 = 4433;
  public static final int FIX_0_390180644 = 3196;
  public static final int FIX_1_501321110 = 12299;
  public static final int APP0 = 65504;
  public static final int APP15 = 65519;
  public static final int COM = 65534;
  public static final int DAC = 65484;
  public static final int DHP = 65502;
  public static final int DHT = 65476;
  public static final int DNL = 65500;
  public static final int DRI = 65501;
  public static final int DQT = 65499;
  public static final int EOI = 65497;
  public static final int EXP = 65503;
  public static final int JPG = 65480;
  public static final int JPG0 = 65520;
  public static final int JPG13 = 65533;
  public static final int RST0 = 65488;
  public static final int RST1 = 65489;
  public static final int RST2 = 65490;
  public static final int RST3 = 65491;
  public static final int RST4 = 65492;
  public static final int RST5 = 65493;
  public static final int RST6 = 65494;
  public static final int RST7 = 65495;
  public static final int SOF0 = 65472;
  public static final int SOF1 = 65473;
  public static final int SOF2 = 65474;
  public static final int SOF3 = 65475;
  public static final int SOF5 = 65477;
  public static final int SOF6 = 65478;
  public static final int SOF7 = 65479;
  public static final int SOF9 = 65481;
  public static final int SOF10 = 65482;
  public static final int SOF11 = 65483;
  public static final int SOF13 = 65485;
  public static final int SOF14 = 65486;
  public static final int SOF15 = 65487;
  public static final int SOI = 65496;
  public static final int SOS = 65498;
  public static final int TEM = 65281;
  public static final int TQI = 0;
  public static final int HI = 1;
  public static final int VI = 2;
  public static final int CW = 3;
  public static final int CH = 4;
  public static final int DC = 0;
  public static final int AC = 1;
  public static final int ID_Y = 0;
  public static final int ID_CB = 1;
  public static final int ID_CR = 2;
  public static final RGB[] RGB16 = {
    new RGB(0, 0, 0), 
    new RGB(128, 0, 0), 
    new RGB(0, 128, 0), 
    new RGB(128, 128, 0), 
    new RGB(0, 0, 128), 
    new RGB(128, 0, 128), 
    new RGB(0, 128, 128), 
    new RGB(192, 192, 192), 
    new RGB(128, 128, 128), 
    new RGB(255, 0, 0), 
    new RGB(0, 255, 0), 
    new RGB(255, 255, 0), 
    new RGB(0, 0, 255), 
    new RGB(255, 0, 255), 
    new RGB(0, 255, 255), 
    new RGB(255, 255, 255) };
  public static final int[] ExtendTest = {
    0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 
    4096, 8192, 16384, 32768, 65536, 131072, 262144 };
  public static final int[] ExtendOffset = {
    0, -1, -3, -7, -15, -31, -63, -127, 65281, 65025, 64513, 63489, 
    61441, 57345, 49153, 32769, -65535, -131071, -262143 };
  public static final int[] ZigZag8x8 = {
    0, 1, 8, 16, 9, 2, 3, 10, 
    17, 24, 32, 25, 18, 11, 4, 5, 
    12, 19, 26, 33, 40, 48, 41, 34, 
    27, 20, 13, 6, 7, 14, 21, 28, 
    35, 42, 49, 56, 57, 50, 43, 36, 
    29, 22, 15, 23, 30, 37, 44, 51, 
    58, 59, 52, 45, 38, 31, 39, 46, 
    53, 60, 61, 54, 47, 55, 62, 63 };
  public static final int[] CrRTable;
  public static final int[] CbBTable;
  public static final int[] CrGTable;
  public static final int[] CbGTable;
  public static final int[] RYTable;
  public static final int[] GYTable;
  public static final int[] BYTable;
  public static final int[] RCbTable;
  public static final int[] GCbTable;
  public static final int[] BCbTable;
  public static final int[] RCrTable;
  public static final int[] GCrTable;
  public static final int[] BCrTable;
  public static final int[] NBitsTable;
  
  static
  {
    int[] rYTable = new int['?'];
    int[] gYTable = new int['?'];
    int[] bYTable = new int['?'];
    int[] rCbTable = new int['?'];
    int[] gCbTable = new int['?'];
    int[] bCbTable = new int['?'];
    int[] gCrTable = new int['?'];
    int[] bCrTable = new int['?'];
    for (int i = 0; i < 256; i++)
    {
      rYTable[i] = (i * 19595);
      gYTable[i] = (i * 38470);
      bYTable[i] = (i * 7471 + 32768);
      rCbTable[i] = (i * 54477);
      gCbTable[i] = (i * 43827);
      bCbTable[i] = (i * 32768 + 8388608);
      gCrTable[i] = (i * 38097);
      bCrTable[i] = (i * 60207);
    }
    RYTable = rYTable;
    GYTable = gYTable;
    BYTable = bYTable;
    RCbTable = rCbTable;
    GCbTable = gCbTable;
    BCbTable = bCbTable;
    RCrTable = bCbTable;
    GCrTable = gCrTable;
    BCrTable = bCrTable;
    
    int[] crRTable = new int['?'];
    int[] cbBTable = new int['?'];
    int[] crGTable = new int['?'];
    int[] cbGTable = new int['?'];
    for (int i = 0; i < 256; i++)
    {
      int x2 = 2 * i - 255;
      crRTable[i] = (45941 * x2 + 32768 >> 16);
      cbBTable[i] = (58065 * x2 + 32768 >> 16);
      crGTable[i] = (42135 * x2);
      cbGTable[i] = (54259 * x2 + 32768);
    }
    CrRTable = crRTable;
    CbBTable = cbBTable;
    CrGTable = crGTable;
    CbGTable = cbGTable;
    
    int nBits = 1;
    int power2 = 2;
    int[] nBitsTable = new int['?'];
    nBitsTable[0] = 0;
    for (int i = 1; i < nBitsTable.length; i++)
    {
      if (i >= power2)
      {
        nBits++;
        power2 *= 2;
      }
      nBitsTable[i] = nBits;
    }
    NBitsTable = nBitsTable;
  }
  
  void compress(ImageData image, byte[] dataYComp, byte[] dataCbComp, byte[] dataCrComp)
  {
    int srcWidth = width;
    int srcHeight = height;
    int vhFactor = maxV * maxH;
    
    imageComponents = new byte[nComponents][];
    for (int i = 0; i < nComponents; i++)
    {
      int[] frameComponent = frameComponents[componentIds[i]];
      imageComponents[i] = new byte[frameComponent[3] * frameComponent[4]];
    }
    int[] frameComponent = frameComponents[componentIds[0]];
    for (int yPos = 0; yPos < srcHeight; yPos++)
    {
      int srcOfs = yPos * srcWidth;
      int dstOfs = yPos * frameComponent[3];
      System.arraycopy(dataYComp, srcOfs, imageComponents[0], dstOfs, srcWidth);
    }
    frameComponent = frameComponents[componentIds[1]];
    for (int yPos = 0; yPos < srcHeight / maxV; yPos++)
    {
      int destRowIndex = yPos * frameComponent[3];
      for (int xPos = 0; xPos < srcWidth / maxH; xPos++)
      {
        int sum = 0;
        for (int iv = 0; iv < maxV; iv++)
        {
          int srcIndex = (yPos * maxV + iv) * srcWidth + xPos * maxH;
          for (int ih = 0; ih < maxH; ih++) {
            sum += (dataCbComp[(srcIndex + ih)] & 0xFF);
          }
        }
        imageComponents[1][(destRowIndex + xPos)] = ((byte)(sum / vhFactor));
      }
    }
    frameComponent = frameComponents[componentIds[2]];
    for (int yPos = 0; yPos < srcHeight / maxV; yPos++)
    {
      int destRowIndex = yPos * frameComponent[3];
      for (int xPos = 0; xPos < srcWidth / maxH; xPos++)
      {
        int sum = 0;
        for (int iv = 0; iv < maxV; iv++)
        {
          int srcIndex = (yPos * maxV + iv) * srcWidth + xPos * maxH;
          for (int ih = 0; ih < maxH; ih++) {
            sum += (dataCrComp[(srcIndex + ih)] & 0xFF);
          }
        }
        imageComponents[2][(destRowIndex + xPos)] = ((byte)(sum / vhFactor));
      }
    }
    for (int iComp = 0; iComp < nComponents; iComp++)
    {
      byte[] imageComponent = imageComponents[iComp];
      frameComponent = frameComponents[componentIds[iComp]];
      int hFactor = frameComponent[1];
      int vFactor = frameComponent[2];
      int componentWidth = frameComponent[3];
      int componentHeight = frameComponent[4];
      int compressedWidth = srcWidth / (maxH / hFactor);
      int compressedHeight = srcHeight / (maxV / vFactor);
      if (compressedWidth < componentWidth)
      {
        int delta = componentWidth - compressedWidth;
        for (int yPos = 0; yPos < compressedHeight; yPos++)
        {
          int dstOfs = (yPos + 1) * componentWidth - delta;
          int dataValue = imageComponent[0] & 0xFF;
          for (int i = 0; i < delta; i++) {
            imageComponent[(dstOfs + i)] = ((byte)dataValue);
          }
        }
      }
      if (compressedHeight < componentHeight)
      {
        int srcOfs = compressedHeight > 0 ? (compressedHeight - 1) * componentWidth : 1;
        for (int yPos = compressedHeight > 0 ? compressedHeight : 1; yPos <= componentHeight; yPos++)
        {
          int dstOfs = (yPos - 1) * componentWidth;
          System.arraycopy(imageComponent, srcOfs, imageComponent, dstOfs, componentWidth);
        }
      }
    }
  }
  
  void convert4BitRGBToYCbCr(ImageData image)
  {
    RGB[] rgbs = image.getRGBs();
    int paletteSize = rgbs.length;
    byte[] yComp = new byte[paletteSize];
    byte[] cbComp = new byte[paletteSize];
    byte[] crComp = new byte[paletteSize];
    int srcWidth = width;
    int srcHeight = height;
    for (int i = 0; i < paletteSize; i++)
    {
      RGB color = rgbs[i];
      int r = red;
      int g = green;
      int b = blue;
      int n = RYTable[r] + GYTable[g] + BYTable[b];
      yComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp119_117 = i; byte[] tmp119_115 = yComp;tmp119_115[tmp119_117] = ((byte)(tmp119_115[tmp119_117] - 1));
      }
      n = RCbTable[r] + GCbTable[g] + BCbTable[b];
      cbComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp176_174 = i; byte[] tmp176_172 = cbComp;tmp176_172[tmp176_174] = ((byte)(tmp176_172[tmp176_174] - 1));
      }
      n = RCrTable[r] + GCrTable[g] + BCrTable[b];
      crComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp233_231 = i; byte[] tmp233_229 = crComp;tmp233_229[tmp233_231] = ((byte)(tmp233_229[tmp233_231] - 1));
      }
    }
    int bSize = srcWidth * srcHeight;
    byte[] dataYComp = new byte[bSize];
    byte[] dataCbComp = new byte[bSize];
    byte[] dataCrComp = new byte[bSize];
    byte[] origData = data;
    int bytesPerLine = bytesPerLine;
    int maxScanlineByte = srcWidth >> 1;
    for (int yPos = 0; yPos < srcHeight; yPos++) {
      for (int xPos = 0; xPos < maxScanlineByte; xPos++)
      {
        int srcIndex = yPos * bytesPerLine + xPos;
        int dstIndex = yPos * srcWidth + xPos * 2;
        int value2 = origData[srcIndex] & 0xFF;
        int value1 = value2 >> 4;
        value2 &= 0xF;
        dataYComp[dstIndex] = yComp[value1];
        dataCbComp[dstIndex] = cbComp[value1];
        dataCrComp[dstIndex] = crComp[value1];
        dataYComp[(dstIndex + 1)] = yComp[value2];
        dataCbComp[(dstIndex + 1)] = cbComp[value2];
        dataCrComp[(dstIndex + 1)] = crComp[value2];
      }
    }
    compress(image, dataYComp, dataCbComp, dataCrComp);
  }
  
  void convert8BitRGBToYCbCr(ImageData image)
  {
    RGB[] rgbs = image.getRGBs();
    int paletteSize = rgbs.length;
    byte[] yComp = new byte[paletteSize];
    byte[] cbComp = new byte[paletteSize];
    byte[] crComp = new byte[paletteSize];
    int srcWidth = width;
    int srcHeight = height;
    for (int i = 0; i < paletteSize; i++)
    {
      RGB color = rgbs[i];
      int r = red;
      int g = green;
      int b = blue;
      int n = RYTable[r] + GYTable[g] + BYTable[b];
      yComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp119_117 = i; byte[] tmp119_115 = yComp;tmp119_115[tmp119_117] = ((byte)(tmp119_115[tmp119_117] - 1));
      }
      n = RCbTable[r] + GCbTable[g] + BCbTable[b];
      cbComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp176_174 = i; byte[] tmp176_172 = cbComp;tmp176_172[tmp176_174] = ((byte)(tmp176_172[tmp176_174] - 1));
      }
      n = RCrTable[r] + GCrTable[g] + BCrTable[b];
      crComp[i] = ((byte)(n >> 16));
      if ((n < 0) && ((n & 0xFFFF) != 0))
      {
        int tmp233_231 = i; byte[] tmp233_229 = crComp;tmp233_229[tmp233_231] = ((byte)(tmp233_229[tmp233_231] - 1));
      }
    }
    int dstWidth = width;
    int dstHeight = srcHeight;
    int stride = srcWidth + 3 >> 2 << 2;
    int bSize = dstWidth * dstHeight;
    byte[] dataYComp = new byte[bSize];
    byte[] dataCbComp = new byte[bSize];
    byte[] dataCrComp = new byte[bSize];
    byte[] origData = data;
    for (int yPos = 0; yPos < srcHeight; yPos++)
    {
      int srcRowIndex = yPos * stride;
      int dstRowIndex = yPos * dstWidth;
      for (int xPos = 0; xPos < srcWidth; xPos++)
      {
        int value = origData[(srcRowIndex + xPos)] & 0xFF;
        int dstIndex = dstRowIndex + xPos;
        dataYComp[dstIndex] = yComp[value];
        dataCbComp[dstIndex] = cbComp[value];
        dataCrComp[dstIndex] = crComp[value];
      }
    }
    compress(image, dataYComp, dataCbComp, dataCrComp);
  }
  
  byte[] convertCMYKToRGB()
  {
    return new byte[0];
  }
  
  void convertImageToYCbCr(ImageData image)
  {
    switch (depth)
    {
    case 4: 
      convert4BitRGBToYCbCr(image);
      return;
    case 8: 
      convert8BitRGBToYCbCr(image);
      return;
    case 16: 
    case 24: 
    case 32: 
      convertMultiRGBToYCbCr(image);
      return;
    }
    SWT.error(38);
  }
  
  void convertMultiRGBToYCbCr(ImageData image)
  {
    int srcWidth = width;
    int srcHeight = height;
    int bSize = srcWidth * srcHeight;
    byte[] dataYComp = new byte[bSize];
    byte[] dataCbComp = new byte[bSize];
    byte[] dataCrComp = new byte[bSize];
    PaletteData palette = palette;
    int[] buffer = new int[srcWidth];
    if (isDirect)
    {
      int redMask = redMask;
      int greenMask = greenMask;
      int blueMask = blueMask;
      int redShift = redShift;
      int greenShift = greenShift;
      int blueShift = blueShift;
      for (int yPos = 0; yPos < srcHeight; yPos++)
      {
        image.getPixels(0, yPos, srcWidth, buffer, 0);
        int dstRowIndex = yPos * srcWidth;
        for (int xPos = 0; xPos < srcWidth; xPos++)
        {
          int pixel = buffer[xPos];
          int dstDataIndex = dstRowIndex + xPos;
          int r = pixel & redMask;
          r = redShift < 0 ? r >>> -redShift : r << redShift;
          int g = pixel & greenMask;
          g = greenShift < 0 ? g >>> -greenShift : g << greenShift;
          int b = pixel & blueMask;
          b = blueShift < 0 ? b >>> -blueShift : b << blueShift;
          dataYComp[dstDataIndex] = ((byte)(RYTable[r] + GYTable[g] + BYTable[b] >> 16));
          dataCbComp[dstDataIndex] = ((byte)(RCbTable[r] + GCbTable[g] + BCbTable[b] >> 16));
          dataCrComp[dstDataIndex] = ((byte)(RCrTable[r] + GCrTable[g] + BCrTable[b] >> 16));
        }
      }
    }
    else
    {
      for (int yPos = 0; yPos < srcHeight; yPos++)
      {
        image.getPixels(0, yPos, srcWidth, buffer, 0);
        int dstRowIndex = yPos * srcWidth;
        for (int xPos = 0; xPos < srcWidth; xPos++)
        {
          int pixel = buffer[xPos];
          int dstDataIndex = dstRowIndex + xPos;
          RGB rgb = palette.getRGB(pixel);
          int r = red;
          int g = green;
          int b = blue;
          dataYComp[dstDataIndex] = ((byte)(RYTable[r] + GYTable[g] + BYTable[b] >> 16));
          dataCbComp[dstDataIndex] = ((byte)(RCbTable[r] + GCbTable[g] + BCbTable[b] >> 16));
          dataCrComp[dstDataIndex] = ((byte)(RCrTable[r] + GCrTable[g] + BCrTable[b] >> 16));
        }
      }
    }
    compress(image, dataYComp, dataCbComp, dataCrComp);
  }
  
  byte[] convertYToRGB()
  {
    int compWidth = frameComponents[componentIds[0]][3];
    int bytesPerLine = ((imageWidth * 8 + 7) / 8 + 3) / 4 * 4;
    byte[] data = new byte[bytesPerLine * imageHeight];
    byte[] yComp = imageComponents[0];
    int destIndex = 0;
    for (int i = 0; i < imageHeight; i++)
    {
      int srcIndex = i * compWidth;
      for (int j = 0; j < bytesPerLine; j++)
      {
        int y = yComp[srcIndex] & 0xFF;
        if (y < 0) {
          y = 0;
        } else if (y > 255) {
          y = 255;
        }
        if (j >= imageWidth) {
          y = 0;
        }
        data[destIndex] = ((byte)y);
        srcIndex++;
        destIndex++;
      }
    }
    return data;
  }
  
  byte[] convertYCbCrToRGB()
  {
    int bSize = imageWidth * imageHeight * nComponents;
    byte[] rgbData = new byte[bSize];
    int destIndex = 0;
    expandImageComponents();
    byte[] yComp = imageComponents[0];
    byte[] cbComp = imageComponents[1];
    byte[] crComp = imageComponents[2];
    int compWidth = frameComponents[componentIds[0]][3];
    for (int v = 0; v < imageHeight; v++)
    {
      int srcIndex = v * compWidth;
      for (int i = 0; i < imageWidth; i++)
      {
        int y = yComp[srcIndex] & 0xFF;
        int cb = cbComp[srcIndex] & 0xFF;
        int cr = crComp[srcIndex] & 0xFF;
        int r = y + CrRTable[cr];
        int g = y + (CbGTable[cb] + CrGTable[cr] >> 16);
        int b = y + CbBTable[cb];
        if (r < 0) {
          r = 0;
        } else if (r > 255) {
          r = 255;
        }
        if (g < 0) {
          g = 0;
        } else if (g > 255) {
          g = 255;
        }
        if (b < 0) {
          b = 0;
        } else if (b > 255) {
          b = 255;
        }
        rgbData[destIndex] = ((byte)b);
        rgbData[(destIndex + 1)] = ((byte)g);
        rgbData[(destIndex + 2)] = ((byte)r);
        destIndex += 3;
        srcIndex++;
      }
    }
    return rgbData;
  }
  
  void decodeACCoefficients(int[] dataUnit, int iComp)
  {
    int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
    JPEGHuffmanTable acTable = acHuffmanTables[sParams[1]];
    int k = 1;
    while (k < 64)
    {
      int rs = decodeUsingTable(acTable);
      int r = rs >> 4;
      int s = rs & 0xF;
      if (s == 0)
      {
        if (r != 15) {
          break;
        }
        k += 16;
      }
      else
      {
        k += r;
        int bits = receive(s);
        dataUnit[ZigZag8x8[k]] = extendBy(bits, s);
        k++;
      }
    }
  }
  
  void decodeACFirstCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit)
  {
    if (eobrun > 0)
    {
      eobrun -= 1;
      return;
    }
    int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
    JPEGHuffmanTable acTable = acHuffmanTables[sParams[1]];
    int k = start;
    while (k <= end)
    {
      int rs = decodeUsingTable(acTable);
      int r = rs >> 4;
      int s = rs & 0xF;
      if (s == 0)
      {
        if (r == 15)
        {
          k += 16;
        }
        else
        {
          eobrun = ((1 << r) + receive(r) - 1);
          break;
        }
      }
      else
      {
        k += r;
        int bits = receive(s);
        dataUnit[ZigZag8x8[k]] = (extendBy(bits, s) << approxBit);
        k++;
      }
    }
  }
  
  void decodeACRefineCoefficients(int[] dataUnit, int iComp, int start, int end, int approxBit)
  {
    int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
    JPEGHuffmanTable acTable = acHuffmanTables[sParams[1]];
    int k = start;
    while (k <= end) {
      if (eobrun > 0)
      {
        while (k <= end)
        {
          int zzIndex = ZigZag8x8[k];
          if (dataUnit[zzIndex] != 0) {
            dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
          }
          k++;
        }
        eobrun -= 1;
      }
      else
      {
        int rs = decodeUsingTable(acTable);
        int r = rs >> 4;
        int s = rs & 0xF;
        if (s == 0)
        {
          if (r == 15)
          {
            int zeros = 0;
            do
            {
              int zzIndex = ZigZag8x8[k];
              if (dataUnit[zzIndex] != 0) {
                dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
              } else {
                zeros++;
              }
              k++;
              if (zeros >= 16) {
                break;
              }
            } while (k <= end);
          }
          else
          {
            eobrun = ((1 << r) + receive(r));
          }
        }
        else
        {
          int bit = receive(s);
          int zeros = 0;
          int zzIndex = ZigZag8x8[k];
          while (((zeros < r) || (dataUnit[zzIndex] != 0)) && (k <= end))
          {
            if (dataUnit[zzIndex] != 0) {
              dataUnit[zzIndex] = refineAC(dataUnit[zzIndex], approxBit);
            } else {
              zeros++;
            }
            k++;
            zzIndex = ZigZag8x8[k];
          }
          if (bit != 0) {
            dataUnit[zzIndex] = (1 << approxBit);
          } else {
            dataUnit[zzIndex] = (-1 << approxBit);
          }
          k++;
        }
      }
    }
  }
  
  int refineAC(int ac, int approxBit)
  {
    if (ac > 0)
    {
      int bit = nextBit();
      if (bit != 0) {
        ac += (1 << approxBit);
      }
    }
    else if (ac < 0)
    {
      int bit = nextBit();
      if (bit != 0) {
        ac += (-1 << approxBit);
      }
    }
    return ac;
  }
  
  void decodeDCCoefficient(int[] dataUnit, int iComp, boolean first, int approxBit)
  {
    int[] sParams = scanHeader.componentParameters[componentIds[iComp]];
    JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[0]];
    int lastDC = 0;
    if ((progressive) && (!first))
    {
      int bit = nextBit();
      lastDC = dataUnit[0] + (bit << approxBit);
    }
    else
    {
      lastDC = precedingDCs[iComp];
      int nBits = decodeUsingTable(dcTable);
      if (nBits != 0)
      {
        int bits = receive(nBits);
        int diff = extendBy(bits, nBits);
        lastDC += diff;
        precedingDCs[iComp] = lastDC;
      }
      if (progressive) {
        lastDC <<= approxBit;
      }
    }
    dataUnit[0] = lastDC;
  }
  
  void dequantize(int[] dataUnit, int iComp)
  {
    int[] qTable = quantizationTables[frameComponents[componentIds[iComp]][0]];
    for (int i = 0; i < dataUnit.length; i++)
    {
      int zzIndex = ZigZag8x8[i];
      dataUnit[zzIndex] *= qTable[i];
    }
  }
  
  byte[] decodeImageComponents()
  {
    if (nComponents == 3) {
      return convertYCbCrToRGB();
    }
    if (nComponents == 4) {
      return convertCMYKToRGB();
    }
    return convertYToRGB();
  }
  
  void decodeMCUAtXAndY(int xmcu, int ymcu, int nComponentsInScan, boolean first, int start, int end, int approxBit)
  {
    for (int iComp = 0; iComp < nComponentsInScan; iComp++)
    {
      int scanComponent = iComp;
      while (scanHeader.componentParameters[componentIds[scanComponent]] == null) {
        scanComponent++;
      }
      int[] frameComponent = frameComponents[componentIds[scanComponent]];
      int hi = frameComponent[1];
      int vi = frameComponent[2];
      if (nComponentsInScan == 1)
      {
        hi = 1;
        vi = 1;
      }
      int compWidth = frameComponent[3];
      for (int ivi = 0; ivi < vi; ivi++) {
        for (int ihi = 0; ihi < hi; ihi++)
        {
          if (progressive)
          {
            int index = (ymcu * vi + ivi) * compWidth + xmcu * hi + ihi;
            dataUnit = dataUnits[scanComponent][index];
            if (dataUnit == null)
            {
              dataUnit = new int[64];
              dataUnits[scanComponent][index] = dataUnit;
            }
          }
          else
          {
            for (int i = 0; i < dataUnit.length; i++) {
              dataUnit[i] = 0;
            }
          }
          if ((!progressive) || (scanHeader.isDCProgressiveScan())) {
            decodeDCCoefficient(dataUnit, scanComponent, first, approxBit);
          }
          if (!progressive)
          {
            decodeACCoefficients(dataUnit, scanComponent);
          }
          else
          {
            if (scanHeader.isACProgressiveScan()) {
              if (first) {
                decodeACFirstCoefficients(dataUnit, scanComponent, start, end, approxBit);
              } else {
                decodeACRefineCoefficients(dataUnit, scanComponent, start, end, approxBit);
              }
            }
            if (loader.hasListeners())
            {
              int[] temp = dataUnit;
              dataUnit = new int[64];
              System.arraycopy(temp, 0, dataUnit, 0, 64);
            }
          }
          if ((!progressive) || ((progressive) && (loader.hasListeners())))
          {
            dequantize(dataUnit, scanComponent);
            inverseDCT(dataUnit);
            storeData(dataUnit, scanComponent, xmcu, ymcu, hi, ihi, vi, ivi);
          }
        }
      }
    }
  }
  
  void decodeScan()
  {
    if ((progressive) && (!scanHeader.verifyProgressiveScan())) {
      SWT.error(40);
    }
    int nComponentsInScan = scanHeader.getNumberOfImageComponents();
    int mcuRowsInScan = interleavedMcuRows;
    int mcusPerRow = interleavedMcuCols;
    if (nComponentsInScan == 1)
    {
      int scanComponent = 0;
      while (scanHeader.componentParameters[componentIds[scanComponent]] == null) {
        scanComponent++;
      }
      int[] frameComponent = frameComponents[componentIds[scanComponent]];
      int hi = frameComponent[1];
      int vi = frameComponent[2];
      int mcuWidth = 8 * maxH / hi;
      int mcuHeight = 8 * maxV / vi;
      mcusPerRow = (imageWidth + mcuWidth - 1) / mcuWidth;
      mcuRowsInScan = (imageHeight + mcuHeight - 1) / mcuHeight;
    }
    boolean first = scanHeader.isFirstScan();
    int start = scanHeader.getStartOfSpectralSelection();
    int end = scanHeader.getEndOfSpectralSelection();
    int approxBit = scanHeader.getApproxBitPositionLow();
    restartsToGo = restartInterval;
    nextRestartNumber = 0;
    for (int ymcu = 0; ymcu < mcuRowsInScan; ymcu++) {
      for (int xmcu = 0; xmcu < mcusPerRow; xmcu++)
      {
        if (restartInterval != 0)
        {
          if (restartsToGo == 0) {
            processRestartInterval();
          }
          restartsToGo -= 1;
        }
        decodeMCUAtXAndY(xmcu, ymcu, nComponentsInScan, first, start, end, approxBit);
      }
    }
  }
  
  int decodeUsingTable(JPEGHuffmanTable huffmanTable)
  {
    int i = 0;
    int[] maxCodes = huffmanTable.getDhMaxCodes();
    int[] minCodes = huffmanTable.getDhMinCodes();
    int[] valPtrs = huffmanTable.getDhValPtrs();
    int[] huffVals = huffmanTable.getDhValues();
    int code = nextBit();
    while (code > maxCodes[i])
    {
      code = code * 2 + nextBit();
      i++;
    }
    int j = valPtrs[i] + code - minCodes[i];
    return huffVals[j];
  }
  
  void emit(int huffCode, int nBits)
  {
    if (nBits == 0) {
      SWT.error(40);
    }
    int[] power2m1 = {
      1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 
      16383, 32767, 65535, 131125 };
    
    int code = (huffCode & power2m1[(nBits - 1)]) << 24 - nBits - currentBitCount;
    byte[] codeBuffer = new byte[4];
    codeBuffer[0] = ((byte)(code & 0xFF));
    codeBuffer[1] = ((byte)(code >> 8 & 0xFF));
    codeBuffer[2] = ((byte)(code >> 16 & 0xFF));
    codeBuffer[3] = ((byte)(code >> 24 & 0xFF));
    int abs = nBits - (8 - currentBitCount);
    if (abs < 0) {
      abs = -abs;
    }
    if (abs >> 3 > 0)
    {
      currentByte += codeBuffer[2];
      emitByte((byte)currentByte);
      emitByte(codeBuffer[1]);
      currentByte = codeBuffer[0];
      currentBitCount += nBits - 16;
    }
    else
    {
      currentBitCount += nBits;
      if (currentBitCount >= 8)
      {
        currentByte += codeBuffer[2];
        emitByte((byte)currentByte);
        currentByte = codeBuffer[1];
        currentBitCount -= 8;
      }
      else
      {
        currentByte += codeBuffer[2];
      }
    }
  }
  
  void emitByte(byte byteValue)
  {
    if (bufferCurrentPosition >= 512) {
      resetOutputBuffer();
    }
    dataBuffer[bufferCurrentPosition] = byteValue;
    bufferCurrentPosition += 1;
    if (byteValue == -1) {
      emitByte((byte)0);
    }
  }
  
  void encodeACCoefficients(int[] dataUnit, int iComp)
  {
    int[] sParams = scanHeader.componentParameters[iComp];
    JPEGHuffmanTable acTable = acHuffmanTables[sParams[1]];
    int[] ehCodes = ehCodes;
    byte[] ehSizes = ehCodeLengths;
    int r = 0;
    int k = 1;
    while (k < 64)
    {
      k++;
      int acValue = dataUnit[ZigZag8x8[(k - 1)]];
      if (acValue == 0)
      {
        if (k == 64) {
          emit(ehCodes[0], ehSizes[0] & 0xFF);
        } else {
          r++;
        }
      }
      else
      {
        while (r > 15)
        {
          emit(ehCodes['�'], ehSizes['�'] & 0xFF);
          r -= 16;
        }
        if (acValue < 0)
        {
          int absACValue = acValue;
          if (absACValue < 0) {
            absACValue = -absACValue;
          }
          int nBits = NBitsTable[absACValue];
          int rs = r * 16 + nBits;
          emit(ehCodes[rs], ehSizes[rs] & 0xFF);
          emit(16777215 - absACValue, nBits);
        }
        else
        {
          int nBits = NBitsTable[acValue];
          int rs = r * 16 + nBits;
          emit(ehCodes[rs], ehSizes[rs] & 0xFF);
          emit(acValue, nBits);
        }
        r = 0;
      }
    }
  }
  
  void encodeDCCoefficients(int[] dataUnit, int iComp)
  {
    int[] sParams = scanHeader.componentParameters[iComp];
    JPEGHuffmanTable dcTable = dcHuffmanTables[sParams[0]];
    int lastDC = precedingDCs[iComp];
    int dcValue = dataUnit[0];
    int diff = dcValue - lastDC;
    precedingDCs[iComp] = dcValue;
    if (diff < 0)
    {
      int absDiff = 0 - diff;
      int nBits = NBitsTable[absDiff];
      emit(ehCodes[nBits], ehCodeLengths[nBits]);
      emit(16777215 - absDiff, nBits);
    }
    else
    {
      int nBits = NBitsTable[diff];
      emit(ehCodes[nBits], ehCodeLengths[nBits]);
      if (nBits != 0) {
        emit(diff, nBits);
      }
    }
  }
  
  void encodeMCUAtXAndY(int xmcu, int ymcu)
  {
    int nComponentsInScan = scanHeader.getNumberOfImageComponents();
    dataUnit = new int[64];
    for (int iComp = 0; iComp < nComponentsInScan; iComp++)
    {
      int[] frameComponent = frameComponents[componentIds[iComp]];
      int hi = frameComponent[1];
      int vi = frameComponent[2];
      for (int ivi = 0; ivi < vi; ivi++) {
        for (int ihi = 0; ihi < hi; ihi++)
        {
          extractData(dataUnit, iComp, xmcu, ymcu, ihi, ivi);
          forwardDCT(dataUnit);
          quantizeData(dataUnit, iComp);
          encodeDCCoefficients(dataUnit, iComp);
          encodeACCoefficients(dataUnit, iComp);
        }
      }
    }
  }
  
  void encodeScan()
  {
    for (int ymcu = 0; ymcu < interleavedMcuRows; ymcu++) {
      for (int xmcu = 0; xmcu < interleavedMcuCols; xmcu++) {
        encodeMCUAtXAndY(xmcu, ymcu);
      }
    }
    if (currentBitCount != 0) {
      emitByte((byte)currentByte);
    }
    resetOutputBuffer();
  }
  
  void expandImageComponents()
  {
    for (int iComp = 0; iComp < nComponents; iComp++)
    {
      int[] frameComponent = frameComponents[componentIds[iComp]];
      int hi = frameComponent[1];
      int vi = frameComponent[2];
      int upH = maxH / hi;
      int upV = maxV / vi;
      if (upH * upV > 1)
      {
        byte[] component = imageComponents[iComp];
        int compWidth = frameComponent[3];
        int compHeight = frameComponent[4];
        int upCompWidth = compWidth * upH;
        int upCompHeight = compHeight * upV;
        ImageData src = new ImageData(compWidth, compHeight, 8, new PaletteData(RGB16), 4, component);
        ImageData dest = src.scaledTo(upCompWidth, upCompHeight);
        imageComponents[iComp] = data;
      }
    }
  }
  
  int extendBy(int diff, int t)
  {
    if (diff < ExtendTest[t]) {
      return diff + ExtendOffset[t];
    }
    return diff;
  }
  
  void extractData(int[] dataUnit, int iComp, int xmcu, int ymcu, int ihi, int ivi)
  {
    byte[] compImage = imageComponents[iComp];
    int[] frameComponent = frameComponents[componentIds[iComp]];
    int hi = frameComponent[1];
    int vi = frameComponent[2];
    int compWidth = frameComponent[3];
    int srcIndex = (ymcu * vi + ivi) * compWidth * 8 + (xmcu * hi + ihi) * 8;
    int destIndex = 0;
    for (int i = 0; i < 8; i++)
    {
      for (int col = 0; col < 8; col++)
      {
        dataUnit[destIndex] = ((compImage[(srcIndex + col)] & 0xFF) - 128);
        destIndex++;
      }
      srcIndex += compWidth;
    }
  }
  
  void forwardDCT(int[] dataUnit)
  {
    for (int row = 0; row < 8; row++)
    {
      int rIndex = row * 8;
      int tmp0 = dataUnit[rIndex] + dataUnit[(rIndex + 7)];
      int tmp7 = dataUnit[rIndex] - dataUnit[(rIndex + 7)];
      int tmp1 = dataUnit[(rIndex + 1)] + dataUnit[(rIndex + 6)];
      int tmp6 = dataUnit[(rIndex + 1)] - dataUnit[(rIndex + 6)];
      int tmp2 = dataUnit[(rIndex + 2)] + dataUnit[(rIndex + 5)];
      int tmp5 = dataUnit[(rIndex + 2)] - dataUnit[(rIndex + 5)];
      int tmp3 = dataUnit[(rIndex + 3)] + dataUnit[(rIndex + 4)];
      int tmp4 = dataUnit[(rIndex + 3)] - dataUnit[(rIndex + 4)];
      
      int tmp10 = tmp0 + tmp3;
      int tmp13 = tmp0 - tmp3;
      int tmp11 = tmp1 + tmp2;
      int tmp12 = tmp1 - tmp2;
      
      dataUnit[rIndex] = ((tmp10 + tmp11) * 4);
      dataUnit[(rIndex + 4)] = ((tmp10 - tmp11) * 4);
      
      int z1 = (tmp12 + tmp13) * 4433;
      int n = z1 + tmp13 * 6270 + 1024;
      dataUnit[(rIndex + 2)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 2)] -= 1;
      }
      n = z1 + tmp12 * 50399 + 1024;
      dataUnit[(rIndex + 6)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 6)] -= 1;
      }
      z1 = tmp4 + tmp7;
      int z2 = tmp5 + tmp6;
      int z3 = tmp4 + tmp6;
      int z4 = tmp5 + tmp7;
      int z5 = (z3 + z4) * 9633;
      
      tmp4 *= 2446;
      tmp5 *= 16819;
      tmp6 *= 25172;
      tmp7 *= 12299;
      z1 *= 58163;
      z2 *= 44541;
      z3 *= 49467;
      z4 *= 62340;
      
      z3 += z5;
      z4 += z5;
      
      n = tmp4 + z1 + z3 + 1024;
      dataUnit[(rIndex + 7)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 7)] -= 1;
      }
      n = tmp5 + z2 + z4 + 1024;
      dataUnit[(rIndex + 5)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 5)] -= 1;
      }
      n = tmp6 + z2 + z3 + 1024;
      dataUnit[(rIndex + 3)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 3)] -= 1;
      }
      n = tmp7 + z1 + z4 + 1024;
      dataUnit[(rIndex + 1)] = (n >> 11);
      if ((n < 0) && ((n & 0x7FF) != 0)) {
        dataUnit[(rIndex + 1)] -= 1;
      }
    }
    for (int col = 0; col < 8; col++)
    {
      int c0 = col;
      int c1 = col + 8;
      int c2 = col + 16;
      int c3 = col + 24;
      int c4 = col + 32;
      int c5 = col + 40;
      int c6 = col + 48;
      int c7 = col + 56;
      int tmp0 = dataUnit[c0] + dataUnit[c7];
      int tmp7 = dataUnit[c0] - dataUnit[c7];
      int tmp1 = dataUnit[c1] + dataUnit[c6];
      int tmp6 = dataUnit[c1] - dataUnit[c6];
      int tmp2 = dataUnit[c2] + dataUnit[c5];
      int tmp5 = dataUnit[c2] - dataUnit[c5];
      int tmp3 = dataUnit[c3] + dataUnit[c4];
      int tmp4 = dataUnit[c3] - dataUnit[c4];
      
      int tmp10 = tmp0 + tmp3;
      int tmp13 = tmp0 - tmp3;
      int tmp11 = tmp1 + tmp2;
      int tmp12 = tmp1 - tmp2;
      
      int n = tmp10 + tmp11 + 16;
      dataUnit[c0] = (n >> 5);
      if ((n < 0) && ((n & 0x1F) != 0)) {
        dataUnit[c0] -= 1;
      }
      n = tmp10 - tmp11 + 16;
      dataUnit[c4] = (n >> 5);
      if ((n < 0) && ((n & 0x1F) != 0)) {
        dataUnit[c4] -= 1;
      }
      int z1 = (tmp12 + tmp13) * 4433;
      n = z1 + tmp13 * 6270 + 131072;
      dataUnit[c2] = (n >> 18);
      if ((n < 0) && ((n & 0x3FFFF) != 0)) {
        dataUnit[c2] -= 1;
      }
      n = z1 + tmp12 * 50399 + 131072;
      dataUnit[c6] = (n >> 18);
      if ((n < 0) && ((n & 0x3FFFF) != 0)) {
        dataUnit[c6] -= 1;
      }
      z1 = tmp4 + tmp7;
      int z2 = tmp5 + tmp6;
      int z3 = tmp4 + tmp6;
      int z4 = tmp5 + tmp7;
      int z5 = (z3 + z4) * 9633;
      
      tmp4 *= 2446;
      tmp5 *= 16819;
      tmp6 *= 25172;
      tmp7 *= 12299;
      z1 *= 58163;
      z2 *= 44541;
      z3 *= 49467;
      z4 *= 62340;
      
      z3 += z5;
      z4 += z5;
      
      n = tmp4 + z1 + z3 + 131072;
      dataUnit[c7] = (n >> 18);
      if ((n < 0) && ((n & 0x3FFFF) != 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd