Java ByteBuffer Flip flip(ByteBuffer bytes, int width, int height)

Here you can find the source of flip(ByteBuffer bytes, int width, int height)

Description

flip

License

Open Source License

Declaration

public static void flip(ByteBuffer bytes, int width, int height) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static void flip(byte[] bytes, int width, int height) {
        byte[] line = new byte[width];

        for (int i = 0; i < height / 2; i++) {
            System.arraycopy(bytes, i * width, line, 0, width);
            System.arraycopy(bytes, (height - i - 1) * width, bytes, i * width, width);
            System.arraycopy(line, 0, bytes, (height - i - 1) * width, width);
        }//ww w .  j  a v a2 s  . c  o m
    }

    public static void flip(ByteBuffer bytes, int width, int height) {
        byte[] line = new byte[width];
        byte[] line2 = new byte[width];

        for (int i = 0; i < height / 2; i++) {
            bytes.position(i * width);
            bytes.get(line);
            bytes.position((height - i - 1) * width);
            bytes.get(line2);
            bytes.position(i * width);
            bytes.put(line2);
            bytes.position((height - i - 1) * width);
            bytes.put(line);
        }
    }
}

Related

  1. flip(ByteBuffer b)
  2. flip(ByteBuffer buffer)
  3. flip(ByteBuffer bytes, int width, int height)
  4. flip(ByteBuffer[] buffers)
  5. flip(ByteBuffer[] bufs)
  6. flipPutFlip(ByteBuffer from, ByteBuffer to)
  7. flipToFill(ByteBuffer buffer)