Package ch.heigvd.dai.utilities
Class BmpFile
java.lang.Object
ch.heigvd.dai.utilities.BmpFile
Implements the required logic to parse a bitmap file and modify its content.
- Author:
- Pedro Alves da Silva, Gonçalo Carvalheiro Heleno
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final Stringprivate intprivate booleanprivate intprivate byte[]private intprivate static final intprivate static final intprivate static final intprivate static final intstatic final intstatic final intstatic final intstatic final intprivate static final String[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bits belonging to the hidden message per data byte.intReturns the hidden message's length.byte[]Returns the pixel array that was read from the BMP file.booleanReturns whether this file has a hidden message inside.private booleanisValidMagic(byte[] magicBytes) Checks whether the provided magic bytes are valid for a bitmap file.private voidreadBitmapHeader(BufferedInputStream fileBuffer) Reads and checks the file's header.private voidreadPixelArray(BufferedInputStream fileBuffer) Reads the bitmap file's pixel array.voidDumps the pixel array into the provided output file.voidsetData(byte[] data, int messageLength, int bitsPerByte) Changes the pixel array data, hidden message length, and number of bits per data byte.
-
Field Details
-
VALID_MAGICS
-
MIN_MESSAGE_LENGTH
public static final int MIN_MESSAGE_LENGTH- See Also:
-
MAX_MESSAGE_LENGTH
public static final int MAX_MESSAGE_LENGTH- See Also:
-
MIN_BITS_PER_BYTE
public static final int MIN_BITS_PER_BYTE- See Also:
-
MAX_BITS_PER_BYTE
public static final int MAX_BITS_PER_BYTE- See Also:
-
BITS_PER_BYTE_SHIFT
private static final int BITS_PER_BYTE_SHIFT- See Also:
-
MAGIC_BYTES_LEN
private static final int MAGIC_BYTES_LEN- See Also:
-
HEADER_FIELDS_LEN
private static final int HEADER_FIELDS_LEN- See Also:
-
HEADER_LEN
private static final int HEADER_LEN- See Also:
-
_hasMessage
private boolean _hasMessage -
_pixelArray
private byte[] _pixelArray -
_fileSize
private int _fileSize -
_pixelArrayOffset
private int _pixelArrayOffset -
_messageLength
private int _messageLength -
_bitsPerByte
private int _bitsPerByte -
_bmpFilePath
-
-
Constructor Details
-
BmpFile
Parses and splits a bitmap file into useful data.- Parameters:
bmpFilePath- aStringwith the path to a bitmap file- Throws:
BmpFileException- if the bitmap file is not validIOException- if there is an IO error when handling the bitmap file
-
-
Method Details
-
hasMessage
public boolean hasMessage()Returns whether this file has a hidden message inside.- Returns:
trueif a message is present,falseif not
-
getMessageLength
public int getMessageLength()Returns the hidden message's length.- Returns:
- Hidden message's length if one is present, or 0 if no message is hidden
-
getBitsPerByte
public int getBitsPerByte()Returns the number of bits belonging to the hidden message per data byte.- Returns:
- an
intwith the number of bits per data byte
-
setData
public void setData(byte[] data, int messageLength, int bitsPerByte) Changes the pixel array data, hidden message length, and number of bits per data byte.- Parameters:
data- new pixel array as abyte[]messageLength- new message lengthbitsPerByte- number of bits per data byte
-
getPixelArray
public byte[] getPixelArray()Returns the pixel array that was read from the BMP file.This function returns a copy of the pixel array of the instance.
- Returns:
- a
byte[]with the pixel array
-
saveFile
Dumps the pixel array into the provided output file.Note that the original input file must still exist.
- Parameters:
outputFilePath- aStringwith the path to the output file which must not be the same file as the input file- Throws:
IOException- if an IO error occurs with either the input or output file
-
isValidMagic
private boolean isValidMagic(byte[] magicBytes) Checks whether the provided magic bytes are valid for a bitmap file.- Parameters:
magicBytes- abyte[]containing the magic bytes- Returns:
trueif magic is valid,falseif not
-
readBitmapHeader
Reads and checks the file's header.- Parameters:
fileBuffer- aBufferedInputStreamto read from- Throws:
BmpFileException- if the function fails to read the file's header
-
readPixelArray
Reads the bitmap file's pixel array.- Parameters:
fileBuffer- aBufferedInputStreamto read from- Throws:
BmpFileException- if the function fails to read the pixel array
-