<commit_before>package imageFX;

/**
 * File: ImageFX.java
 * 
 * Description:
 * Contains common image processing methods.
 * 
 * @author <NAME>
 * @version 1.0
 * Date: 26-01-2014 sun
 */
import java.awt.image.BufferedImage;

public class ImageFX {
    
    /////////////////////////// Pixel elements ARGB Methods ////////////////////
    
    /**
     * This method will return alpha value from the pixel value.
     * 
     * @param pixelVal The pixel value from which alpha value is calculated.
     * @return Alpha value [0-255].
     */
    public static int getAlphaValueFromPixelValue(int pixelVal){
        return (pixelVal>>24) & 0xFF;
    }
    
    /**
     * This method will return red value from the pixel value.
     * 
     * @param pixelVal The pixel value from which red value is calculated.
     * @return Red value [0-255].
     */
    public static int getRedValueFromPixelValue(int pixelVal){
        return (pixelVal>>16) & 0xFF;
    }
    
    /**
     * This method will return green value from the pixel value.
     * 
     * @param pixelVal The pixel value from which green value is calculated.
     * @return Green value [0-255].
     */
    public static int getGreenValueFromPixelValue(int pixelVal){
        return (pixelVal>>8) & 0xFF;
    }
    
    /**
     * This method will return blue value from the pixel value.
     * 
     * @param pixelVal The pixel value from which blue value is calculated.
     * @return Blue value [0-255].
     */
    public static int getBlueValueFromPixelValue(int pixelVal){
        return pixelVal & 0xFF;
    }
    
    /**
     * This method will return pixel value from the ARGB value.
     * 
     * @param a Alpha value [0-255].
     * @param r Red value [0-255].
     * @param g Green value [0-255].
     * @param b Blue value [0-255].
     * @return Pixel value.
     */
    public static int getPixelValueFromARGBValue(int a, int r, int g, int b){
        return (a<<24) | (r<<16) | (g<<8) | b;
    }
    
    //////////////////////////// Rotation and Flip Methods /////////////////////
    
    /**
     * This method will rotate the image left.
     * 
     * @param img The image to rotate.
     */
    public static void rotateLeft(MyImage img){
        BufferedImage bi = new BufferedImage(img.getImageHeight(), img.getImageWidth(), BufferedImage.TYPE_INT_ARGB);
        for(int sx = img.getImageWidth()-1, y = 0; sx >= 0; sx--, y++){
            for(int sy = 0, x = 0; sy < img.getImageHeight(); sy++, x++){
                bi.setRGB(x, y, img.getPixel(sx, sy));
            }
        }
        img.modifyImageObject(img.getImageHeight(), img.getImageWidth(), bi);
        img.initPixelArray();
    }
    
    /**
     * This method will rotate the image right.
     * <commit_msg>update - HSI methods added<commit_after>package imageFX;

/**
 * File: ImageFX.java
 * 
 * Description:
 * Contains common image processing methods.
 * 
 * @author <NAME>
 * @version 1.0
 * Date: 26-01-2014 sun
 */
import java.awt.image.BufferedImage;

public class ImageFX {
    
    /////////////////////////// Pixel elements ARGB Methods ////////////////////
    
    /**
     * This method will return alpha value from the pixel value.
     * 
     * @param pixelVal The pixel value from which alpha value is calculated.
     * @return Alpha value [0-255].
     */
    public static int getAlphaValueFromPixelValue(int pixelVal){
        return (pixelVal>>24) & 0xFF;
    }
    
    /**
     * This method will return red value from the pixel value.
     * 
     * @param pixelVal The pixel value from which red value is calculated.
     * @return Red value [0-255].
     */
    public static int getRedValueFromPixelValue(int pixelVal){
        return (pixelVal>>16) & 0xFF;
    }
    
    /**
     * This method will return green value from the pixel value.
     * 
     * @param pixelVal The pixel value from which green value is calculated.
     * @return Green value [0-255].
     */
    public static int getGreenValueFromPixelValue(int pixelVal){
        return (pixelVal>>8) & 0xFF;
    }
    
    /**
     * This method will return blue value from the pixel value.
     * 
     * @param pixelVal The pixel value from which blue value is calculated.
     * @return Blue value [0-255].
     */
    public static int getBlueValueFromPixelValue(int pixelVal){
        return pixelVal & 0xFF;
    }
    
    /**
     * This method will return pixel value from the ARGB value.
     * 
     * @param a Alpha value [0-255].
     * @param r Red value [0-255].
     * @param g Green value [0-255].
     * @param b Blue value [0-255].
     * @return Pixel value.
     */
    public static int getPixelValueFromARGBValue(int a, int r, int g, int b){
        return (a<<24) | (r<<16) | (g<<8) | b;
    }
    
    ///////////////////////////// HSI methods //////////////////////////////////
    
    /**
     * This method will change the hue value of the image.
     * This method is using HSI (Hue-Saturation-Intensity) color model.
     * 
     * @param img The image pixels to change.
     * @param hue The hue value to set in degree [0-360]
     */
    public static void HSI_changeImageHueValue(MyImage img, double hue){
        for(int y = 0; y < img.getImageHeight(); y++){
            for(int x = 0; x < img.getImageWidth(); x++){
                img.setHue_HSI(x, y, hue);
            }
        }
    }
    
    /**
     * This method will change the saturation value of the image.
     * This method is using HSI (Hue-Saturation-Intensity) color model.
     * 
     * @param img The image pixels to change.
     * @param saturation The saturation value [0-1]
     */
    public static void HSI_changeImageSaturationValue(MyImage img, double saturation){
        for(int y = 0; y < img.getImageHeight(); y++){
            for(int x = 0; x < img.getImageWidth(); x++){
                img.setSaturation_HSI(x, y, saturation);
            }
        }
    }
    
    /**
     * This method will change the intensity value of the image.
     * This method is using HSI (Hue-Saturation-Intensity) color model.
     * 
     * @param img The image pixels to change.
     * @param intensity The intensity value [0-255]
     */
    public static void HSI_changeImageIntensityValue(MyImage img, double intensity){
        for(int y = 0; y < img.getImageHeight(); y++){
            for(int x = 0; x < img.getImageWidth(); x++){
                img.setIntensity_HSI(x, y, intensity);
            }
        }
    }
    
    //////////////////////////// Rotation and Flip Methods /////////////////////
    
    /**
     * This method will rotate the image left.
     * 
     * @param img The image to rotate.
     */
    public static void rotateLeft(MyImage img){
        BufferedImage bi = new BufferedImage(img.getImageHeight(), img.getImageWidth(), BufferedImage.TYPE_INT_ARGB);
        for(int sx = img.getImageWidth()-1, y = 0; sx >= 0; sx--, y++){
            for(int sy = 0, x = 0; sy < img.getImageHeight(); sy++, x++){
                bi.setRGB(x, y, img.getPixel(sx, sy));
            }
        }
        img.modifyImageObject(img.getImageHeight(), img.getImageWidth(), bi);
        img.initPixelArray();
    }
    
    /**
     * This method will rotate the image right.
     * 
{'fraction_non_alphanumeric': 0.14082758620689656, 'fraction_numerical': 0.01903448275862069, 'mean_word_length': 1.8728209191759113, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2193972', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2095, 'n_words': 704}