Examples of BinaryOutputStream


Examples of org.apache.sanselan.common.BinaryOutputStream

    {
        public byte[] generateBitmap(int foreground, int background, int paletteSize)
                throws IOException, ImageWriteException
        {
            ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            // Palette
            bos.write3Bytes(background);
            bos.write(0);
            bos.write3Bytes(foreground);
            bos.write(0);
            for (int i = 2; i < paletteSize; i++)
                bos.write4Bytes(0);
            // Image
            for (int y = 15; y >= 0; y--)
            {
                for (int x = 0; x < 16; x++)
                {
                    bos.write(image[y][x]);
                }
            }
            // Mask
            for (int y = image.length - 1; y >= 0; y--)
            {
                bos.write(0);
                bos.write(0);
                // Pad to 4 bytes:
                bos.write(0);
                bos.write(0);
            }
            bos.flush();
            return byteArrayStream.toByteArray();
        }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    {
        public byte[] generateBitmap(int foreground, int background, int paletteSize)
                throws IOException, ImageWriteException
        {
            ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            // Palette
            for (int i = 0; i < paletteSize; i++)
                bos.write4Bytes(0);
            // Image
            for (int y = 15; y >= 0; y--)
            {
                for (int x = 0; x < 16; x++)
                {
                    if (image[y][x] == 1)
                        bos.write2Bytes((0x1f & (foreground >> 3)) |
                                ((0x1f & (foreground >> 11)) << 5) |
                                ((0x1f & (foreground >> 19)) << 10));
                    else
                        bos.write2Bytes((0x1f & (background >> 3)) |
                                ((0x1f & (background >> 11)) << 5) |
                                ((0x1f & (background >> 19)) << 10));
                }
            }
            // Mask
            for (int y = image.length - 1; y >= 0; y--)
            {
                bos.write(0);
                bos.write(0);
                // Pad to 4 bytes:
                bos.write(0);
                bos.write(0);
            }
            bos.flush();
            return byteArrayStream.toByteArray();
        }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test1BPPIconMaskVersus8BPPMask() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0xff000000;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 2*16*16/8 + 4 + 4 + 16*16);
    bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
    bos.write4Bytes(4 + 4 + 2*16*16/8);
    // 1 BPP image - all black
    for (int y = 0; y < 16; y++)
    {
      bos.write(0xff);
      bos.write(0xff);
    }
    // 1 BPP mask - all opaque
    for (int y = 0; y < 16; y++)
    {
      bos.write(0xff);
      bos.write(0xff);
    }
    // 8 BPP alpha mask - partially transparent
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(0x00);
      }
    }
    bos.flush();
    writeAndReadImageData("1bpp-image-mask-versus-8bpp-mask",
        baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    {
        public byte[] generateBitmap(int foreground, int background, int paletteSize)
                throws IOException, ImageWriteException
        {
            ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            // Palette
            for (int i = 0; i < paletteSize; i++)
                bos.write4Bytes(0);
            // Image
            for (int y = 15; y >= 0; y--)
            {
                for (int x = 0; x < 16; x++)
                {
                    if (image[y][x] == 1)
                        bos.write3Bytes(0xffffff & foreground);
                    else
                        bos.write3Bytes(0xffffff & background);
                }
            }
            // Mask
            for (int y = image.length - 1; y >= 0; y--)
            {
                bos.write(0);
                bos.write(0);
                // Pad to 4 bytes:
                bos.write(0);
                bos.write(0);
            }
            bos.flush();
            return byteArrayStream.toByteArray();
        }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test8BPPIcon8BPPMask() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0x00cccccc;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 16*16 + 4 + 4 + 16*16);
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    // 8 BPP image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(43);
      }
    }
    // 8 BPP alpha mask
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(0x00);
      }
    }
    bos.flush();
    writeAndReadImageData("8bpp-image-8bpp-mask", baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

        public byte[] generate32bitRGBABitmap(int foreground, int background,
                int paletteSize, boolean writeMask) throws IOException,
                ImageWriteException
        {
            ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(byteArrayStream,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            // Palette
            for (int i = 0; i < paletteSize; i++)
                bos.write4Bytes(0);
            // Image
            for (int y = 15; y >= 0; y--)
            {
                for (int x = 0; x < 16; x++)
                {
                    if (image[y][x] == 1)
                        bos.write4Bytes(foreground);
                    else
                        bos.write4Bytes(background);
                }
            }
            // Mask
            if (writeMask)
            {
                for (int y = image.length - 1; y >= 0; y--)
                {
                    bos.write(0);
                    bos.write(0);
                    // Pad to 4 bytes:
                    bos.write(0);
                    bos.write(0);
                }
            }
            bos.flush();
            return byteArrayStream.toByteArray();
        }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

      throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0x00cccccc;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 16*16 + 4 + 4 + 16*16 + 4 + 4 + 2*16*16/8);
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    // 8 BPP image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(43);
      }
    }
    // 8 BPP alpha mask, some transparent
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(0x00);
      }
    }
    // 1 BPP mask
    bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
    bos.write4Bytes(4 + 4 + 2*16*16/8);
    // 1 bit image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x += 8)
      {
        int eightBits = 0;
        for (int pos = 0; pos < 8; pos++)
        {
          if (image[y][x+pos] != 0)
            eightBits |= (1 << (7 - pos));
        }
        bos.write(eightBits);
      }
    }
    // 1 bit mask, all opaque
    for (int y = 0; y < 16; y++)
    {
      bos.write(0xff);
      bos.write(0xff);
    }
    bos.flush();
    writeAndReadImageData("8bpp-image-8bpp-mask-vs-1bpp-mask",
        baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

      throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0x00cccccc;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 16*16 + 4 + 4 + 16*16 + 4 + 4 + 2*16*16/8);
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    // 8 BPP image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(43);
      }
    }
    // 1 BPP mask
    bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
    bos.write4Bytes(4 + 4 + 2*16*16/8);
    // 1 bit image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x += 8)
      {
        int eightBits = 0;
        for (int pos = 0; pos < 8; pos++)
        {
          if (image[y][x+pos] != 0)
            eightBits |= (1 << (7 - pos));
        }
        bos.write(eightBits);
      }
    }
    // 1 bit mask, all opaque
    for (int y = 0; y < 16; y++)
    {
      bos.write(0xff);
      bos.write(0xff);
    }
    // 8 BPP alpha mask, some transparent
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_MASK.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(0x00);
      }
    }
    bos.flush();
    writeAndReadImageData("8bpp-image-1bpp-mask-vs-8bpp-mask",
        baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test8BPPIconNoMask() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0xffcccccc;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 16*16);
    bos.write4Bytes(IcnsType.ICNS_16x16_8BIT_IMAGE.getType());
    bos.write4Bytes(4 + 4 + 16*16);
    // 8 BPP image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        if (image[y][x] != 0)
          bos.write(0xff);
        else
          bos.write(43);
      }
    }
    bos.flush();
    writeAndReadImageData("8bpp-image-no-mask", baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test32BPPMaskedIcon() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0x000000ff;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputStream bos = new BinaryOutputStream(baos,
        BinaryOutputStream.BYTE_ORDER_BIG_ENDIAN);
    bos.write4Bytes(IcnsImageParser.ICNS_MAGIC);
    bos.write4Bytes(4 + 4 + 4 + 4 + 4*16*16 + 4 + 4 + 2*16*16/8);
    bos.write4Bytes(IcnsType.ICNS_16x16_32BIT_IMAGE.getType());
    bos.write4Bytes(4 + 4 + 4*16*16);
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x++)
      {
        // argb, a ignored
        bos.write(0);
        final int pixel;
        if (image[y][x] != 0)
          pixel = foreground;
        else
          pixel = background;
        bos.write(0xff & (pixel >> 16));
        bos.write(0xff & (pixel >> 8));
        bos.write(0xff & pixel);
      }
    }
    bos.write4Bytes(IcnsType.ICNS_16x16_1BIT_IMAGE_AND_MASK.getType());
    bos.write4Bytes(4 + 4 + 2*16*16/8);
    // 1 bit image
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x += 8)
      {
        int eightBits = 0;
        for (int pos = 0; pos < 8; pos++)
        {
          if (image[y][x+pos] != 0)
            eightBits |= (1 << (7 - pos));
        }
        bos.write(eightBits);
      }
    }
    // 1 bit mask
    for (int y = 0; y < 16; y++)
    {
      for (int x = 0; x < 16; x += 8)
      {
        int eightBits = 0;
        for (int pos = 0; pos < 8; pos++)
        {
          if (image[y][x+pos] != 0)
            eightBits |= (1 << (7 - pos));
        }
        bos.write(eightBits);
      }
    }
    bos.flush();
    writeAndReadImageData("32bpp-image-1bpp-mask", baos.toByteArray(), foreground, background);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.