Java ByteBuffer Put putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize)

Here you can find the source of putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize)

Description

put RG Bfrom HSB

License

Open Source License

Declaration

public static void putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize) 

Method Source Code


//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    public static void putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize) {
        int idx = 0;
        for (int i = hsb.length / 3; --i >= 0;) {
            int r = 0, g = 0, b = 0;
            if (hsb[idx + 1] == 0)
                r = g = b = (int) (hsb[idx + 2] * 255.0f + 0.5f);
            else {
                float h = (hsb[idx + 0] - (float) Math.floor(hsb[idx + 0])) * 6.0f;
                float f = h - (float) Math.floor(h);
                float p = hsb[idx + 2] * (1.0f - hsb[idx + 1]);
                float q = hsb[idx + 2] * (1.0f - hsb[idx + 1] * f);
                float t = hsb[idx + 2] * (1.0f - (hsb[idx + 1] * (1.0f - f)));
                switch ((int) h) {
                case 0:
                    r = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    g = (int) (t * 255.0f + 0.5f);
                    b = (int) (p * 255.0f + 0.5f);
                    break;
                case 1:
                    r = (int) (q * 255.0f + 0.5f);
                    g = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    b = (int) (p * 255.0f + 0.5f);
                    break;
                case 2:
                    r = (int) (p * 255.0f + 0.5f);
                    g = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    b = (int) (t * 255.0f + 0.5f);
                    break;
                case 3:
                    r = (int) (p * 255.0f + 0.5f);
                    g = (int) (q * 255.0f + 0.5f);
                    b = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    break;
                case 4:
                    r = (int) (t * 255.0f + 0.5f);
                    g = (int) (p * 255.0f + 0.5f);
                    b = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    break;
                case 5:
                    r = (int) (hsb[idx + 2] * 255.0f + 0.5f);
                    g = (int) (p * 255.0f + 0.5f);
                    b = (int) (q * 255.0f + 0.5f);
                    break;
                }// w  w  w .  j a v  a2  s.c om
            }
            pixels.put((byte) r);
            pixels.put((byte) g);
            pixels.put((byte) b);
            if (pixelSize == 4)
                pixels.get();
            idx += 3;
        }
    }
}

Related

  1. putNullTerminal(ByteBuffer buffer)
  2. putObject(ByteBuffer byteBuffer, Object object)
  3. putObject(final ByteBuffer buffer, Serializable o)
  4. putQuickchatParam(ByteBuffer buf, long param, int size)
  5. putRange(ByteBuffer buffer, int start, int end, byte b)
  6. putStr(ByteBuffer buff, String str)
  7. putString(@Nullable final String s, @Nonnull final ByteBuffer dst)
  8. putString(ByteBuffer bb, String s)
  9. putString(ByteBuffer buf, String value)