Examples of BinaryOutputStream


Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test32BPPHalfMaskedIcon() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0xff0000ff;
    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 + 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 + 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);
      }
    }
    // Missing 1 bit mask!!!
    bos.flush();
   
    boolean threw = false;
    try
    {
      writeAndReadImageData("32bpp-half-masked-CORRUPT", baos.toByteArray(), foreground, background);
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

  public void test32BPPMaskMissingIcon() throws ImageReadException, ImageWriteException, IOException
  {
    final int foreground = 0xff000000;
    final int background = 0xff0000ff;
    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);
    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.flush();
    writeAndReadImageData("32bpp-mask-missing", baos.toByteArray(), foreground, background);
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

            Map.Entry entry = (Map.Entry) it.next();
            int bitDepth = ((Integer)entry.getKey()).intValue();
            BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(baos,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
                    (bitDepth <= 8) ? (1 << bitDepth) : 0);
            writeICONDIR(bos, 0, 1, 1);
            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
            writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
            bos.write(bitmap);
            bos.flush();
            writeAndReadImageData("16x16x" + bitDepth, baos.toByteArray(), foreground, background);
        }
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

            Map.Entry entry = (Map.Entry) it.next();
            int bitDepth = ((Integer)entry.getKey()).intValue();
            BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(baos,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
                    (bitDepth <= 8) ? (1 << bitDepth) : 0);
            writeICONDIR(bos, 0, 1, 1);
            writeICONDIRENTRY(bos, 3 /* width, should be 16 */,
                    4 /* height, should be 16 */,
                    7 /* colorCount, should be 2 or 0 */,
                    20 /* reserved, should be 0 */,
                    11 /* planes, should be 1 or 0 */,
                    19 /* bitCount, should be bitDepth */,
                    40 + bitmap.length);
            writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 0, 0);
            bos.write(bitmap);
            bos.flush();
            writeAndReadImageData("16x16x" + bitDepth + "-corrupt-icondirentry",
                    baos.toByteArray(), foreground, background);
        }
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

            Map.Entry entry = (Map.Entry) it.next();
            int bitDepth = ((Integer)entry.getKey()).intValue();
            BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(baos,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background, 2);
            writeICONDIR(bos, 0, 1, 1);
            writeICONDIRENTRY(bos, 3, 4, 7, 20, 11, 19, 40 + bitmap.length);
            writeBITMAPINFOHEADER(bos, 16, 2*16, 1, bitDepth, 0, 2, 0);
            bos.write(bitmap);
            bos.flush();
            writeAndReadImageData("16x16x" + bitDepth + "-custom-palette",
                    baos.toByteArray(), foreground, background);
        }
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

            Map.Entry entry = (Map.Entry) it.next();
            int bitDepth = ((Integer)entry.getKey()).intValue();
            BitmapGenerator bitmapGenerator = (BitmapGenerator) entry.getValue();

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BinaryOutputStream bos = new BinaryOutputStream(baos,
                    BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
            byte[] bitmap = bitmapGenerator.generateBitmap(foreground, background,
                    (bitDepth <= 8) ? (1 << bitDepth) : 0);
            writeICONDIR(bos, 0, 1, 1);
            writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, bitDepth, 40 + bitmap.length);
            writeBITMAPINFOHEADER(bos, 16, 2*16, 0 /* should be 1 */, bitDepth, 0, 0, 0);
            bos.write(bitmap);
            bos.flush();

            boolean threw = false;
            try
            {
                writeAndReadImageData("16x16x" + bitDepth + "-zero-colorPlanes",
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    }

    public void testBitfieldCompression() throws IOException, ImageWriteException, ImageReadException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputStream bos = new BinaryOutputStream(baos,
                BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
        byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
                0xFFFF0000, 0xFFFFFFFF, 0, true);
        writeICONDIR(bos, 0, 1, 1);
        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
        writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 3 /* BI_BITFIELDS */, 0, 0);
        bos.write4Bytes(0x000000FF); // red mask
        bos.write4Bytes(0x0000FF00); // green mask
        bos.write4Bytes(0x00FF0000); // blue mask
        bos.write(bitmap);
        bos.flush();
        writeAndReadImageData("16x16x32-bitfield-compressed", baos.toByteArray(),
                0xFF0000FF, 0xFFFFFFFF);
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    public void test32bitMask() throws IOException, ImageWriteException, ImageReadException
    {
        final int foreground = 0xFFF000E0;
        final int background = 0xFF102030;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputStream bos = new BinaryOutputStream(baos,
                BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
        // For 32 bit RGBA, the AND mask can be missing:
        byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
                foreground, background, 0, false);
        writeICONDIR(bos, 0, 1, 1);
        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
        writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
        bos.write(bitmap);
        bos.flush();
        writeAndReadImageData("16x16x32-no-mask", baos.toByteArray(), foreground, background);
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    }

    public void testAlphaVersusANDMask() throws IOException, ImageWriteException, ImageReadException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputStream bos = new BinaryOutputStream(baos,
                BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
        byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
                0xFF000000, 0x00000000, 0, true);
        writeICONDIR(bos, 0, 1, 1);
        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
        writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
        bos.write(bitmap);
        bos.flush();
        // The AND mask is fully opaque, yet the fully transparent alpha should win:
        writeAndReadImageData("16x16x32-alpha-vs-mask", baos.toByteArray(),
                0xFF000000, 0x00000000);
    }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryOutputStream

    }

    public void testFullyTransparent32bitRGBA() throws IOException, ImageWriteException, ImageReadException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputStream bos = new BinaryOutputStream(baos,
                BinaryOutputStream.BYTE_ORDER_LITTLE_ENDIAN);
        byte[] bitmap = new GeneratorFor32BitBitmaps().generate32bitRGBABitmap(
                0x00000000, 0x00FFFFFF, 0, true);
        writeICONDIR(bos, 0, 1, 1);
        writeICONDIRENTRY(bos, 16, 16, 0, 0, 1, 32, 40 + bitmap.length);
        writeBITMAPINFOHEADER(bos, 16, 2*16, 1, 32, 0, 0, 0);
        bos.write(bitmap);
        bos.flush();
        // Because every pixel is fully trasparent, ***ALPHA GETS IGNORED***:
        writeAndReadImageData("16x16x32-fully-transparent", baos.toByteArray(),
                0xFF000000, 0xFFFFFFFF);
    }
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.