InsetCropParser.java 1.48 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.scene7.is.util.RectInt
 *  org.jetbrains.annotations.NotNull
 */
package com.adobe.cq.dam.dm.process.workflow;

import com.adobe.cq.dam.dm.process.workflow.InvalidInsetCrop;
import com.scene7.is.util.RectInt;
import org.jetbrains.annotations.NotNull;

class InsetCropParser {
    InsetCropParser() {
    }

    @NotNull
    public static RectInt parseInsetCrop(@NotNull String value, @NotNull RectInt rect) throws InvalidInsetCrop {
        try {
            if (value.isEmpty()) {
                return rect;
            }
            String[] s = value.split(",");
            if (s.length != 4) {
                throw new InvalidInsetCrop(value);
            }
            int[] inset = new int[4];
            for (int i = 0; i != 4; ++i) {
                inset[i] = Integer.parseInt(s[i]);
                if (inset[i] >= 0) continue;
                throw new InvalidInsetCrop(value);
            }
            int left = rect.x + inset[0];
            int top = rect.y + inset[1];
            int right = rect.x + rect.width - inset[2];
            int bottom = rect.y + rect.height - inset[3];
            if (left < right && top < bottom) {
                return RectInt.rectInt((int)left, (int)top, (int)(right - left), (int)(bottom - top));
            }
            return RectInt.rectInt();
        }
        catch (NumberFormatException e) {
            throw new InvalidInsetCrop(value, e);
        }
    }
}