IppRect.java 5.08 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.scene7.is.ipp.messages;

import com.scene7.is.ipp.messages.Ipp;
import com.scene7.is.ipp.messages.IppInt;
import com.scene7.is.ipp.messages.Offset;
import java.io.IOException;
import java.io.Writer;

public class IppRect {
    private int x_;
    private int y_;
    private int w_;
    private int h_;

    public IppRect(int x, int y, int w, int h) {
        this.x_ = x;
        this.y_ = y;
        this.w_ = w;
        this.h_ = h;
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        buffer.append("x: ").append(String.valueOf(this.x_)).append(" ");
        buffer.append("y: ").append(String.valueOf(this.y_)).append(" ");
        buffer.append("w: ").append(String.valueOf(this.w_)).append(" ");
        buffer.append("h: ").append(String.valueOf(this.h_)).append(" ");
        buffer.append("]");
        return buffer.toString();
    }

    public boolean equals(Object o) {
        if (!(o instanceof IppRect)) {
            return false;
        }
        IppRect e = (IppRect)o;
        if (this.x_ != e.x_) {
            return false;
        }
        if (this.y_ != e.y_) {
            return false;
        }
        if (this.w_ != e.w_) {
            return false;
        }
        if (this.h_ != e.h_) {
            return false;
        }
        return true;
    }

    public static IppRect Unstuff(byte[] arr, Offset arrayPos) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppRect align");
        int x = IppInt.Unstuff(arr, arrayPos);
        int y = IppInt.Unstuff(arr, arrayPos);
        int w = IppInt.Unstuff(arr, arrayPos);
        int h = IppInt.Unstuff(arr, arrayPos);
        return new IppRect(x, y, w, h);
    }

    public static IppRect[] UnstuffArray(byte[] arr, Offset arrayPos) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppRect alignemt");
        int count = IppInt.Unstuff(arr, arrayPos);
        int size = IppInt.Unstuff(arr, arrayPos);
        Ipp.Assert(count == 0 || size >= 16, "IppRect count");
        Offset roff = new Offset(IppInt.Unstuff(arr, arrayPos));
        Offset loff = new Offset(roff.val);
        IppRect[] result = new IppRect[count];
        for (int i = 0; i < count; ++i) {
            loff.val = roff.val;
            result[i] = IppRect.Unstuff(arr, loff);
            roff.val += size;
        }
        return result;
    }

    public static IppRect[] UnstuffFixedArray(byte[] arr, Offset arrayPos, int count) {
        IppRect[] result = new IppRect[count];
        for (int i = 0; i < count; ++i) {
            result[i] = IppRect.Unstuff(arr, arrayPos);
        }
        return result;
    }

    public static void Stuff(byte[] arr, Offset arrayPos, Offset varPos, IppRect val) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppRect align");
        if (val != null) {
            IppInt.Stuff(arr, arrayPos, varPos, val.x());
            IppInt.Stuff(arr, arrayPos, varPos, val.y());
            IppInt.Stuff(arr, arrayPos, varPos, val.w());
            IppInt.Stuff(arr, arrayPos, varPos, val.h());
        } else {
            Ipp.StuffNullBytes(arr, arrayPos, 16);
        }
    }

    public static void StuffArray(byte[] arr, Offset arrayPos, Offset varPos, IppRect[] val) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppRect stuffarray align");
        int len = val != null ? val.length : 0;
        IppInt.Stuff(arr, arrayPos, varPos, len);
        IppInt.Stuff(arr, arrayPos, varPos, 16);
        Ipp.StuffOffset(arr, arrayPos, varPos, len > 0 ? 4 : 1);
        Offset varvarPos = new Offset(varPos.val + 16 * len);
        for (int i = 0; i < len; ++i) {
            IppRect.Stuff(arr, varPos, varvarPos, val[i]);
        }
        varPos.val = varvarPos.val;
    }

    public static void StuffFixedArray(byte[] arr, Offset arrayPos, Offset varPos, int count, IppRect[] val) {
        Ipp.Assert(val.length == count, "IppRect count");
        for (int i = 0; i < count; ++i) {
            IppRect.Stuff(arr, arrayPos, varPos, val[i]);
        }
    }

    public static void Print(Writer tf, String label, IppRect it) throws IOException {
        String ll = label + "IppRect: ";
        if (it == null) {
            tf.write(ll + "NULL!!\n");
            return;
        }
        tf.write(ll + "\n");
        IppInt.Print(tf, ll + "x: ", it.x());
        IppInt.Print(tf, ll + "y: ", it.y());
        IppInt.Print(tf, ll + "w: ", it.w());
        IppInt.Print(tf, ll + "h: ", it.h());
    }

    public static void PrintArray(Writer tf, String label, IppRect[] it) throws IOException {
        String ll = label + "IppRect Array, length: ";
        tf.write(ll);
        if (it == null) {
            tf.write("NULL!!!\n");
            return;
        }
        tf.write("" + it.length + "\n");
        for (int i = 0; i < it.length; ++i) {
            ll = label + "IppRect[" + String.valueOf(i) + "]: ";
            IppRect.Print(tf, ll, it[i]);
        }
    }

    public int x() {
        return this.x_;
    }

    public int y() {
        return this.y_;
    }

    public int w() {
        return this.w_;
    }

    public int h() {
        return this.h_;
    }
}