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

ru.olegcherednik.icoman.icl.ImageHeader Maven / Gradle / Ivy

The newest version!
package ru.olegcherednik.icoman.icl;

import ru.olegcherednik.icoman.ImageKey;
import ru.olegcherednik.icoman.Utils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.imageio.stream.ImageInputStream;
import java.io.IOException;

/**
 * @author Oleg Cherednik
 * @since 21.10.2016
 */
@Data
@EqualsAndHashCode(callSuper = true)
final class ImageHeader extends ImageKey {
    public static final int SIZE = 14;

    private final int pos;
    private final int planes;

    public static ImageHeader read(int pos, ImageInputStream in) throws IOException {
        in.skipBytes(6);
        int width = Utils.zeroTo256(in.readUnsignedByte());
        int height = Utils.zeroTo256(in.readUnsignedByte());
        int colors = in.readUnsignedByte();
        in.skipBytes(1);
        int planes = in.readShort();
        int bitsPerPixel = Utils.bitsPerPixel(in.readShort(), colors);
        return new ImageHeader(pos, width, height, bitsPerPixel, planes);
    }

    public ImageHeader(int pos, int width, int height, int bitsPerPixel, int planes) {
        super(width, height, bitsPerPixel);
        this.pos = pos;
        this.planes = planes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy