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

askBits);
        for (int i = 0; i < maskData.length; i++)
        {
          int tmp910_908 = i; byte[] tmp910_906 = maskData;tmp910_906[tmp910_908] = ((byte)(tmp910_906[tmp910_908] ^ 0xFFFFFFFF));
        }
        int bpl = imageSize / height;
        for (int maskPad = 1; maskPad < 128; maskPad++)
        {
          int calcBpl = ((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad;
          if (calcBpl == bpl) {
            break;
          }
        }
        maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, 2);
      }
      OS.HeapFree(hHeap, 0, lpvBits);
      OS.SelectObject(hBitmapDC, hOldBitmap);
      if (oldPalette != 0)
      {
        OS.SelectPalette(hBitmapDC, oldPalette, false);
        OS.RealizePalette(hBitmapDC);
      }
      OS.DeleteDC(hBitmapDC);
      
      device.internal_dispose_GC(hDC, null);
      if (hbmColor != 0) {
        OS.DeleteObject(hbmColor);
      }
      if (hbmMask != 0) {
        OS.DeleteObject(hbmMask);
      }
      ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
      maskData = maskData;
      maskPad = 2;
      return imageData;
    case 0: 
      BITMAP bm = new BITMAP();
      OS.GetObject(this.handle, BITMAP.sizeof, bm);
      int depth = bmPlanes * bmBitsPixel;
      int width = bmWidth;
      int height = bmHeight;
      
      boolean isDib = bmBits != 0;
      
      int hDC = device.internal_new_GC(null);
      
      int handle = this.handle;
      if ((OS.IsWinCE) && 
        (!isDib))
      {
        boolean mustRestore = false;
        if ((memGC != null) && (!memGC.isDisposed()))
        {
          memGC.flush();
          mustRestore = true;
          GCData data = memGC.data;
          if (hNullBitmap != 0)
          {
            OS.SelectObject(memGC.handle, hNullBitmap);
            hNullBitmap = 0;
          }
        }
        handle = createDIBFromDDB(hDC, this.handle, width, height);
        if (mustRestore)
        {
          int hOldBitmap = OS.SelectObject(memGC.handle, this.handle);
          memGC.data.hNullBitmap = hOldBitmap;
        }
        isDib = true;
      }
      DIBSECTION dib = null;
      if (isDib)
      {
        dib = new DIBSECTION();
        OS.GetObject(handle, DIBSECTION.sizeof, dib);
      }
      int numColors = 0;
      if (depth <= 8) {
        if (isDib) {
          numColors = biClrUsed;
        } else {
          numColors = 1 << depth;
        }
      }
      byte[] bmi = (byte[])null;
      BITMAPINFOHEADER bmiHeader = null;
      if (!isDib)
      {
        bmiHeader = new BITMAPINFOHEADER();
        biSize = BITMAPINFOHEADER.sizeof;
        biWidth = width;
        biHeight = (-height);
        biPlanes = 1;
        biBitCount = ((short)depth);
        biCompression = 0;
        bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
        OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
      }
      int hBitmapDC = OS.CreateCompatibleDC(hDC);
      int hOldBitmap = OS.SelectObject(hBitmapDC, handle);
      
      int oldPalette = 0;
      if ((!isDib) && (depth <= 8))
      {
        int hPalette = device.hPalette;
        if (hPalette != 0)
        {
          oldPalette = OS.SelectPalette(hBitmapDC, hPalette, false);
          OS.RealizePalette(hBitmapDC);
        }
      }
      int imageSize;
      int imageSize;
      if (isDib)
      {
        imageSize = biSizeImage;
      }
      else
      {
        if (OS.IsWinCE) {
          SWT.error(20);
        }
        OS.GetDIBits(hBitmapDC, handle, 0, height, 0, bmi, 0);
        OS.MoveMemory(bmiHeader, bmi, BITMAPINFOHEADER.sizeof);
        imageSize = biSizeImage;
      }
      byte[] data = new byte[imageSize];
      if (isDib)
      {
        if ((OS.IsWinCE) && (this.handle != handle)) {
          OS.MoveMemory(data, bmBits, imageSize);
        } else {
          OS.MoveMemory(data, bmBits, imageSize);
        }
      }
      else
      {
        int hHeap = OS.GetProcessHeap();
        int lpvBits = OS.HeapAlloc(hHeap, 8, imageSize);
        if (lpvBits == 0) {
          SWT.error(2);
        }
        if (OS.IsWinCE) {
          SWT.error(20);
        }
        OS.GetDIBits(hBitmapDC, handle, 0, height, lpvBits, bmi, 0);
        OS.MoveMemory(data, lpvBits, imageSize);
        OS.HeapFree(hHeap, 0, lpvBits);
      }
      PaletteData palette = null;
      if (depth <= 8)
      {
        RGB[] rgbs = new RGB[numColors];
        if (isDib)
        {
          if (OS.IsWinCE)
          {
            int red = 0;int green = 0;int blue = 0;
            byte[] pBits = new byte[1];
            OS.MoveMemory(pBits, bmBits, 1);
            byte oldValue = pBits[0];
            int mask = 255 << 8 - bmBitsPixel & 0xFF;
            for (int i = 0; i < numColors; i++)
            {
              pBits[0] = ((byte)(i << 8 - bmBitsPixel | pBits[0] & (mask ^ 0xFFFFFFFF)));
              OS.MoveMemory(bmBits, pBits, 1);
              int color = OS.GetPixel(hBitmapDC, 0, 0);
              blue = (color & 0xFF0000) >> 16;
              green = (color & 0xFF00) >> 8;
              red = color & 0xFF;
              rgbs[i] = new RGB(red, green, blue);
            }
            pBits[0] = oldValue;
            OS.MoveMemory(bmBits, pBits, 1);
          }
          else
          {
            byte[] colors = new byte[numColors * 4];
            OS.GetDIBColorTable(hBitmapDC, 0, numColors, colors);
            int colorIndex = 0;
            for (int i = 0; i < rgbs.length; i++)
            {
              rgbs[i] = new RGB(colors[(colorIndex + 2)] & 0xFF, colors[(colorIndex + 1)] & 0xFF, colors[colorIndex] & 0xFF);
              colorIndex += 4;
            }
          }
        }
        else
        {
          int srcIndex = BITMAPINFOHEADER.sizeof;
          for (int i = 0; i < numColors; i++)
          {
            rgbs[i] = new RGB(bmi[(srcIndex + 2)] & 0xFF, bmi[(srcIndex + 1)] & 0xFF, bmi[srcIndex] & 0xFF);
            srcIndex += 4;
          }
        }
        palette = new PaletteData(rgbs);
      }
      else if (depth == 16)
      {
        palette = new PaletteData(31744, 992, 31);
      }
      else if (depth == 24)
      {
        palette = new PaletteData(255, 65280, 16711680);
      }
      else if (depth == 32)
      {
        palette = new PaletteData(65280, 16711680, -16777216);
      }
      else
      {
        SWT.error(38);
      }
      OS.SelectObject(hBitmapDC, hOldBitmap);
      if (oldPalette != 0)
      {
        OS.SelectPalette(hBitmapDC, oldPalette, false);
        OS.RealizePalette(hBitmapDC);
      }
      if ((OS.IsWinCE) && 
        (handle != this.handle)) {
        OS.DeleteObject(handle);
      }
      OS.DeleteDC(hBitmapDC);
      
      device.internal_dispose_GC(hDC, null);
      
      ImageData imageData = new ImageData(width, height, depth, palette, 4, data);
      transparentPixel = transparentPixel;
      alpha = alpha;
      if ((alpha == -1) && (alphaData != null))
      {
        alphaData = new byte[alphaData.length];
        System.arraycopy(alphaData, 0, alphaData, 0, alphaData.length);
      }
      return imageData;
    }
    SWT.error(40);
    return null;
  }
  
  public int hashCode()
  {
    return handle;
  }
  
  void init(int width, int height)
  {
    if ((width <= 0) || (height <= 0)) {
      SWT.error(5);
    }
    type = 0;
    int hDC = device.internal_new_GC(null);
    handle = OS.CreateCompatibleBitmap(hDC, width, height);
    if (handle == 0)
    {
      int bits = OS.GetDeviceCaps(hDC, 12);
      int planes = OS.GetDeviceCaps(hDC, 14);
      int depth = bits * planes;
      if (depth < 16) {
        depth = 16;
      }
      handle = createDIB(width, height, depth);
    }
    if (handle != 0)
    {
      int memDC = OS.CreateCompatibleDC(hDC);
      int hOldBitmap = OS.SelectObject(memDC, handle);
      OS.PatBlt(memDC, 0, 0, width, height, 15728673);
      OS.SelectObject(memDC, hOldBitmap);
      OS.DeleteDC(memDC);
    }
    device.internal_dispose_GC(hDC, null);
    if (handle == 0) {
      SWT.error(2, null, device.getLastError());
    }
  }
  
  static int createDIB(int width, int height, int depth)
  {
    BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
    biSize = BITMAPINFOHEADER.sizeof;
    biWidth = width;
    biHeight = (-height);
    biPlanes = 1;
    biBitCount = ((short)depth);
    if (OS.IsWinCE) {
      biCompression = 3;
    } else {
      biCompression = 0;
    }
    byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + (OS.IsWinCE ? 12 : 0)];
    OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
    if (OS.IsWinCE)
    {
      int redMask = 65280;
      int greenMask = 16711680;
      int blueMask = -16777216;
      
      int offset = BITMAPINFOHEADER.sizeof;
      bmi[offset] = ((byte)((redMask & 0xFF000000) >> 24));
      bmi[(offset + 1)] = ((byte)((redMask & 0xFF0000) >> 16));
      bmi[(offset + 2)] = ((byte)((redMask & 0xFF00) >> 8));
      bmi[(offset + 3)] = ((byte)((redMask & 0xFF) >> 0));
      bmi[(offset + 4)] = ((byte)((greenMask & 0xFF000000) >> 24));
      bmi[(offset + 5)] = ((byte)((greenMask & 0xFF0000) >> 16));
      bmi[(offset + 6)] = ((byte)((greenMask & 0xFF00) >> 8));
      bmi[(offset + 7)] = ((byte)((greenMask & 0xFF) >> 0));
      bmi[(offset + 8)] = ((byte)((blueMask & 0xFF000000) >> 24));
      bmi[(offset + 9)] = ((byte)((blueMask & 0xFF0000) >> 16));
      bmi[(offset + 10)] = ((byte)((blueMask & 0xFF00) >> 8));
      bmi[(offset + 11)] = ((byte)((blueMask & 0xFF) >> 0));
    }
    int[] pBits = new int[1];
    return OS.CreateDIBSection(0, bmi, 0, pBits, 0, 0);
  }
  
  static void GetIconInfo(Image image, ICONINFO info)
  {
    int[] result = init(device, null, data);
    hbmColor = result[0];
    hbmMask = result[1];
  }
  
  static int[] init(Device device, Image image, ImageData i)
  {
    if (((OS.IsWin95) && (depth == 1) && (i.getTransparencyType() != 2)) || (depth == 2))
    {
      ImageData img = new ImageData(width, height, 4, palette);
      ImageData.blit(1, 
        data, depth, bytesPerLine, i.getByteOrder(), 0, 0, width, height, null, null, null, 
        255, null, 0, 0, 0, 
        data, depth, bytesPerLine, i.getByteOrder(), 0, 0, width, height, null, null, null, 
        false, false);
      transparentPixel = transparentPixel;
      maskPad = maskPad;
      maskData = maskData;
      alpha = alpha;
      alphaData = alphaData;
      i = img;
    }
    if (palette.isDirect)
    {
      PaletteData palette = palette;
      int redMask = redMask;
      int greenMask = greenMask;
      int blueMask = blueMask;
      int newDepth = depth;
      int newOrder = 1;
      PaletteData newPalette = null;
      switch (depth)
      {
      case 8: 
        newDepth = 16;
        newOrder = 0;
        newPalette = new PaletteData(31744, 992, 31);
        break;
      case 16: 
        newOrder = 0;
        if ((redMask != 31744) || (greenMask != 992) || (blueMask != 31)) {
          newPalette = new PaletteData(31744, 992, 31);
        }
        break;
      case 24: 
        if ((redMask != 255) || (greenMask != 65280) || (blueMask != 16711680)) {
          newPalette = new PaletteData(255, 65280, 16711680);
        }
        break;
      case 32: 
        if ((redMask != 65280) || (greenMask != 16711680) || (blueMask != -16777216)) {
          newPalette = new PaletteData(65280, 16711680, -16777216);
        }
        break;
      default: 
        SWT.error(38);
      }
      if (newPalette != null)
      {
        ImageData img = new ImageData(width, height, newDepth, newPalette);
        ImageData.blit(1, 
          data, depth, bytesPerLine, i.getByteOrder(), 0, 0, width, height, redMask, greenMask, blueMask, 
          255, null, 0, 0, 0, 
          data, depth, bytesPerLine, newOrder, 0, 0, width, height, redMask, greenMask, blueMask, 
          false, false);
        if (transparentPixel != -1) {
          transparentPixel = newPalette.getPixel(palette.getRGB(transparentPixel));
        }
        maskPad = maskPad;
        maskData = maskData;
        alpha = alpha;
        alphaData = alphaData;
        i = img;
      }
    }
    RGB[] rgbs = palette.getRGBs();
    boolean useBitfields = (OS.IsWinCE) && ((depth == 16) || (depth == 32));
    BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
    biSize = BITMAPINFOHEADER.sizeof;
    biWidth = width;
    biHeight = (-height);
    biPlanes = 1;
    biBitCount = ((short)depth);
    if (useBitfields) {
      biCompression = 3;
    } else {
      biCompression = 0;
    }
    biClrUsed = (rgbs == null ? 0 : rgbs.length);
    byte[] bmi;
    byte[] bmi;
    if (palette.isDirect) {
      bmi = new byte[BITMAPINFOHEADER.sizeof + (useBitfields ? 12 : 0)];
    } else {
      bmi = new byte[BITMAPINFOHEADER.sizeof + rgbs.length * 4];
    }
    OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
    
    int offset = BITMAPINFOHEADER.sizeof;
    if (palette.isDirect)
    {
      if (useBitfields)
      {
        PaletteData palette = palette;
        int redMask = redMask;
        int greenMask = greenMask;
        int blueMask = blueMask;
        if (i.getByteOrder() == 0)
        {
          bmi[offset] = ((byte)((redMask & 0xFF) >> 0));
          bmi[(offset + 1)] = ((byte)((redMask & 0xFF00) >> 8));
          bmi[(offset + 2)] = ((byte)((redMask & 0xFF0000) >> 16));
          bmi[(offset + 3)] = ((byte)((redMask & 0xFF000000) >> 24));
          bmi[(offset + 4)] = ((byte)((greenMask & 0xFF) >> 0));
          bmi[(offset + 5)] = ((byte)((greenMask & 0xFF00) >> 8));
          bmi[(offset + 6)] = ((byte)((greenMask & 0xFF0000) >> 16));
          bmi[(offset + 7)] = ((byte)((greenMask & 0xFF000000) >> 24));
          bmi[(offset + 8)] = ((byte)((blueMask & 0xFF) >> 0));
          bmi[(offset + 9)] = ((byte)((blueMask & 0xFF00) >> 8));
          bmi[(offset + 10)] = ((byte)((blueMask & 0xFF0000) >> 16));
          bmi[(offset + 11)] = ((byte)((blueMask & 0xFF000000) >> 24));
        }
        else
        {
          bmi[offset] = ((byte)((redMask & 0xFF000000) >> 24));
          bmi[(offset + 1)] = ((byte)((redMask & 0xFF0000) >> 16));
          bmi[(offset + 2)] = ((byte)((redMask & 0xFF00) >> 8));
          bmi[(offset + 3)] = ((byte)((redMask & 0xFF) >> 0));
          bmi[(offset + 4)] = ((byte)((greenMask & 0xFF000000) >> 24));
          bmi[(offset + 5)] = ((byte)((greenMask & 0xFF0000) >> 16));
          bmi[(offset + 6)] = ((byte)((greenMask & 0xFF00) >> 8));
          bmi[(offset + 7)] = ((byte)((greenMask & 0xFF) >> 0));
          bmi[(offset + 8)] = ((byte)((blueMask & 0xFF000000) >> 24));
          bmi[(offset + 9)] = ((byte)((blueMask & 0xFF0000) >> 16));
          bmi[(offset + 10)] = ((byte)((blueMask & 0xFF00) >> 8));
          bmi[(offset + 11)] = ((byte)((blueMask & 0xFF) >> 0));
        }
      }
    }
    else {
      for (int j = 0; j < rgbs.length; j++)
      {
        bmi[offset] = ((byte)blue);
        bmi[(offset + 1)] = ((byte)green);
        bmi[(offset + 2)] = ((byte)red);
        bmi[(offset + 3)] = 0;
        offset += 4;
      }
    }
    int[] pBits = new int[1];
    int hDib = OS.CreateDIBSection(0, bmi, 0, pBits, 0, 0);
    if (hDib == 0) {
      SWT.error(2);
    }
    byte[] data = data;
    if ((scanlinePad != 4) && (bytesPerLine % 4 != 0)) {
      data = ImageData.convertPad(data, width, height, depth, scanlinePad, 4);
    }
    OS.MoveMemory(pBits[0], data, data.length);
    
    int[] result = (int[])null;
    if (i.getTransparencyType() == 2)
    {
      int hDC = device.internal_new_GC(null);
      
      int hdcSrc = OS.CreateCompatibleDC(hDC);
      OS.SelectObject(hdcSrc, hDib);
      int hBitmap = OS.CreateCompatibleBitmap(hDC, width, height);
      if (hBitmap == 0) {
        SWT.error(2);
      }
      int hdcDest = OS.CreateCompatibleDC(hDC);
      OS.SelectObject(hdcDest, hBitmap);
      OS.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, 13369376);
      
      device.internal_dispose_GC(hDC, null);
      
      byte[] maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, 2);
      int hMask = OS.CreateBitmap(width, height, 1, 1, maskData);
      if (hMask == 0) {
        SWT.error(2);
      }
      OS.SelectObject(hdcSrc, hMask);
      OS.PatBlt(hdcSrc, 0, 0, width, height, 5570569);
      OS.DeleteDC(hdcSrc);
      OS.DeleteDC(hdcDest);
      OS.DeleteObject(hDib);
      if (image == null)
      {
        result = new int[] { hBitmap, hMask };
      }
      else
      {
        ICONINFO info = new ICONINFO();
        fIcon = true;
        hbmColor = hBitmap;
        hbmMask = hMask;
        int hIcon = OS.CreateIconIndirect(info);
        if (hIcon == 0) {
          SWT.error(2);
        }
        OS.DeleteObject(hBitmap);
        OS.DeleteObject(hMask);
        handle = hIcon;
        type = 1;
        if (OS.IsWinCE) {
          data = i;
        }
      }
    }
    else if (image == null)
    {
      result = new int[] { hDib };
    }
    else
    {
      handle = hDib;
      type = 0;
      transparentPixel = transparentPixel;
      if (transparentPixel == -1)
      {
        alpha = alpha;
        if ((alpha == -1) && (alphaData != null))
        {
          int length = alphaData.length;
          alphaData = new byte[length];
          System.arraycopy(alphaData, 0, alphaData, 0, length);
        }
      }
    }
    return result;
  }
  
  static int[] init(Device device, Image image, ImageData source, ImageData mask)
  {
    int blackIndex = 0;
    ImageData imageData;
    ImageData imageData;
    if (palette.isDirect)
    {
      imageData = new ImageData(width, height, depth, palette);
    }
    else
    {
      RGB black = new RGB(0, 0, 0);
      RGB[] rgbs = source.getRGBs();
      if (transparentPixel != -1)
      {
        newRGBs = new RGB[rgbs.length];
        System.arraycopy(rgbs, 0, newRGBs, 0, rgbs.length);
        if (transparentPixel >= newRGBs.length)
        {
          rgbs = new RGB[transparentPixel + 1];
          System.arraycopy(newRGBs, 0, rgbs, 0, newRGBs.length);
          for (i = newRGBs.length; i <= transparentPixel; i++) {
            rgbs[i] = new RGB(0, 0, 0);
          }
        }
        else
        {
          newRGBs[transparentPixel] = black;
          rgbs = newRGBs;
        }
        blackIndex = transparentPixel;
        imageData = new ImageData(width, height, depth, new PaletteData(rgbs));
      }
      else
      {
        while (blackIndex < rgbs.length)
        {
          RGB[] newRGBs;
          int i;
          ImageData imageData;
          if (rgbs[blackIndex].equals(black)) {
            break;
          }
          blackIndex++;
        }
        if (blackIndex == rgbs.length) {
          if (1 << depth > rgbs.length)
          {
            RGB[] newRGBs = new RGB[rgbs.length + 1];
            System.arraycopy(rgbs, 0, newRGBs, 0, rgbs.length);
            newRGBs[rgbs.length] = black;
            rgbs = newRGBs;
          }
          else
          {
            blackIndex = -1;
          }
        }
        imageData = new ImageData(width, height, depth, new PaletteData(rgbs));
      }
    }
    if (blackIndex == -1)
    {
      System.arraycopy(data, 0, data, 0, data.length);
    }
    else
    {
      int[] imagePixels = new int[width];
      int[] maskPixels = new int[width];
      for (int y = 0; y < height; y++)
      {
        source.getPixels(0, y, width, imagePixels, 0);
        mask.getPixels(0, y, width, maskPixels, 0);
        for (int i = 0; i < imagePixels.length; i++) {
          if (maskPixels[i] == 0) {
            imagePixels[i] = blackIndex;
          }
        }
        imageData.setPixels(0, y, width, imagePixels, 0);
      }
    }
    maskPad = scanlinePad;
    maskData = data;
    return init(device, image, imageData);
  }
  
  void init(ImageData i)
  {
    if (i == null) {
      SWT.error(4);
    }
    init(device, this, i);
  }
  
  public int internal_new_GC(GCData data)
  {
    if (handle == 0) {
      SWT.error(44);
    }
    if ((type != 0) || (memGC != null)) {
      SWT.error(5);
    }
    int hDC = device.internal_new_GC(null);
    int imageDC = OS.CreateCompatibleDC(hDC);
    device.internal_dispose_GC(hDC, null);
    if (imageDC == 0) {
      SWT.error(2);
    }
    if (data != null)
    {
      int mask = 100663296;
      if ((style & mask) != 0) {
        layout = ((style & 0x4000000) != 0 ? 1 : 0);
      } else {
        style |= 0x2000000;
      }
      device = device;
      image = this;
      font = device.systemFont;
    }
    return imageDC;
  }
  
  public void internal_dispose_GC(int hDC, GCData data)
  {
    OS.DeleteDC(hDC);
  }
  
  public boolean isDisposed()
  {
    return handle == 0;
  }
  
  public void setBackground(Color color)
  {
    if (OS.IsWinCE) {
      return;
    }
    if (isDisposed()) {
      SWT.error(44);
    }
    if (color == null) {
      SWT.error(4);
    }
    if (color.isDisposed()) {
      SWT.error(5);
    }
    if (transparentPixel == -1) {
      return;
    }
    transparentColor = -1;
    
    int hDC = device.internal_new_GC(null);
    
    BITMAP bm = new BITMAP();
    OS.GetObject(handle, BITMAP.sizeof, bm);
    int hdcMem = OS.CreateCompatibleDC(hDC);
    OS.SelectObject(hdcMem, handle);
    int maxColors = 1 << bmBitsPixel;
    byte[] colors = new byte[maxColors * 4];
    if (OS.IsWinCE) {
      SWT.error(20);
    }
    int numColors = OS.GetDIBColorTable(hdcMem, 0, maxColors, colors);
    int offset = transparentPixel * 4;
    colors[offset] = ((byte)color.getBlue());
    colors[(offset + 1)] = ((byte)color.getGreen());
    colors[(offset + 2)] = ((byte)color.getRed());
    if (OS.IsWinCE) {
      SWT.error(20);
    }
    OS.SetDIBColorTable(hdcMem, 0, numColors, colors);
    OS.DeleteDC(hdcMem);
    
    device.internal_dispose_GC(hDC, null);
  }
  
  public String toString()
  {
    if (isDisposed()) {
      return "Image {*DISPOSED*}";
    }
    return "Image {" + handle + "}";
  }
  
  public static Image win32_new(Device device, int type, int handle)
  {
    Image image = new Image(device);
    type = type;
    handle = handle;
    return image;
  }
}

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

import java.io.InputStream;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.CloneableCompatibility;

public final class ImageData
  implements CloneableCompatibility
{
  public int width;
  public int height;
  public int depth;
  public int scanlinePad;
  public int bytesPerLine;
  public byte[] data;
  public PaletteData palette;
  public int transparentPixel;
  public byte[] maskData;
  public int maskPad;
  public byte[] alphaData;
  public int alpha;
  public int type;
  public int x;
  public int y;
  public int disposalMethod;
  public int delayTime;
  static final byte[][] ANY_TO_EIGHT = new byte[9][];
  
  static
  {
    for (int b = 0; b < 9; b++)
    {
      byte[] data = ANY_TO_EIGHT[b] = new byte[1 << b];
      if (b != 0)
      {
        int inc = 0;
        for (int bit = 65536; bit >>= b != 0; inc |= bit) {}
        int v = 0;
        for (int p = 0; v < 65536; v += inc) {
          data[(p++)] = ((byte)(v >> 8));
        }
      }
    }
  }
  
  static final byte[] ONE_TO_ONE_MAPPING = ANY_TO_EIGHT[8];
  static final int[][] DITHER_MATRIX = {
    { 16515072, 8126464, 14417920, 6029312, 15990784, 7602176, 13893632, 5505024 }, 
    { 3932160, 12320768, 1835008, 10223616, 3407872, 11796480, 1310720, 9699328 }, 
    { 13369344, 4980736, 15466496, 7077888, 12845056, 4456448, 14942208, 6553600 }, 
    { 786432, 9175040, 2883584, 11272192, 262144, 8650752, 2359296, 10747904 }, 
    { 15728640, 7340032, 13631488, 5242880, 16252928, 7864320, 14155776, 5767168 }, 
    { 3145728, 11534336, 1048576, 9437184, 3670016, 12058624, 1572864, 9961472 }, 
    { 12582912, 4194304, 14680064, 6291456, 13107200, 4718592, 15204352, 6815744 }, 
    { 0, 8388608, 2097152, 10485760, 524288, 8912896, 2621440, 11010048 } };
  static final int BLIT_SRC = 1;
  static final int BLIT_ALPHA = 2;
  static final int BLIT_DITHER = 4;
  static final int ALPHA_OPAQUE = 255;
  static final int ALPHA_TRANSPARENT = 0;
  static final int ALPHA_CHANNEL_SEPARATE = -1;
  static final int ALPHA_CHANNEL_SOURCE = -2;
  static final int ALPHA_MASK_UNPACKED = -3;
  static final int ALPHA_MASK_PACKED = -4;
  static final int ALPHA_MASK_INDEX = -5;
  static final int ALPHA_MASK_RGB = -6;
  static final int LSB_FIRST = 0;
  static final int MSB_FIRST = 1;
  private static final int TYPE_GENERIC_8 = 0;
  private static final int TYPE_GENERIC_16_MSB = 1;
  private static final int TYPE_GENERIC_16_LSB = 2;
  private static final int TYPE_GENERIC_24 = 3;
  private static final int TYPE_GENERIC_32_MSB = 4;
  private static final int TYPE_GENERIC_32_LSB = 5;
  private static final int TYPE_INDEX_8 = 6;
  private static final int TYPE_INDEX_4 = 7;
  private static final int TYPE_INDEX_2 = 8;
  private static final int TYPE_INDEX_1_MSB = 9;
  private static final int TYPE_INDEX_1_LSB = 10;
  
  public ImageData(int width, int height, int depth, PaletteData palette)
  {
    this(width, height, depth, palette, 4, null, 0, null, null, -1, -1, -1, 0, 0, 0, 0);
  }
  
  public ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data)
  {
    this(width, height, depth, palette, scanlinePad, checkData(data), 0, null, null, -1, -1, -1, 0, 0, 0, 0);
  }
  
  public ImageData(InputStream stream)
  {
    ImageData[] data = ImageDataLoader.load(stream);
    if (data.length < 1) {
      SWT.error(40);
    }
    ImageData i = data[0];
    setAllFields(
      width, 
      height, 
      depth, 
      scanlinePad, 
      bytesPerLine, 
      data, 
      palette, 
      transparentPixel, 
      maskData, 
      maskPad, 
      alphaData, 
      alpha, 
      type, 
      x, 
      y, 
      disposalMethod, 
      delayTime);
  }
  
  public ImageData(String filename)
  {
    ImageData[] data = ImageDataLoader.load(filename);
    if (data.length < 1) {
      SWT.error(40);
    }
    ImageData i = data[0];
    setAllFields(
      width, 
      height, 
      depth, 
      scanlinePad, 
      bytesPerLine, 
      data, 
      palette, 
      transparentPixel, 
      maskData, 
      maskPad, 
      alphaData, 
      alpha, 
      type, 
      x, 
      y, 
      disposalMethod, 
      delayTime);
  }
  
  ImageData() {}
  
  ImageData(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime)
  {
    if (palette == null) {
      SWT.error(4);
    }
    if ((depth != 1) && (depth != 2) && (depth != 4) && (depth != 8) && 
      (depth != 16) && (depth != 24) && (depth != 32)) {
      SWT.error(5);
    }
    if ((width <= 0) || (height <= 0)) {
      SWT.error(5);
    }
    if (scanlinePad == 0) {
      SWT.error(7);
    }
    int bytesPerLine = ((width * depth + 7) / 8 + (scanlinePad - 1)) / 
      scanlinePad * scanlinePad;
    
    int minBytesPerLine = type == 5 ? ((width + 7) / 8 + 3) / 4 * 4 : bytesPerLine;
    if ((data != null) && (data.length < minBytesPerLine * height)) {
      SWT.error(5);
    }
    setAllFields(
      width, 
      height, 
      depth, 
      scanlinePad, 
      bytesPerLine, 
      data != null ? data : new byte[bytesPerLine * height], 
      palette, 
      transparentPixel, 
      maskData, 
      maskPad, 
      alphaData, 
      alpha, 
      type, 
      x, 
      y, 
      disposalMethod, 
      delayTime);
  }
  
  void setAllFields(int width, int height, int depth, int scanlinePad, int bytesPerLine, byte[] data, PaletteData palette, int transparentPixel, byte[] maskData, int maskPad, byte[] alphaData, int alpha, int type, int x, int y, int disposalMethod, int delayTime)
  {
    this.width = width;
    this.height = height;
    this.depth = depth;
    this.scanlinePad = scanlinePad;
    this.bytesPerLine = bytesPerLine;
    this.data = data;
    this.palette = palette;
    this.transparentPixel = transparentPixel;
    this.maskData = maskData;
    this.maskPad = maskPad;
    this.alphaData = alphaData;
    this.alpha = alpha;
    this.type = type;
    this.x = x;
    this.y = y;
    this.disposalMethod = disposalMethod;
    this.delayTime = delayTime;
  }
  
  public static ImageData internal_new(int width, int height, int depth, PaletteData palette, int scanlinePad, byte[] data, int maskPad, byte[] maskData, byte[] alphaData, int alpha, int transparentPixel, int type, int x, int y, int disposalMethod, int delayTime)
  {
    return new ImageData(
      width, height, depth, palette, scanlinePad, data, maskPad, maskData, 
      alphaData, alpha, transparentPixel, type, x, y, disposalMethod, delayTime);
  }
  
  ImageData colorMaskImage(int pixel)
  {
    ImageData mask = new ImageData(width, height, 1, bwPalette(), 
      2, null, 0, null, null, -1, -1, -1, 
      0, 0, 0, 0);
    int[] row = new int[width];
    for (int y = 0; y < height; y++)
    {
      getPixels(0, y, width, row, 0);
      for (int i = 0; i < width; i++) {
        if ((pixel != -1) && (row[i] == pixel)) {
          row[i] = 0;
        } else {
          row[i] = 1;
        }
      }
      mask.setPixels(0, y, width, row, 0);
    }
    return mask;
  }
  
  static byte[] checkData(byte[] data)
  {
    if (data == null) {
      SWT.error(4);
    }
    return data;
  }
  
  public Object clone()
  {
    byte[] cloneData = new byte[data.length];
    System.arraycopy(data, 0, cloneData, 0, data.length);
    byte[] cloneMaskData = (byte[])null;
    if (maskData != null)
    {
      cloneMaskData = new byte[maskData.length];
      System.arraycopy(maskData, 0, cloneMaskData, 0, maskData.length);
    }
    byte[] cloneAlphaData = (byte[])null;
    if (alphaData != null)
    {
      cloneAlphaData = new byte[alphaData.length];
      System.arraycopy(alphaData, 0, cloneAlphaData, 0, alphaData.length);
    }
    return new ImageData(
      width, 
      height, 
      depth, 
      palette, 
      scanlinePad, 
      cloneData, 
      maskPad, 
      cloneMaskData, 
      cloneAlphaData, 
      alpha, 
      transparentPixel, 
      type, 
      x, 
      y, 
      disposalMethod, 
      delayTime);
  }
  
  public int getAlpha(int x, int y)
  {
    if ((x >= width) || (y >= height) || (x < 0) || (y < 0)) {
      SWT.error(5);
    }
    if (alphaData == null) {
      return 255;
    }
    return alphaData[(y * width + x)] & 0xFF;
  }
  
  public void getAlphas(int x, int y, int getWidth, byte[] alphas, int startIndex)
  {
    if (alphas == null) {
      SWT.error(4);
    }
    if ((getWidth < 0) || (x >= width) || (y >= height) || (x < 0) || (y < 0)) {
      SWT.error(5);
    }
    if (getWidth == 0) {
      return;
    }
    if (alphaData == null)
    {
      int endIndex = startIndex + getWidth;
      for (int i = startIndex; i < endIndex; i++) {
        alphas[i] = -1;
      }
      return;
    }
    System.arraycopy(alphaData, y * width + x, alphas, startIndex, getWidth);
  }
  
  public int getPixel(int x, int y)
  {
    if ((x >= width) || (y >= height) || (x < 0) || (y < 0)) {
      SWT.error(5);
    }
    switch (depth)
    {
    case 32: 
      int index = y * bytesPerLine + x * 4;
      return ((data[index] & 0xFF) << 24) + ((data[(index + 1)] & 0xFF) << 16) + (
        (data[(index + 2)] & 0xFF) << 8) + (data[(index + 3)] & 0xFF);
    case 24: 
      int index = y * bytesPerLine + x * 3;
      return ((data[index] & 0xFF) << 16) + ((data[(index + 1)] & 0xFF) << 8) + (
        data[(index + 2)] & 0xFF);
    case 16: 
      int index = y * bytesPerLine + x * 2;
      return ((data[(index + 1)] & 0xFF) << 8) + (data[index] & 0xFF);
    case 8: 
      int index = y * bytesPerLine + x;
      return data[index] & 0xFF;
    case 4: 
      int index = y * bytesPerLine + (x >> 1);
      int theByte = data[index] & 0xFF;
      if ((x & 0x1) == 0) {
        return theByte >> 4;
      }
      return theByte & 0xF;
    case 2: 
      int index = y * bytesPerLine + (x >> 2);
      int theByte = data[index] & 0xFF;
      int offset = 3 - x % 4;
      int mask = 3 << offset * 2;
      return (theByte & mask) >> offset * 2;
    case 1: 
      int index = y * bytesPerLine + (x >> 3);
      int theByte = data[index] & 0xFF;
      int mask = 1 << 7 - (x & 0x7);
      if ((theByte & mask) == 0) {
        return 0;
      }
      return 1;
    }
    SWT.error(38);
    return 0;
  }
  
  public void getPixels(int x, int y, int getWidth, byte[] pixels, int startIndex)
  {
    if (pixels == null) {
      SWT.error(4);
    }
    if ((getWidth < 0) || (x >= width) || (y >= height) || (x < 0) || (y < 0)) {
      SWT.error(5);
    }
    if (getWidth == 0) {
      return;
    }
    int mask = 0;
    int n = getWidth;
    int i = startIndex;
    int srcX = x;int srcY = y;
    switch (depth)
    {
    case 8: 
      int index = y * bytesPerLine + x;
      for (int j = 0; j < getWidth; j++)
      {
        pixels[i] = data[index];
        i++;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index++;
        }
      }
      return;
    case 4: 
      int index = y * bytesPerLine + (x >> 1);
      if ((x & 0x1) == 1)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = ((byte)(theByte & 0xF));
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index++;
        }
      }
      while (n > 1)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = ((byte)(theByte >> 4));
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          pixels[i] = ((byte)(theByte & 0xF));
          i++;
          n--;
          srcX++;
          if (srcX >= width)
          {
            srcY++;
            index = srcY * bytesPerLine;
            srcX = 0;
          }
          else
          {
            index++;
          }
        }
      }
      if (n > 0)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = ((byte)(theByte >> 4));
      }
      return;
    case 2: 
      int index = y * bytesPerLine + (x >> 2);
      int theByte = data[index] & 0xFF;
      while (n > 0)
      {
        int offset = 3 - srcX % 4;
        mask = 3 << offset * 2;
        pixels[i] = ((byte)((theByte & mask) >> offset * 2));
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          if (n > 0) {
            theByte = data[index] & 0xFF;
          }
          srcX = 0;
        }
        else if (offset == 0)
        {
          index++;
          theByte = data[index] & 0xFF;
        }
      }
      return;
    case 1: 
      int index = y * bytesPerLine + (x >> 3);
      int theByte = data[index] & 0xFF;
      while (n > 0)
      {
        mask = 1 << 7 - (srcX & 0x7);
        if ((theByte & mask) == 0) {
          pixels[i] = 0;
        } else {
          pixels[i] = 1;
        }
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          if (n > 0) {
            theByte = data[index] & 0xFF;
          }
          srcX = 0;
        }
        else if (mask == 1)
        {
          index++;
          if (n > 0) {
            theByte = data[index] & 0xFF;
          }
        }
      }
      return;
    }
    SWT.error(38);
  }
  
  public void getPixels(int x, int y, int getWidth, int[] pixels, int startIndex)
  {
    if (pixels == null) {
      SWT.error(4);
    }
    if ((getWidth < 0) || (x >= width) || (y >= height) || (x < 0) || (y < 0)) {
      SWT.error(5);
    }
    if (getWidth == 0) {
      return;
    }
    int n = getWidth;
    int i = startIndex;
    int srcX = x;int srcY = y;
    switch (depth)
    {
    case 32: 
      int index = y * bytesPerLine + x * 4;
      i = startIndex;
      for (int j = 0; j < getWidth; j++)
      {
        pixels[i] = 
          ((data[index] & 0xFF) << 24 | (data[(index + 1)] & 0xFF) << 16 | (data[(index + 2)] & 0xFF) << 8 | data[(index + 3)] & 0xFF);
        i++;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index += 4;
        }
      }
      return;
    case 24: 
      int index = y * bytesPerLine + x * 3;
      for (int j = 0; j < getWidth; j++)
      {
        pixels[i] = 
          ((data[index] & 0xFF) << 16 | (data[(index + 1)] & 0xFF) << 8 | data[(index + 2)] & 0xFF);
        i++;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index += 3;
        }
      }
      return;
    case 16: 
      int index = y * bytesPerLine + x * 2;
      for (int j = 0; j < getWidth; j++)
      {
        pixels[i] = (((data[(index + 1)] & 0xFF) << 8) + (data[index] & 0xFF));
        i++;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index += 2;
        }
      }
      return;
    case 8: 
      int index = y * bytesPerLine + x;
      for (int j = 0; j < getWidth; j++)
      {
        pixels[i] = (data[index] & 0xFF);
        i++;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index++;
        }
      }
      return;
    case 4: 
      int index = y * bytesPerLine + (x >> 1);
      if ((x & 0x1) == 1)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = (theByte & 0xF);
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          index++;
        }
      }
      while (n > 1)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = (theByte >> 4);
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          srcX = 0;
        }
        else
        {
          pixels[i] = (theByte & 0xF);
          i++;
          n--;
          srcX++;
          if (srcX >= width)
          {
            srcY++;
            index = srcY * bytesPerLine;
            srcX = 0;
          }
          else
          {
            index++;
          }
        }
      }
      if (n > 0)
      {
        int theByte = data[index] & 0xFF;
        pixels[i] = (theByte >> 4);
      }
      return;
    case 2: 
      int index = y * bytesPerLine + (x >> 2);
      int theByte = data[index] & 0xFF;
      while (n > 0)
      {
        int offset = 3 - srcX % 4;
        int mask = 3 << offset * 2;
        pixels[i] = ((byte)((theByte & mask) >> offset * 2));
        i++;
        n--;
        srcX++;
        if (srcX >= width)
        {
          srcY++;
          index = srcY * bytesPerLine;
          if (n > 0) {
            theByte = data[index] & 0xFF;
          }
          srcX = 0;
        }
        else if (offset == 0)
        {
          index++;
          theByte = data[index] & 0xFF;
        }
      }
      return;
    case 1: 
      int index = y * bytesPerLine + (x >> 3);
      int theByte = data[index] & 0xFF;
      while (n > 0)
      {
        int mask = 1 << 7 - (srcX & 0x7);
        if ((theByte & mask) == 0) {
          pixels[i] = 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