IppPixel.java 4.82 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.IppByteArray;
import com.scene7.is.ipp.messages.IppInt;
import com.scene7.is.ipp.messages.IppPixelType;
import com.scene7.is.ipp.messages.Offset;
import java.io.IOException;
import java.io.Writer;

public class IppPixel {
    private int type_;
    private byte[] value_;

    public IppPixel(int type, byte[] value) {
        this.type_ = type;
        this.value_ = value;
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        buffer.append("type: ").append(String.valueOf(this.type_)).append(" ");
        buffer.append("value: ").append(String.valueOf(this.value_)).append(" ");
        buffer.append("]");
        return buffer.toString();
    }

    public boolean equals(Object o) {
        if (!(o instanceof IppPixel)) {
            return false;
        }
        IppPixel e = (IppPixel)o;
        if (this.type_ != e.type_) {
            return false;
        }
        if (this.value_.length != e.value_.length) {
            return false;
        }
        for (int i = 0; i < this.value_.length; ++i) {
            if (this.value_[i] == e.value_[i]) continue;
            return false;
        }
        return true;
    }

    public static IppPixel Unstuff(byte[] arr, Offset arrayPos) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppPixel align");
        int type = IppInt.Unstuff(arr, arrayPos);
        byte[] value = IppByteArray.Unstuff(arr, arrayPos);
        return new IppPixel(type, value);
    }

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

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

    public static void Stuff(byte[] arr, Offset arrayPos, Offset varPos, IppPixel val) {
        Ipp.Assert((arrayPos.val & 3) == 0, "IppPixel align");
        if (val != null) {
            IppInt.Stuff(arr, arrayPos, varPos, val.type());
            IppByteArray.Stuff(arr, arrayPos, varPos, val.value());
        } else {
            Ipp.StuffNullBytes(arr, arrayPos, 12);
        }
    }

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

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

    public static void Print(Writer tf, String label, IppPixel it) throws IOException {
        String ll = label + "IppPixel: ";
        if (it == null) {
            tf.write(ll + "NULL!!\n");
            return;
        }
        tf.write(ll + "\n");
        IppPixelType.Print(tf, ll + "type: ", it.type());
        IppByteArray.Print(tf, ll + "value: ", it.value());
    }

    public static void PrintArray(Writer tf, String label, IppPixel[] it) throws IOException {
        String ll = label + "IppPixel 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 + "IppPixel[" + String.valueOf(i) + "]: ";
            IppPixel.Print(tf, ll, it[i]);
        }
    }

    public void adjustVarPos(Offset varPos) {
        varPos.val += this.value_.length;
    }

    public int type() {
        return this.type_;
    }

    public byte[] value() {
        return this.value_;
    }
}