Package _api.alienfactory.javamappy

Examples of _api.alienfactory.javamappy.PixelData


   * @throws IllegalArgumentException if <code>Map</code> is <code>null</code>
   **/
  public J2SE14Renderer(Map map) throws IllegalArgumentException {
    super(map);

    PixelData imageData[]  = map.getImageData();
    super.opaqueImages    = new Image[imageData.length];
    super.transparentImages  = new Image[imageData.length];

    GraphicsEnvironment    gfxEnviro = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice      gfxDevice = gfxEnviro.getDefaultScreenDevice();   
      GraphicsConfiguration   gfxConfig = gfxDevice.getDefaultConfiguration();

      Graphics         gfx;
      PixelData        pixelData;
    BufferedImage       image;

    for (int i=0; i < imageData.length; i++) {
      pixelData    = imageData[i];

      image = new BufferedImage(blockWidth, blockHeight, BufferedImage.TYPE_INT_ARGB);
      image.setRGB(0, 0, blockWidth, blockHeight, imageData[i].getRawPixelData(), 0, blockWidth);
     
      // draw our opaque image
      super.opaqueImages[i] = gfxConfig.createCompatibleImage(blockWidth, blockHeight);
      gfx = super.opaqueImages[i].getGraphics();
      gfx.drawImage(image, 0, 0, null);
      gfx.dispose();     

      // don't bother making a a transparent image if it has no transparent pixels
      if (pixelData.hasTransparentPixels()) {
        super.transparentImages[i] = gfxConfig.createCompatibleImage(blockWidth, blockHeight, Transparency.BITMASK);
        gfx = super.transparentImages[i].getGraphics();
        gfx.drawImage(image, 0, 0, null);
        gfx.dispose();
      }
View Full Code Here


   * @throws IllegalArgumentException if <code>Map</code> is <code>null</code>
   **/
  public JDK11Renderer(Map map) throws IllegalArgumentException {
    super(map);
   
    PixelData imageData[]  = map.getImageData();
    MapHeader mapHeader   = map.getMapHeader();
    Colour[]  colours     = map.getColours();

    super.opaqueImages    = new Image[imageData.length];
    super.transparentImages  = new Image[imageData.length];
   
    int[] intImageData;
    PixelData pixelData;

    // index colour models are only valid for Colour Map images
    boolean usesColourMap = (mapHeader.getColourDepth() == 8);
    IndexColorModel icmSolid = null, icmTrans = null;
    if (usesColourMap) {
        LOG.debug("Using IndexColourModels");
      icmSolid = new IndexColorModel(8, colours.length, toByteArray(colours), 0, false);   
      icmTrans = new IndexColorModel(8, colours.length, toByteArray(colours), 0, false, mapHeader.getChromeKeyIndex());
    }
   
    for (int i=0; i < imageData.length; i++) {
      pixelData    = imageData[i];
     
      // create the opaque image
      MemoryImageSource mis;
      if (usesColourMap)
        mis = new MemoryImageSource(blockWidth, blockHeight, icmSolid, pixelData.getCmapPixelData(), 0, blockWidth);
      else
        mis = new MemoryImageSource(blockWidth, blockHeight, pixelData.getRawPixelData(), 0, blockWidth);
      super.opaqueImages[i] = Toolkit.getDefaultToolkit().createImage(mis);
     
      if (pixelData.hasTransparentPixels()) {
        if (usesColourMap) {
          super.transparentImages[i] = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(blockWidth, blockHeight, icmTrans, pixelData.getCmapPixelData(), 0, blockWidth));
         
        } else {
          // in JDK1.1 the MemoryImageSource doesn't copy the given
          // array, so any changes you make to the array are reflected
          // in the generated image!
          intImageData = new int[pixelData.getRawPixelData().length];
          System.arraycopy(pixelData.getRawPixelData(), 0, intImageData, 0, intImageData.length)
          super.transparentImages[i] = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(blockWidth, blockHeight, intImageData, 0, blockWidth));
        }
      }     
    }
  }
View Full Code Here

   * @throws IllegalArgumentException if <code>Map</code> is <code>null</code>
   **/
  public JDK12Renderer(Map map) throws IllegalArgumentException {
    super(map);
   
    PixelData imageData[]  = map.getImageData();
    super.opaqueImages    = new Image[imageData.length];
    super.transparentImages = new Image[imageData.length];
       
    BufferedImage buffImage;
    for (int i=0; i < imageData.length; i++) {
View Full Code Here

  public void loadChunk(Map map) throws ChunkLoadException {
    MapHeader   mapHeader   = map.getMapHeader();
    Colour[]  colours    = map.getColours();
    int      colourDepth  = mapHeader.getColourDepth();
    PixelData  imageData[]  = new PixelData[mapHeader.getNoOfImages()];
    int intAlpha=0 , intRed=0, intGreen=0, intBlue=0, colourIndex;
   
   
    // cache some map header values
    int blockHeight = mapHeader.getBlockHeight();
    int blockWidth   = mapHeader.getBlockWidth();
   
   
    // grab the transparent colour
    Colour chromeKey = null;
    if (mapHeader.getColourDepth() == 8) {
      colourIndex = mapHeader.getChromeKeyIndex();
      chromeKey  = colours[colourIndex];
    } else {
      chromeKey  = mapHeader.getChromeKey();
    }
    int transparent  = chromeKey.toInt();


        PixelData pixelData;
    log.info("Reading [" + mapHeader.getNoOfImages() + "] images...");
    for (int i=0; i < mapHeader.getNoOfImages(); i++) {
      int[]   intImage = new int [mapHeader.getBlockWidth() * mapHeader.getBlockHeight()];
      byte[]  bytImage = new byte[mapHeader.getBlockWidth() * mapHeader.getBlockHeight()];
            int     index    = 0;
            boolean  hasTransparentPixels = false;

      for (int y=0 ; y<blockHeight; y++) {       
        for (int x=0 ; x<blockWidth; x++) {
          int  upper, lower;
          int colour;

          // grab the colour of the pixel
          switch (colourDepth) {
          case 8:
            colourIndex = super.readUByte();
            intAlpha   = colours[colourIndex].getAlpha();
            intRed     = colours[colourIndex].getRed();
            intGreen  = colours[colourIndex].getGreen();
            intBlue   = colours[colourIndex].getBlue();
            bytImage[index] = (byte) colourIndex;
            break;
          case 15:
            upper  = super.readUByte();
            lower   = super.readUByte();
            intAlpha   = 0xFF;
            intRed     =  (upper & 0x7C) << 1;
            intGreen   = ((upper & 0x03) << 6) | ((lower & 0xE0) >> 2);
            intBlue   =  (lower & 0x1F) << 3;
            break;
          case 16:
            upper  = super.readUByte();
            lower   = super.readUByte();
            intAlpha   = 0xFF;
            intRed     =  (upper & 0xF8);
            intGreen   = ((upper & 0x07) << 5) | ((lower & 0xE0) >> 3);
            intBlue   =  (lower & 0x1F) << 3;
            break;
          case 24:
            intAlpha   = 0xFF;
            intRed     = super.readUByte();
            intGreen   = super.readUByte();
            intBlue   = super.readUByte();
            break;
          case 32:
            intAlpha  = super.readUByte();
            intRed     = super.readUByte();
            intGreen  = super.readUByte();
            intBlue   = super.readUByte();
            transparent = 0;    // prevents (semi) opaque colours being made transparent
            break;
          }
         
          colour = (intAlpha << 24) | (intRed << 16) | (intGreen << 8) | intBlue;
          if (colour == transparent) {
            colour &= 0x00FFFFFF;
            hasTransparentPixels = true;
          }
         
          // this caters for 32 bit colours
          if (intAlpha != 0xFF)
            hasTransparentPixels = true;
          intImage[index++] = colour;
        }
      }     
     
      if (colourDepth == 8)
        pixelData = new PixelData(intImage, bytImage, hasTransparentPixels);
      else
        pixelData = new PixelData(intImage, hasTransparentPixels);

      imageData[i] = pixelData;
           
//      this logging detail is far too much for normal use!
//      String data = "";
View Full Code Here

TOP

Related Classes of _api.alienfactory.javamappy.PixelData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.