Java ByteBuffer Print printImageContentsSubset(ByteBuffer buf, int w, int h)

Here you can find the source of printImageContentsSubset(ByteBuffer buf, int w, int h)

Description

Print a small subset of the given image, namely the upper left 20x20.

License

Open Source License

Declaration

private static void printImageContentsSubset(ByteBuffer buf, int w, int h) 

Method Source Code

//package com.java2s;
/**/*ww w .j a v  a  2 s  .  c om*/
 * Project Wonderland
 *
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved
 *
 * Redistributions in source code form must reproduce the above
 * copyright and this condition.
 *
 * The contents of this file are subject to the GNU General Public
 * License, Version 2 (the "License"); you may not use this file
 * except in compliance with the License. A copy of the License is
 * available at http://www.opensource.org/licenses/gpl-license.php.
 *
 * Sun designates this particular file as subject to the "Classpath" 
 * exception as provided by Sun in the License file that accompanied 
 * this code.
 */

import java.nio.ByteBuffer;

import java.nio.IntBuffer;

public class Main {
    /**
     * Print a small subset of the given image, namely the upper left 20x20.
     */
    private static void printImageContentsSubset(ByteBuffer buf, int w, int h) {
        // Line size (in ints)
        int lineSize = w * 4;

        w = (w > 20) ? 20 : w;
        h = (h > 20) ? 20 : h;

        IntBuffer ibuf = buf.asIntBuffer();
        int nextLine = 0;
        for (int y = 0; y < h; y++, nextLine += lineSize) {
            ibuf.position(nextLine);
            for (int x = 0; x < w; x++) {
                int pixel = ibuf.get();
                System.err.print(Integer.toHexString(pixel) + " ");
            }
            System.err.println();
        }
    }
}

Related

  1. printBuffer(ByteBuffer buffer)
  2. printBuffer(String msg, ByteBuffer buffer)
  3. printByteBuffer(ByteBuffer buf)
  4. printData(ByteBuffer buf, int offset, int len)
  5. printData(ByteBuffer buffer, int len)
  6. println(String string, ByteBuffer buffer)
  7. printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos)