/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seniorproject.augmentedreality.utils;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

/**
 *
 * @author RainWhileLoop
 */
public class ConvertColor {

    Integer width;
    Integer height;
    public static void main(String[] args) {

        new ConvertColor();
    }

    public ConvertColor() {

        File file = new File("E:\\dog.jpg");
        if (!file.isFile()) {
            System.err.print("Error");
        }
        InputStream stream = null;
        try {
            stream = new FileInputStream(file);
            BufferedImage image = ImageIO.read(stream);
            getSize(image);
        } catch (IOException ex) {
            Logger.getLogger(ConvertColor.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                stream.close();
            } catch (IOException ex) {
                Logger.getLogger(ConvertColor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    private void getSize(BufferedImage image) {
        this.width = image.getWidth();
        this.height = image.getHeight();
        System.out.println("width = " + width);
        System.out.println("height = " + height);
//        for (int x = 0; x < width; x++) {
//            for (int y = 0; y < height; y++) {
        printPixelARGB(image.getRGB(121, 320));
//            }
//        }
    }

    public void printPixelARGB(Integer pixel) {
        System.out.println("bit pixel : " + pixel.toBinaryString(pixel));
        System.out.println("count bit pixel : " + pixel.toBinaryString(pixel).length());
        Integer alpha = (pixel >> 24) & 0xff;
        Integer red = (pixel >> 16) & 0xff;
        Integer green = (pixel >> 8) & 0xff;
        Integer blue = (pixel) & 0xff;
//        System.out.println("alpha : " + alpha);
        System.out.println("red : " + red.toBinaryString(red) + " (" + red + ")");
        System.out.println("green : " + green.toBinaryString(green) + " (" + green + ")");
        System.out.println("blue : " + blue.toBinaryString(blue) + " (" + blue + ")");
    }
}

@@ -599,16 +599,83 @@
 eight;%0D%0A
+%0D%0A    float h = 0.0f;%0D%0A    float s = 0.0f;%0D%0A    float v = 0.0f;%0D%0A%0D%0A
     publ
@@ -1882,21 +1882,22 @@
 %0A%0D%0A    p
-ublic
+rivate
  void pr
@@ -2489,32 +2489,32 @@
  green + %22)%22);%0D%0A
-
         System.o
@@ -2581,22 +2581,865 @@
 ue + %22)%22);%0D%0A
+        RGBtoHSV(red,green,blue);%0D%0A    %7D%0D%0A%0D%0A    private void RGBtoHSV(int r , int g , int b) %7B%0D%0A%0D%0A        Float fr = r / 255.0f;%0D%0A        Float fg = g / 255.0f;%0D%0A        Float fb = b / 255.0f;%0D%0A        float max = Math.max(Math.max(fr, fg), fb);%0D%0A        float min = Math.min(Math.min(fr, fg), fb);%0D%0A        this.v = max;%0D%0A        float delta = max - min;%0D%0A        this.s = (max == 0.0f) ? 0.0f : delta / max;%0D%0A        if (fr.equals(max)) %7B%0D%0A            this.h = 60.0f * ((fg - fb) / delta + (fg %3C fb ? 6 : 0));%0D%0A        %7D else if (fg.equals(max)) %7B%0D%0A            this.h = 60.0f * ((fb - fr) / delta + 2);%0D%0A        %7D else %7B%0D%0A            this.h = 60.0f * ((fr - fg) / delta + 4);%0D%0A        %7D%0D%0A%0D%0A        System.out.println(%22Hue : %22 + this.h);%0D%0A        System.out.println(%22Saturate : %22 + this.s);%0D%0A        System.out.println(%22Value : %22 + this.v);%0D%0A
     %7D%0D%0A%7D%0D%0A

add convert from RGB to HSV color