Here you can find the source of writeImageDescriptor(ByteBuffer out, int imageLeft, int imageTop, int imageWidth, int imageHeight, boolean hasLct, int numColors)
public static void writeImageDescriptor(ByteBuffer out, int imageLeft, int imageTop, int imageWidth, int imageHeight, boolean hasLct, int numColors)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static final int IMAGE_DESCRIPTOR_LENGTH = 10; public static void writeImageDescriptor(ByteBuffer out, int imageLeft, int imageTop, int imageWidth, int imageHeight, boolean hasLct, int numColors) { verifyRemaining(out, IMAGE_DESCRIPTOR_LENGTH); verifyShortValues(imageLeft, imageTop, imageWidth, imageHeight); final byte packed; if (hasLct) { int size = log2(numColors) - 1; packed = (byte) (0x80 | size); } else {/*w ww . j a v a2 s . c o m*/ packed = 0x00; } // Image separator out.put((byte) 0x2C); out.putShort((short) imageLeft).putShort((short) imageTop) .putShort((short) imageWidth).putShort((short) imageHeight) .put(packed); } private static void verifyRemaining(ByteBuffer buffer, int expected) { if (buffer.remaining() < expected) { throw new IllegalArgumentException("Must have at least " + expected + " bytes to write"); } } private static void verifyShortValues(int... shortValues) { for (int dimen : shortValues) { if (dimen > Short.MAX_VALUE || dimen < 0) { throw new IllegalArgumentException( "Must pass in non-negative short dimensions, not: " + dimen); } } } private static int log2(int num) { return (int) Math.round(Math.log(num) / Math.log(2)); } }