<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jtrim.image.transform;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ImagingOpException;
import org.jtrim.image.ImageData;

/**
 *
 * @author <NAME>
 */
public final class AffineImageTransformer implements ImageTransformer {
    private static final double RAD_0;
    private static final double RAD_90;
    private static final double RAD_180;
    private static final double RAD_270;

    static {
        BasicImageTransformations.Builder radConvTest;
        radConvTest = new BasicImageTransformations.Builder();

        radConvTest.setRotateInDegrees(0);
        RAD_0 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(90);
        RAD_90 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(180);
        RAD_180 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(270);
        RAD_270 = radConvTest.getRotateInRadians();
    }

    public static AffineTransform getTransformationMatrix(
            BasicImageTransformations transformations,
            double srcWidth, double srcHeight,
            double destWidth, double destHeight) {

        double srcAnchorX = (srcWidth - 1.0) * 0.5;
        double srcAnchorY = (srcHeight - 1.0) * 0.5;

        double destAnchorX = (destWidth - 1.0) * 0.5;
        double destAnchorY = (destHeight - 1.0) * 0.5;

        AffineTransform affineTransf = new AffineTransform();
        affineTransf.translate(transformations.getOffsetX(), transformations.getOffsetY());
        affineTransf.translate(destAnchorX, destAnchorY);
        affineTransf.rotate(transformations.getRotateInRadians());
        if (transformations.isFlipVertical()) affineTransf.scale(-1.0, 1.0);
        if (transformations.isFlipHorizontal()) affineTransf.scale(1.0, -1.0);
        affineTransf.scale(transformations.getZoomX(), transformations.getZoomY());
        affineTransf.translate(-srcAnchorX, -srcAnchorY);

        return affineTransf;
    }

    public static AffineTransform getTransformationMatrix(
            BasicImageTransformations transformations,
            ImageTransformerData input) {

        BufferedImage srcImage = input.getSourceImage();
        if (srcImage == null) {
            return null;
        }

        return getTransformationMatrix(transformations,
                srcImage.getWidth(), srcImage.getHeight(),
                input.getDestWidth(), input.getDestHeight());
    }

    public static boolean isSimpleTransformation(
            BasicImageTransformations transformation) {

        double radRotate = transformation.getRotateInRadians();<commit_msg>Horizontal and vertical flips are handled properly.<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jtrim.image.transform;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ImagingOpException;
import org.jtrim.image.ImageData;

/**
 *
 * @author <NAME>
 */
public final class AffineImageTransformer implements ImageTransformer {
    private static final double RAD_0;
    private static final double RAD_90;
    private static final double RAD_180;
    private static final double RAD_270;

    static {
        BasicImageTransformations.Builder radConvTest;
        radConvTest = new BasicImageTransformations.Builder();

        radConvTest.setRotateInDegrees(0);
        RAD_0 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(90);
        RAD_90 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(180);
        RAD_180 = radConvTest.getRotateInRadians();

        radConvTest.setRotateInDegrees(270);
        RAD_270 = radConvTest.getRotateInRadians();
    }

    public static AffineTransform getTransformationMatrix(
            BasicImageTransformations transformations,
            double srcWidth, double srcHeight,
            double destWidth, double destHeight) {

        double srcAnchorX = (srcWidth - 1.0) * 0.5;
        double srcAnchorY = (srcHeight - 1.0) * 0.5;

        double destAnchorX = (destWidth - 1.0) * 0.5;
        double destAnchorY = (destHeight - 1.0) * 0.5;

        AffineTransform affineTransf = new AffineTransform();
        affineTransf.translate(transformations.getOffsetX(), transformations.getOffsetY());
        affineTransf.translate(destAnchorX, destAnchorY);
        affineTransf.rotate(transformations.getRotateInRadians());
        if (transformations.isFlipHorizontal()) affineTransf.scale(-1.0, 1.0);
        if (transformations.isFlipVertical()) affineTransf.scale(1.0, -1.0);
        affineTransf.scale(transformations.getZoomX(), transformations.getZoomY());
        affineTransf.translate(-srcAnchorX, -srcAnchorY);

        return affineTransf;
    }

    public static AffineTransform getTransformationMatrix(
            BasicImageTransformations transformations,
            ImageTransformerData input) {

        BufferedImage srcImage = input.getSourceImage();
        if (srcImage == null) {
            return null;
        }

        return getTransformationMatrix(transformations,
                srcImage.getWidth(), srcImage.getHeight(),
                input.getDestWidth(), input.getDestHeight());
    }

    public static boolean isSimpleTransformation(
            BasicImageTransformations transformation) {

        double radRotate = transformation.getRotateInRadians();
{'fraction_non_alphanumeric': 0.09006105834464044, 'fraction_numerical': 0.01797829036635007, 'mean_word_length': 3.2061340941512126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '536245', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1631, 'n_words': 343}