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

7) & 0x1)];
            sp += (sfx >>> 16);
            int shift = dp & 0x7;
            destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | index << shift));dx--;dp += dprxi;
          }
          dy--;sp = spr += (sfy >>> 16) * srcStride;sfy = (sfy & 0xFFFF) + sfyi;
        }
      default: 
        break;int dy = destHeight;
        for (int sfy = sfyi; dy > 0;)
        {
          int dx = destWidth;
          for (int sfx = sfxi; dx > 0;)
          {
            switch (stype)
            {
            case 6: 
              int index = srcData[sp] & 0xFF;
              sp += (sfx >>> 16);
              break;
            case 7: 
              int index;
              int index;
              if ((sp & 0x1) != 0) {
                index = srcData[(sp >> 1)] & 0xF;
              } else {
                index = srcData[(sp >> 1)] >>> 4 & 0xF;
              }
              sp += (sfx >>> 16);
              break;
            case 8: 
              int index = srcData[(sp >> 2)] >>> 6 - (sp & 0x3) * 2 & 0x3;
              sp += (sfx >>> 16);
              break;
            case 9: 
              int index = srcData[(sp >> 3)] >>> 7 - (sp & 0x7) & 0x1;
              sp += (sfx >>> 16);
              break;
            case 10: 
              int index = srcData[(sp >> 3)] >>> (sp & 0x7) & 0x1;
              sp += (sfx >>> 16);
              break;
            default: 
              return;
            }
            switch (alphaMode)
            {
            case -3: 
              byte mask = alphaData[ap];
              ap += (sfx >> 16);
              if (mask != 0) {
                break;
              }
              break;
            case -4: 
              int mask = alphaData[(ap >> 3)] & 1 << (ap & 0x7);
              ap += (sfx >> 16);
              if (mask != 0) {
                break;
              }
              break;
            case -5: 
              int i = 0;
              while (i < alphaData.length) {
                if (index == (alphaData[i] & 0xFF)) {
                  break;
                }
              }
              if (i >= alphaData.length) {
                break;
              }
              break;
            case -6: 
              byte r = srcReds[index];byte g = srcGreens[index];byte b = srcBlues[index];
              int i = 0;
              while (i < alphaData.length)
              {
                if ((r == alphaData[i]) && (g == alphaData[(i + 1)]) && (b == alphaData[(i + 2)])) {
                  break;
                }
                i += 3;
              }
              if (i < alphaData.length) {
                break label2463;
              }
            }
            int index = paletteMapping[index] & 0xFF;
            switch (dtype)
            {
            case 6: 
              destData[dp] = ((byte)index);
              break;
            case 7: 
              if ((dp & 0x1) != 0) {
                destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF0 | index));
              } else {
                destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF | index << 4));
              }
              break;
            case 8: 
              int shift = 6 - (dp & 0x3) * 2;
              destData[(dp >> 2)] = ((byte)(destData[(dp >> 2)] & (3 << shift ^ 0xFFFFFFFF) | index << shift));
              break;
            case 9: 
              int shift = 7 - (dp & 0x7);
              destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | index << shift));
              break;
            case 10: 
              int shift = dp & 0x7;
              destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | index << shift));
            }
            label2463:
            dx--;
            dp += dprxi;
            sfx = (sfx & 0xFFFF) + sfxi;
          }
          dy--;
          sp = spr += (sfy >>> 16) * srcStride;
          sfy = (sfy & 0xFFFF) + sfyi;
          dp = dpr += dpryi;
        }
      }
      return;
    }
    int alpha = alphaMode;
    int index = 0;
    int indexq = 0;
    int lastindex = 0;int lastr = -1;int lastg = -1;int lastb = -1;
    int[] berr;
    int[] rerr;
    int[] gerr;
    int[] berr;
    if (ditherEnabled)
    {
      int[] rerr = new int[destWidth + 2];
      int[] gerr = new int[destWidth + 2];
      berr = new int[destWidth + 2];
    }
    else
    {
      rerr = (int[])null;gerr = (int[])null;berr = (int[])null;
    }
    int dy = destHeight;
    for (int sfy = sfyi; dy > 0;)
    {
      int lrerr = 0;int lgerr = 0;int lberr = 0;
      int dx = destWidth;
      for (int sfx = sfxi; dx > 0;)
      {
        switch (stype)
        {
        case 6: 
          index = srcData[sp] & 0xFF;
          sp += (sfx >>> 16);
          break;
        case 7: 
          if ((sp & 0x1) != 0) {
            index = srcData[(sp >> 1)] & 0xF;
          } else {
            index = srcData[(sp >> 1)] >>> 4 & 0xF;
          }
          sp += (sfx >>> 16);
          break;
        case 8: 
          index = srcData[(sp >> 2)] >>> 6 - (sp & 0x3) * 2 & 0x3;
          sp += (sfx >>> 16);
          break;
        case 9: 
          index = srcData[(sp >> 3)] >>> 7 - (sp & 0x7) & 0x1;
          sp += (sfx >>> 16);
          break;
        case 10: 
          index = srcData[(sp >> 3)] >>> (sp & 0x7) & 0x1;
          sp += (sfx >>> 16);
        }
        int r = srcReds[index] & 0xFF;int g = srcGreens[index] & 0xFF;int b = srcBlues[index] & 0xFF;
        switch (alphaMode)
        {
        case -1: 
          alpha = ((alphaData[ap] & 0xFF) << 16) / 255;
          ap += (sfx >> 16);
          break;
        case -3: 
          alpha = alphaData[ap] != 0 ? 65536 : 0;
          ap += (sfx >> 16);
          break;
        case -4: 
          alpha = alphaData[(ap >> 3)] << (ap & 0x7) + 9 & 0x10000;
          ap += (sfx >> 16);
          break;
        case -5: 
          int i = 0;
          while (i < alphaData.length) {
            if (index == (alphaData[i] & 0xFF)) {
              break;
            }
          }
          if (i >= alphaData.length) {
            break;
          }
          break;
        case -6: 
          int i = 0;
          while (i < alphaData.length)
          {
            if ((r == (alphaData[i] & 0xFF)) && 
              (g == (alphaData[(i + 1)] & 0xFF)) && 
              (b == (alphaData[(i + 2)] & 0xFF))) {
              break;
            }
            i += 3;
          }
          if (i < alphaData.length) {
            break label4083;
          }
        }
        if (alpha != 65536)
        {
          if (alpha != 0)
          {
            switch (dtype)
            {
            case 6: 
              indexq = destData[dp] & 0xFF;
              break;
            case 7: 
              if ((dp & 0x1) != 0) {
                indexq = destData[(dp >> 1)] & 0xF;
              } else {
                indexq = destData[(dp >> 1)] >>> 4 & 0xF;
              }
              break;
            case 8: 
              indexq = destData[(dp >> 2)] >>> 6 - (dp & 0x3) * 2 & 0x3;
              break;
            case 9: 
              indexq = destData[(dp >> 3)] >>> 7 - (dp & 0x7) & 0x1;
              break;
            case 10: 
              indexq = destData[(dp >> 3)] >>> (dp & 0x7) & 0x1;
            }
            int rq = destReds[indexq] & 0xFF;
            int gq = destGreens[indexq] & 0xFF;
            int bq = destBlues[indexq] & 0xFF;
            r = rq + ((r - rq) * alpha >> 16);
            g = gq + ((g - gq) * alpha >> 16);
            b = bq + ((b - bq) * alpha >> 16);
          }
        }
        else
        {
          if (ditherEnabled)
          {
            r += (rerr[dx] >> 4);
            if (r < 0) {
              r = 0;
            } else if (r > 255) {
              r = 255;
            }
            g += (gerr[dx] >> 4);
            if (g < 0) {
              g = 0;
            } else if (g > 255) {
              g = 255;
            }
            b += (berr[dx] >> 4);
            if (b < 0) {
              b = 0;
            } else if (b > 255) {
              b = 255;
            }
            rerr[dx] = lrerr;
            gerr[dx] = lgerr;
            berr[dx] = lberr;
          }
          if ((r != lastr) || (g != lastg) || (b != lastb))
          {
            int j = 0;
            for (int minDistance = Integer.MAX_VALUE; j < destPaletteSize; j++)
            {
              int dr = (destReds[j] & 0xFF) - r;
              int dg = (destGreens[j] & 0xFF) - g;
              int db = (destBlues[j] & 0xFF) - b;
              int distance = dr * dr + dg * dg + db * db;
              if (distance < minDistance)
              {
                lastindex = j;
                if (distance == 0) {
                  break;
                }
                minDistance = distance;
              }
            }
            lastr = r;lastg = g;lastb = b;
          }
          if (ditherEnabled)
          {
            int dxm1 = dx - 1;int dxp1 = dx + 1;
            int acc;
            rerr[dxp1] += (acc = (lrerr = r - (destReds[lastindex] & 0xFF)) + lrerr + lrerr);
            rerr[dx] += acc += lrerr + lrerr;
            rerr[dxm1] += acc + lrerr + lrerr;
            gerr[dxp1] += (acc = (lgerr = g - (destGreens[lastindex] & 0xFF)) + lgerr + lgerr);
            gerr[dx] += acc += lgerr + lgerr;
            gerr[dxm1] += acc + lgerr + lgerr;
            berr[dxp1] += (acc = (lberr = b - (destBlues[lastindex] & 0xFF)) + lberr + lberr);
            berr[dx] += acc += lberr + lberr;
            berr[dxm1] += acc + lberr + lberr;
          }
          switch (dtype)
          {
          case 6: 
            destData[dp] = ((byte)lastindex);
            break;
          case 7: 
            if ((dp & 0x1) != 0) {
              destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF0 | lastindex));
            } else {
              destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF | lastindex << 4));
            }
            break;
          case 8: 
            int shift = 6 - (dp & 0x3) * 2;
            destData[(dp >> 2)] = ((byte)(destData[(dp >> 2)] & (3 << shift ^ 0xFFFFFFFF) | lastindex << shift));
            break;
          case 9: 
            int shift = 7 - (dp & 0x7);
            destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | lastindex << shift));
            break;
          case 10: 
            int shift = dp & 0x7;
            destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | lastindex << shift));
          }
        }
        label4083:
        dx--;
        dp += dprxi;
        sfx = (sfx & 0xFFFF) + sfxi;
      }
      dy--;
      sp = spr += (sfy >>> 16) * srcStride;
      ap = apr += (sfy >>> 16) * alphaStride;
      sfy = (sfy & 0xFFFF) + sfyi;
      dp = dpr += dpryi;
    }
  }
  
  static void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, byte[] srcReds, byte[] srcGreens, byte[] srcBlues, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, int destRedMask, int destGreenMask, int destBlueMask, boolean flipX, boolean flipY)
  {
    if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == 0)) {
      return;
    }
    if ((srcX == 0) && (srcY == 0) && (destX == 0) && (destY == 0) && (destWidth == srcWidth) && (destHeight == srcHeight))
    {
      if ((destDepth == 24) && (srcDepth == 8) && ((op & 0x2) == 0) && (destRedMask == 16711680) && (destGreenMask == 65280) && (destBlueMask == 255))
      {
        int y = 0;int sp = 0;int dp = 0;int spad = srcStride - srcWidth;
        for (int dpad = destStride - destWidth * 3; y < destHeight; dp += dpad)
        {
          for (int x = 0; x < destWidth; x++)
          {
            int index = srcData[(sp++)] & 0xFF;
            destData[(dp++)] = srcReds[index];
            destData[(dp++)] = srcGreens[index];
            destData[(dp++)] = srcBlues[index];
          }
          y++;sp += spad;
        }
        return;
      }
      if ((destDepth == 32) && (destOrder == 1) && (srcDepth == 8) && ((op & 0x2) == 0) && (destRedMask == 16711680) && (destGreenMask == 65280) && (destBlueMask == 255))
      {
        int y = 0;int sp = 0;int dp = 0;int spad = srcStride - srcWidth;
        for (int dpad = destStride - destWidth * 4; y < destHeight; dp += dpad)
        {
          for (int x = 0; x < destWidth; x++)
          {
            int index = srcData[(sp++)] & 0xFF;
            dp++;
            destData[(dp++)] = srcReds[index];
            destData[(dp++)] = srcGreens[index];
            destData[(dp++)] = srcBlues[index];
          }
          y++;sp += spad;
        }
        return;
      }
    }
    int dwm1 = destWidth - 1;
    int sfxi = dwm1 != 0 ? (int)(((srcWidth << 16) - 1L) / dwm1) : 0;
    int dhm1 = destHeight - 1;
    int sfyi = dhm1 != 0 ? (int)(((srcHeight << 16) - 1L) / dhm1) : 0;
    int stype;
    int stype;
    int stype;
    int stype;
    switch (srcDepth)
    {
    case 8: 
      stype = 6;
      break;
    case 4: 
      srcStride <<= 1;
      stype = 7;
      break;
    case 2: 
      srcStride <<= 2;
      stype = 8;
      break;
    case 1: 
      srcStride <<= 3;
      stype = srcOrder == 1 ? 9 : 10;
      break;
    case 3: 
    case 5: 
    case 6: 
    case 7: 
    default: 
      return;
    }
    int stype;
    int spr = srcY * srcStride + srcX;
    int dtype;
    int dtype;
    int dtype;
    int dtype;
    switch (destDepth)
    {
    case 8: 
      int dbpp = 1;
      dtype = 0;
      break;
    case 16: 
      int dbpp = 2;
      dtype = destOrder == 1 ? 1 : 2;
      break;
    case 24: 
      int dbpp = 3;
      dtype = 3;
      break;
    case 32: 
      int dbpp = 4;
      dtype = destOrder == 1 ? 4 : 5;
      break;
    default: 
      return;
    }
    int dtype;
    int dbpp;
    int dpr = (flipY ? destY + dhm1 : destY) * destStride + (flipX ? destX + dwm1 : destX) * dbpp;
    int dprxi = flipX ? -dbpp : dbpp;
    int dpryi = flipY ? -destStride : destStride;
    int apr;
    if ((op & 0x2) != 0)
    {
      int apr;
      int apr;
      int apr;
      int apr;
      switch (alphaMode)
      {
      case -3: 
      case -1: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        apr = alphaY * alphaStride + alphaX;
        break;
      case -4: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        alphaStride <<= 3;
        apr = alphaY * alphaStride + alphaX;
        break;
      case -6: 
      case -5: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        apr = 0;
        break;
      default: 
        alphaMode = (alphaMode << 16) / 255;
      case -2: 
        apr = 0;
        break;
      }
    }
    else
    {
      alphaMode = 65536;
      apr = 0;
    }
    int destRedShift = getChannelShift(destRedMask);
    int destRedWidth = getChannelWidth(destRedMask, destRedShift);
    byte[] destReds = ANY_TO_EIGHT[destRedWidth];
    int destRedPreShift = 8 - destRedWidth;
    int destGreenShift = getChannelShift(destGreenMask);
    int destGreenWidth = getChannelWidth(destGreenMask, destGreenShift);
    byte[] destGreens = ANY_TO_EIGHT[destGreenWidth];
    int destGreenPreShift = 8 - destGreenWidth;
    int destBlueShift = getChannelShift(destBlueMask);
    int destBlueWidth = getChannelWidth(destBlueMask, destBlueShift);
    byte[] destBlues = ANY_TO_EIGHT[destBlueWidth];
    int destBluePreShift = 8 - destBlueWidth;
    int destAlphaShift = getChannelShift(0);
    int destAlphaWidth = getChannelWidth(0, destAlphaShift);
    byte[] destAlphas = ANY_TO_EIGHT[destAlphaWidth];
    int destAlphaPreShift = 8 - destAlphaWidth;
    
    int dp = dpr;
    int sp = spr;
    int ap = apr;int alpha = alphaMode;
    int r = 0;int g = 0;int b = 0;int a = 0;int index = 0;
    int rq = 0;int gq = 0;int bq = 0;int aq = 0;
    int dy = destHeight;
    for (int sfy = sfyi; dy > 0;)
    {
      int dx = destWidth;
      for (int sfx = sfxi; dx > 0;)
      {
        switch (stype)
        {
        case 6: 
          index = srcData[sp] & 0xFF;
          sp += (sfx >>> 16);
          break;
        case 7: 
          if ((sp & 0x1) != 0) {
            index = srcData[(sp >> 1)] & 0xF;
          } else {
            index = srcData[(sp >> 1)] >>> 4 & 0xF;
          }
          sp += (sfx >>> 16);
          break;
        case 8: 
          index = srcData[(sp >> 2)] >>> 6 - (sp & 0x3) * 2 & 0x3;
          sp += (sfx >>> 16);
          break;
        case 9: 
          index = srcData[(sp >> 3)] >>> 7 - (sp & 0x7) & 0x1;
          sp += (sfx >>> 16);
          break;
        case 10: 
          index = srcData[(sp >> 3)] >>> (sp & 0x7) & 0x1;
          sp += (sfx >>> 16);
        }
        r = srcReds[index] & 0xFF;
        g = srcGreens[index] & 0xFF;
        b = srcBlues[index] & 0xFF;
        switch (alphaMode)
        {
        case -1: 
          alpha = ((alphaData[ap] & 0xFF) << 16) / 255;
          ap += (sfx >> 16);
          break;
        case -3: 
          alpha = alphaData[ap] != 0 ? 65536 : 0;
          ap += (sfx >> 16);
          break;
        case -4: 
          alpha = alphaData[(ap >> 3)] << (ap & 0x7) + 9 & 0x10000;
          ap += (sfx >> 16);
          break;
        case -5: 
          int i = 0;
          while (i < alphaData.length) {
            if (index == (alphaData[i] & 0xFF)) {
              break;
            }
          }
          if (i >= alphaData.length) {
            break;
          }
          break;
        case -6: 
          int i = 0;
          while (i < alphaData.length)
          {
            if ((r == (alphaData[i] & 0xFF)) && 
              (g == (alphaData[(i + 1)] & 0xFF)) && 
              (b == (alphaData[(i + 2)] & 0xFF))) {
              break;
            }
            i += 3;
          }
          if (i < alphaData.length) {
            break label2553;
          }
        }
        if (alpha != 65536)
        {
          if (alpha != 0)
          {
            switch (dtype)
            {
            case 0: 
              int data = destData[dp] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
              break;
            case 1: 
              int data = (destData[dp] & 0xFF) << 8 | destData[(dp + 1)] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
              break;
            case 2: 
              int data = (destData[(dp + 1)] & 0xFF) << 8 | destData[dp] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
              break;
            case 3: 
              int data = ((destData[dp] & 0xFF) << 8 | 
                destData[(dp + 1)] & 0xFF) << 8 | 
                destData[(dp + 2)] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
              break;
            case 4: 
              int data = (((destData[dp] & 0xFF) << 8 | 
                destData[(dp + 1)] & 0xFF) << 8 | 
                destData[(dp + 2)] & 0xFF) << 8 | 
                destData[(dp + 3)] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
              break;
            case 5: 
              int data = (((destData[(dp + 3)] & 0xFF) << 8 | 
                destData[(dp + 2)] & 0xFF) << 8 | 
                destData[(dp + 1)] & 0xFF) << 8 | 
                destData[dp] & 0xFF;
              rq = destReds[((data & destRedMask) >>> destRedShift)] & 0xFF;
              gq = destGreens[((data & destGreenMask) >>> destGreenShift)] & 0xFF;
              bq = destBlues[((data & destBlueMask) >>> destBlueShift)] & 0xFF;
              aq = destAlphas[(0 >>> destAlphaShift)] & 0xFF;
            }
            a = aq + ((a - aq) * alpha >> 16);
            r = rq + ((r - rq) * alpha >> 16);
            g = gq + ((g - gq) * alpha >> 16);
            b = bq + ((b - bq) * alpha >> 16);
          }
        }
        else
        {
          int data = 
            r >>> destRedPreShift << destRedShift | 
            g >>> destGreenPreShift << destGreenShift | 
            b >>> destBluePreShift << destBlueShift | 
            a >>> destAlphaPreShift << destAlphaShift;
          switch (dtype)
          {
          case 0: 
            destData[dp] = ((byte)data);
            break;
          case 1: 
            destData[dp] = ((byte)(data >>> 8));
            destData[(dp + 1)] = ((byte)(data & 0xFF));
            break;
          case 2: 
            destData[dp] = ((byte)(data & 0xFF));
            destData[(dp + 1)] = ((byte)(data >>> 8));
            break;
          case 3: 
            destData[dp] = ((byte)(data >>> 16));
            destData[(dp + 1)] = ((byte)(data >>> 8));
            destData[(dp + 2)] = ((byte)(data & 0xFF));
            break;
          case 4: 
            destData[dp] = ((byte)(data >>> 24));
            destData[(dp + 1)] = ((byte)(data >>> 16));
            destData[(dp + 2)] = ((byte)(data >>> 8));
            destData[(dp + 3)] = ((byte)(data & 0xFF));
            break;
          case 5: 
            destData[dp] = ((byte)(data & 0xFF));
            destData[(dp + 1)] = ((byte)(data >>> 8));
            destData[(dp + 2)] = ((byte)(data >>> 16));
            destData[(dp + 3)] = ((byte)(data >>> 24));
          }
        }
        label2553:
        dx--;
        dp += dprxi;
        sfx = (sfx & 0xFFFF) + sfxi;
      }
      dy--;
      sp = spr += (sfy >>> 16) * srcStride;
      ap = apr += (sfy >>> 16) * alphaStride;
      sfy = (sfy & 0xFFFF) + sfyi;
      dp = dpr += dpryi;
    }
  }
  
  static void blit(int op, byte[] srcData, int srcDepth, int srcStride, int srcOrder, int srcX, int srcY, int srcWidth, int srcHeight, int srcRedMask, int srcGreenMask, int srcBlueMask, int alphaMode, byte[] alphaData, int alphaStride, int alphaX, int alphaY, byte[] destData, int destDepth, int destStride, int destOrder, int destX, int destY, int destWidth, int destHeight, byte[] destReds, byte[] destGreens, byte[] destBlues, boolean flipX, boolean flipY)
  {
    if ((destWidth <= 0) || (destHeight <= 0) || (alphaMode == 0)) {
      return;
    }
    int dwm1 = destWidth - 1;
    int sfxi = dwm1 != 0 ? (int)(((srcWidth << 16) - 1L) / dwm1) : 0;
    int dhm1 = destHeight - 1;
    int sfyi = dhm1 != 0 ? (int)(((srcHeight << 16) - 1L) / dhm1) : 0;
    int stype;
    int stype;
    int stype;
    int stype;
    switch (srcDepth)
    {
    case 8: 
      int sbpp = 1;
      stype = 0;
      break;
    case 16: 
      int sbpp = 2;
      stype = srcOrder == 1 ? 1 : 2;
      break;
    case 24: 
      int sbpp = 3;
      stype = 3;
      break;
    case 32: 
      int sbpp = 4;
      stype = srcOrder == 1 ? 4 : 5;
      break;
    default: 
      return;
    }
    int stype;
    int sbpp;
    int spr = srcY * srcStride + srcX * sbpp;
    int dtype;
    int dtype;
    int dtype;
    int dtype;
    switch (destDepth)
    {
    case 8: 
      dtype = 6;
      break;
    case 4: 
      destStride <<= 1;
      dtype = 7;
      break;
    case 2: 
      destStride <<= 2;
      dtype = 8;
      break;
    case 1: 
      destStride <<= 3;
      dtype = destOrder == 1 ? 9 : 10;
      break;
    case 3: 
    case 5: 
    case 6: 
    case 7: 
    default: 
      return;
    }
    int dtype;
    int dpr = (flipY ? destY + dhm1 : destY) * destStride + (flipX ? destX + dwm1 : destX);
    int dprxi = flipX ? -1 : 1;
    int dpryi = flipY ? -destStride : destStride;
    int apr;
    if ((op & 0x2) != 0)
    {
      int apr;
      int apr;
      int apr;
      int apr;
      switch (alphaMode)
      {
      case -3: 
      case -1: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        apr = alphaY * alphaStride + alphaX;
        break;
      case -4: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        alphaStride <<= 3;
        apr = alphaY * alphaStride + alphaX;
        break;
      case -5: 
        return;
      case -6: 
        if (alphaData == null) {
          alphaMode = 65536;
        }
        apr = 0;
        break;
      default: 
        alphaMode = (alphaMode << 16) / 255;
      case -2: 
        apr = 0;
        break;
      }
    }
    else
    {
      alphaMode = 65536;
      apr = 0;
    }
    boolean ditherEnabled = (op & 0x4) != 0;
    
    int srcRedShift = getChannelShift(srcRedMask);
    byte[] srcReds = ANY_TO_EIGHT[getChannelWidth(srcRedMask, srcRedShift)];
    int srcGreenShift = getChannelShift(srcGreenMask);
    byte[] srcGreens = ANY_TO_EIGHT[getChannelWidth(srcGreenMask, srcGreenShift)];
    int srcBlueShift = getChannelShift(srcBlueMask);
    byte[] srcBlues = ANY_TO_EIGHT[getChannelWidth(srcBlueMask, srcBlueShift)];
    int srcAlphaShift = getChannelShift(0);
    byte[] srcAlphas = ANY_TO_EIGHT[getChannelWidth(0, srcAlphaShift)];
    
    int dp = dpr;
    int sp = spr;
    int ap = apr;int alpha = alphaMode;
    int r = 0;int g = 0;int b = 0;int a = 0;
    int indexq = 0;
    int lastindex = 0;int lastr = -1;int lastg = -1;int lastb = -1;
    
    int destPaletteSize = 1 << destDepth;
    if ((destReds != null) && (destReds.length < destPaletteSize)) {
      destPaletteSize = destReds.length;
    }
    int[] berr;
    int[] rerr;
    int[] gerr;
    int[] berr;
    if (ditherEnabled)
    {
      int[] rerr = new int[destWidth + 2];
      int[] gerr = new int[destWidth + 2];
      berr = new int[destWidth + 2];
    }
    else
    {
      rerr = (int[])null;gerr = (int[])null;berr = (int[])null;
    }
    int dy = destHeight;
    for (int sfy = sfyi; dy > 0;)
    {
      int lrerr = 0;int lgerr = 0;int lberr = 0;
      int dx = destWidth;
      for (int sfx = sfxi; dx > 0;)
      {
        switch (stype)
        {
        case 0: 
          int data = srcData[sp] & 0xFF;
          sp += (sfx >>> 16);
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
          break;
        case 1: 
          int data = (srcData[sp] & 0xFF) << 8 | srcData[(sp + 1)] & 0xFF;
          sp += (sfx >>> 16) * 2;
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
          break;
        case 2: 
          int data = (srcData[(sp + 1)] & 0xFF) << 8 | srcData[sp] & 0xFF;
          sp += (sfx >>> 16) * 2;
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
          break;
        case 3: 
          int data = ((srcData[sp] & 0xFF) << 8 | 
            srcData[(sp + 1)] & 0xFF) << 8 | 
            srcData[(sp + 2)] & 0xFF;
          sp += (sfx >>> 16) * 3;
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
          break;
        case 4: 
          int data = (((srcData[sp] & 0xFF) << 8 | 
            srcData[(sp + 1)] & 0xFF) << 8 | 
            srcData[(sp + 2)] & 0xFF) << 8 | 
            srcData[(sp + 3)] & 0xFF;
          sp += (sfx >>> 16) * 4;
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
          break;
        case 5: 
          int data = (((srcData[(sp + 3)] & 0xFF) << 8 | 
            srcData[(sp + 2)] & 0xFF) << 8 | 
            srcData[(sp + 1)] & 0xFF) << 8 | 
            srcData[sp] & 0xFF;
          sp += (sfx >>> 16) * 4;
          r = srcReds[((data & srcRedMask) >>> srcRedShift)] & 0xFF;
          g = srcGreens[((data & srcGreenMask) >>> srcGreenShift)] & 0xFF;
          b = srcBlues[((data & srcBlueMask) >>> srcBlueShift)] & 0xFF;
          a = srcAlphas[(0 >>> srcAlphaShift)] & 0xFF;
        }
        switch (alphaMode)
        {
        case -1: 
          alpha = ((alphaData[ap] & 0xFF) << 16) / 255;
          ap += (sfx >> 16);
          break;
        case -2: 
          alpha = (a << 16) / 255;
          break;
        case -3: 
          alpha = alphaData[ap] != 0 ? 65536 : 0;
          ap += (sfx >> 16);
          break;
        case -4: 
          alpha = alphaData[(ap >> 3)] << (ap & 0x7) + 9 & 0x10000;
          ap += (sfx >> 16);
          break;
        case -6: 
          alpha = 65536;
          for (int i = 0; i < alphaData.length; i += 3) {
            if ((r == alphaData[i]) && (g == alphaData[(i + 1)]) && (b == alphaData[(i + 2)]))
            {
              alpha = 0;
              break;
            }
          }
        }
        if (alpha != 65536)
        {
          if (alpha != 0)
          {
            switch (dtype)
            {
            case 6: 
              indexq = destData[dp] & 0xFF;
              break;
            case 7: 
              if ((dp & 0x1) != 0) {
                indexq = destData[(dp >> 1)] & 0xF;
              } else {
                indexq = destData[(dp >> 1)] >>> 4 & 0xF;
              }
              break;
            case 8: 
              indexq = destData[(dp >> 2)] >>> 6 - (dp & 0x3) * 2 & 0x3;
              break;
            case 9: 
              indexq = destData[(dp >> 3)] >>> 7 - (dp & 0x7) & 0x1;
              break;
            case 10: 
              indexq = destData[(dp >> 3)] >>> (dp & 0x7) & 0x1;
            }
            int rq = destReds[indexq] & 0xFF;
            int gq = destGreens[indexq] & 0xFF;
            int bq = destBlues[indexq] & 0xFF;
            r = rq + ((r - rq) * alpha >> 16);
            g = gq + ((g - gq) * alpha >> 16);
            b = bq + ((b - bq) * alpha >> 16);
          }
        }
        else
        {
          if (ditherEnabled)
          {
            r += (rerr[dx] >> 4);
            if (r < 0) {
              r = 0;
            } else if (r > 255) {
              r = 255;
            }
            g += (gerr[dx] >> 4);
            if (g < 0) {
              g = 0;
            } else if (g > 255) {
              g = 255;
            }
            b += (berr[dx] >> 4);
            if (b < 0) {
              b = 0;
            } else if (b > 255) {
              b = 255;
            }
            rerr[dx] = lrerr;
            gerr[dx] = lgerr;
            berr[dx] = lberr;
          }
          if ((r != lastr) || (g != lastg) || (b != lastb))
          {
            int j = 0;
            for (int minDistance = Integer.MAX_VALUE; j < destPaletteSize; j++)
            {
              int dr = (destReds[j] & 0xFF) - r;
              int dg = (destGreens[j] & 0xFF) - g;
              int db = (destBlues[j] & 0xFF) - b;
              int distance = dr * dr + dg * dg + db * db;
              if (distance < minDistance)
              {
                lastindex = j;
                if (distance == 0) {
                  break;
                }
                minDistance = distance;
              }
            }
            lastr = r;lastg = g;lastb = b;
          }
          if (ditherEnabled)
          {
            int dxm1 = dx - 1;int dxp1 = dx + 1;
            int acc;
            rerr[dxp1] += (acc = (lrerr = r - (destReds[lastindex] & 0xFF)) + lrerr + lrerr);
            rerr[dx] += acc += lrerr + lrerr;
            rerr[dxm1] += acc + lrerr + lrerr;
            gerr[dxp1] += (acc = (lgerr = g - (destGreens[lastindex] & 0xFF)) + lgerr + lgerr);
            gerr[dx] += acc += lgerr + lgerr;
            gerr[dxm1] += acc + lgerr + lgerr;
            berr[dxp1] += (acc = (lberr = b - (destBlues[lastindex] & 0xFF)) + lberr + lberr);
            berr[dx] += acc += lberr + lberr;
            berr[dxm1] += acc + lberr + lberr;
          }
          switch (dtype)
          {
          case 6: 
            destData[dp] = ((byte)lastindex);
            break;
          case 7: 
            if ((dp & 0x1) != 0) {
              destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF0 | lastindex));
            } else {
              destData[(dp >> 1)] = ((byte)(destData[(dp >> 1)] & 0xF | lastindex << 4));
            }
            break;
          case 8: 
            int shift = 6 - (dp & 0x3) * 2;
            destData[(dp >> 2)] = ((byte)(destData[(dp >> 2)] & (3 << shift ^ 0xFFFFFFFF) | lastindex << shift));
            break;
          case 9: 
            int shift = 7 - (dp & 0x7);
            destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | lastindex << shift));
            break;
          case 10: 
            int shift = dp & 0x7;
            destData[(dp >> 3)] = ((byte)(destData[(dp >> 3)] & (1 << shift ^ 0xFFFFFFFF) | lastindex << shift));
          }
        }
        dx--;
        dp += dprxi;
        sfx = (sfx & 0xFFFF) + sfxi;
      }
      dy--;
      sp = spr += (sfy >>> 16) * srcStride;
      ap = apr += (sfy >>> 16) * alphaStride;
      sfy = (sfy & 0xFFFF) + sfyi;
      dp = dpr += dpryi;
    }
  }
  
  static int getChannelShift(int mask)
  {
    if (mask == 0) {
      return 0;
    }
    for (int i = 0; ((mask & 0x1) == 0) && (i < 32); i++) {
      mask >>>= 1;
    }
    return i;
  }
  
  static int getChannelWidth(int mask, int shift)
  {
    if (mask == 0) {
      return 0;
    }
    mask >>>= shift;
    for (int i = shift; ((mask & 0x1) != 0) && (i < 32); i++) {
      mask >>>= 1;
    }
    return i - shift;
  }
  
  static byte getChannelField(int data, int mask)
  {
    int shift = getChannelShift(mask);
    return ANY_TO_EIGHT[getChannelWidth(mask, shift)][((data & mask) >>> shift)];
  }
  
  static ImageData createGradientBand(int width, int height, boolean vertical, RGB fromRGB, RGB toRGB, int redBits, int greenBits, int blueBits)
  {
    PaletteData paletteData;
    int bitmapDepth;
    int bandWidth;
    int bandHeight;
    byte[] bitmapData;
    if ((redBits != 0) && (greenBits != 0) && (blueBits != 0))
    {
      PaletteData paletteData = new PaletteData(65280, 16711680, -16777216);
      int bitmapDepth = 32;
      if ((redBits >= 8) && (greenBits >= 8) && (blueBits >= 8))
      {
        int steps;
        int bandWidth;
        int bandHeight;
        int steps;
        if (vertical)
        {
          int bandWidth = 1;
          int bandHeight = height;
          steps = bandHeight > 1 ? bandHeight - 1 : 1;
        }
        else
        {
          bandWidth = width;
          bandHeight = 1;
          steps = bandWidth > 1 ? bandWidth - 1 : 1;
        }
        int bytesPerLine = bandWidth * 4;
        byte[] bitmapData = new byte[bandHeight * bytesPerLine];
        buildPreciseGradientChannel(blue, blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine);
        buildPreciseGradientChannel(green, green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine);
        buildPreciseGradientChannel(red, red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine);
      }
      else
      {
        int steps;
        int bandWidth;
        int bandHeight;
        int steps;
        if (vertical)
        {
          int bandWidth = width < 8 ? width : 8;
          int bandHeight = height;
          steps = bandHeight > 1 ? bandHeight - 1 : 1;
        }
        else
        {
          bandWidth = width;
          bandHeight = height < 8 ? height : 8;
          steps = bandWidth > 1 ? bandWidth - 1 : 1;
        }
        int bytesPerLine = bandWidth * 4;
        byte[] bitmapData = new byte[bandHeight * bytesPerLine];
        buildDitheredGradientChannel(blue, blue, steps, bandWidth, bandHeight, vertical, bitmapData, 0, bytesPerLine, blueBits);
        buildDitheredGradientChannel(green, green, steps, bandWidth, bandHeight, vertical, bitmapData, 1, bytesPerLine, greenBits);
        buildDitheredGradientChannel(red, red, steps, bandWidth, bandHeight, vertical, bitmapData, 2, bytesPerLine, redBits);
      }
    }
    else
    {
      paletteData = new PaletteData(new RGB[] { fromRGB, toRGB });
      bitmapDepth = 8;
      int blendi;
      int blendi;
      if (vertical)
      {
        int bandWidth = width < 8 ? width : 8;
        int bandHeight = height;
        blendi = bandHeight > 1 ? 17039360 / (bandHeight - 1) + 1 : 1;
      }
      else
      {
        bandWidth = width;
        bandHeight = height < 8 ? height : 8;
        blendi = bandWidth > 1 ? 17039360 / (bandWidth - 1) + 1 : 1;
      }
      int bytesPerLine = bandWidth + 3 & 0xFFFFFFFC;
      bitmapData = new byte[bandHeight * bytesPerLine];
      if (vertical)
      {
        int dy = 0;int blend = 0;
        for (int dp = 0; dy < bandHeight; dp += bytesPerLine)
        {
          for (int dx = 0; dx < bandWidth; dx++) {
            bitmapData[(dp + dx)] = 
              (blend + DITHER_MATRIX[(dy & 0x7)][dx] < 16777216 ? 0 : 1);
          }
          dy++;blend += blendi;
        }
      }
      else
      {
        int dx = 0;
        for (int blend = 0; dx < bandWidth; blend += blendi)
        {
          int dy = 0;
          for (int dptr = dx; dy < bandHeight; dptr += bytesPerLine)
          {
            bitmapData[dptr] = 
              (blend + DITHER_MATRIX[dy][(dx & 0x7)] < 16777216 ? 0 : 1);dy++;
          }
          dx++;
        }
      }
    }
    return new ImageData(bandWidth, bandHeight, bitmapDepth, paletteData, 4, bitmapData);
  }
  
  static final void buildPreciseGradientChannel(int from, int to, int steps, int bandWidth, int bandHeight, boolean vertical, byte[] bitmapData, int dp, int bytesPerLine)
  {
    int val = from << 16;
    int inc = ((to << 16) - val) / steps + 1;
    if (vertical) {
      for (int dy = 0; dy < bandHeight; dp += bytesPerLine)
      {
        bitmapData[dp] = ((byte)(val >>> 16));
        val += inc;dy++;
      }
    } else {
      for (int dx = 0; dx < bandWidth; dp += 4)
      {
        bitmapData[dp] = ((byte)(val >>> 16));
        val += inc;dx++;
      }
    }
  }
  
  static final void buildDitheredGradientChannel(int from, int to, int steps, int bandWidth, int bandHeight, boolean vertical, byte[] bitmapData, int dp, int bytesPerLine, int bits)
  {
    int 
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