Java ByteBuffer Write writeColorTable(ByteBuffer out, int numColors)

Here you can find the source of writeColorTable(ByteBuffer out, int numColors)

Description

write Color Table

License

Open Source License

Declaration

public static void writeColorTable(ByteBuffer out, int numColors) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static void writeColorTable(ByteBuffer out, int numColors) {
        verifyRemaining(out, getColorTableLength(numColors));
        for (int i = 0; i < numColors; i++) {
            out.put((byte) (0xFF0000 & i));
            out.put((byte) (0x00FF00 & i));
            out.put((byte) (0x0000FF & i));
        }//from   w  ww .  j  a  va  2  s . c om
    }

    private static void verifyRemaining(ByteBuffer buffer, int expected) {
        if (buffer.remaining() < expected) {
            throw new IllegalArgumentException("Must have at least "
                    + expected + " bytes to write");
        }
    }

    public static int getColorTableLength(int numColors) {
        return 3 * numColors;
    }
}

Related

  1. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  2. writeByteString(ByteBuffer byteBuffer, String value)
  3. writeCDouble(ByteBuffer buffer, double value)
  4. writeCharacterString(ByteBuffer buf, byte[] bytes)
  5. writeCInt(ByteBuffer buffer, int anInt)
  6. writeDouble(ByteBuffer buffer, double d)
  7. writeDouble(double v, ByteBuffer buffer)
  8. writeEmpty(final ByteBuffer buffer, final int type)
  9. writeFakeImageData(ByteBuffer out, int lzwMinCodeSize)