All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jcodec.codecs.h264.decode.aso.FlatMBlockMapper Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package org.jcodec.codecs.h264.decode.aso;

/**
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * A block map that that maps macroblocks sequentially in scan order
 * 
 * @author Jay Codec
 * 
 */
public class FlatMBlockMapper implements Mapper {
    private int frameWidthInMbs;
    private int firstMBAddr;

    public FlatMBlockMapper(int frameWidthInMbs, int firstMBAddr) {
        this.frameWidthInMbs = frameWidthInMbs;
        this.firstMBAddr = firstMBAddr;
    }

    public boolean leftAvailable(int index) {
        int mbAddr = index + firstMBAddr;
        boolean atTheBorder = mbAddr % frameWidthInMbs == 0;
        return !atTheBorder && (mbAddr > firstMBAddr);
    }

    public boolean topAvailable(int index) {
        int mbAddr = index + firstMBAddr;
        return mbAddr - frameWidthInMbs >= firstMBAddr;
    }

    public int getAddress(int index) {
        return firstMBAddr + index;
    }

    public int getMbX(int index) {
        return getAddress(index) % frameWidthInMbs;
    }

    public int getMbY(int index) {
        return getAddress(index) / frameWidthInMbs;
    }

    public boolean topRightAvailable(int index) {
        int mbAddr = index + firstMBAddr;
        boolean atTheBorder = (mbAddr + 1) % frameWidthInMbs == 0;
        return !atTheBorder && mbAddr - frameWidthInMbs + 1 >= firstMBAddr;
    }

    public boolean topLeftAvailable(int index) {
        int mbAddr = index + firstMBAddr;
        boolean atTheBorder = mbAddr % frameWidthInMbs == 0;
        return !atTheBorder && mbAddr - frameWidthInMbs - 1 >= firstMBAddr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy