bitmaps
Class Bitmap

java.lang.Object
  extended by bitmaps.Bitmap
Direct Known Subclasses:
MonochromeBitmap

public class Bitmap
extends java.lang.Object

Note that the use of integers prevents images from being used if they have more than Integer.MAX_VALUE pixels either vertically or horizontally. Note: Pixel rows must always be a multiple of four in length and residual spaces are padded with zeroes...these should not be modified by any steganography implementations.

Author:
Jonathan L Dautrich Jr.

Field Summary
(package private)  int bitsPerPixel
           
(package private)  int byteRowPadding
           
(package private)  int bytesPerPixel
           
(package private)  int colorTableCount
           
(package private)  long dataStartLocation
           
private static int FILE_HEADER_LENGTH
           
private  byte[] fileHeader
           
(package private)  long fileSize
           
(package private)  int fillerLength
           
private  byte[] fillerSpace
           
private  byte[] infoHeader
           
(package private)  int infoHeaderLength
           
private static int IOS
           
private static int MIN_INFO_HEADER_LENGTH
           
(package private)  int pixelHeight
           
private  Pixel[][] pixels
           
(package private)  int pixelWidth
           
(package private)  int rowByteCount
           
private  byte[][] rowPadding
           
private  byte[] trailingData
           
private  boolean verbose
           
 
Constructor Summary
Bitmap(Bitmap bitmap)
          Creates a new Bitmap from the specified bitmap, deep cloning it down to the primitive fields.
Bitmap(java.io.File file)
           
Bitmap(int bitsPerPixel, int pixelHeight, int pixelWidth)
          Creates a new bitmap, setting header values based on parameters.
 
Method Summary
private  void extractHeaderData()
          Populates the global header fields with the appropriate values from the byte arrays.
private  void extractPixelData(java.io.FileInputStream inStream)
          Stores the pixel data from the file in the 2-D pixels Pixel object array
static long getDataValue(byte[] bytes, int start, int end)
          Bytes are expected to be in little endian format.
 int getPixelCount()
           
 int getPixelHeight()
           
 Pixel[][] getPixels()
          Returns the bitmap pixel array reference.
 int getPixelWidth()
           
private  void handleException(java.lang.Exception e)
           
 boolean isVerbose()
           
private  int longToInt(long val, java.lang.String err)
          Converts a long to an int, ensuring the value does not exceed max int value.
private  void printArraySizes()
           
private  void printHeaderData()
           
static long setDataValue(long value, byte[] bytes, int start, int end)
          Bytes will be in little endian format.
private  void setHeaderData()
          Sets data in the infoHeader and fileHeader based on the bitmaps current field values.
 void setVerbose(boolean verbose)
           
private  void writePixelBitData(java.io.FileOutputStream outStream)
           
private  void writePixelData(java.io.FileOutputStream outStream)
           
 void writeToFile(java.io.File outFile)
          Writes the current bitmap out to the specified file.
 void writeToFileGrayscale(java.io.File outFile)
          Writes the current bitmap out to the specified file, first matching all blue and green pixel values to the red pixel values, to produce a gray-scale image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_HEADER_LENGTH

private static final int FILE_HEADER_LENGTH
See Also:
Constant Field Values

MIN_INFO_HEADER_LENGTH

private static final int MIN_INFO_HEADER_LENGTH
See Also:
Constant Field Values

IOS

private static final int IOS
See Also:
Constant Field Values

fileHeader

private byte[] fileHeader

infoHeader

private byte[] infoHeader

fillerSpace

private byte[] fillerSpace

pixels

private Pixel[][] pixels

rowPadding

private byte[][] rowPadding

trailingData

private byte[] trailingData

verbose

private boolean verbose

fileSize

long fileSize

infoHeaderLength

int infoHeaderLength

dataStartLocation

long dataStartLocation

fillerLength

int fillerLength

pixelWidth

int pixelWidth

pixelHeight

int pixelHeight

bitsPerPixel

int bitsPerPixel

bytesPerPixel

int bytesPerPixel

byteRowPadding

int byteRowPadding

rowByteCount

int rowByteCount

colorTableCount

int colorTableCount
Constructor Detail

Bitmap

public Bitmap(java.io.File file)
       throws java.io.IOException
Throws:
java.io.IOException

Bitmap

public Bitmap(Bitmap bitmap)
Creates a new Bitmap from the specified bitmap, deep cloning it down to the primitive fields.

Parameters:
bitmap -

Bitmap

public Bitmap(int bitsPerPixel,
              int pixelHeight,
              int pixelWidth)
Creates a new bitmap, setting header values based on parameters. Initializes with all-zero pixel values.

Parameters:
bitsPerPixel -
pixelHeight -
pixelWidth -
Method Detail

setHeaderData

private void setHeaderData()
Sets data in the infoHeader and fileHeader based on the bitmaps current field values. Overwrites any existing values. Assumes values are consistent (e.g. pixelWidth, pixelHeight, bitsPerPixel and fileSize, etc.)


getPixels

public Pixel[][] getPixels()
Returns the bitmap pixel array reference.

Returns:

writeToFile

public void writeToFile(java.io.File outFile)
Writes the current bitmap out to the specified file.

Parameters:
outFile -

writeToFileGrayscale

public void writeToFileGrayscale(java.io.File outFile)
Writes the current bitmap out to the specified file, first matching all blue and green pixel values to the red pixel values, to produce a gray-scale image.

Parameters:
outFile -

writePixelData

private void writePixelData(java.io.FileOutputStream outStream)
                     throws java.io.IOException
Throws:
java.io.IOException

writePixelBitData

private void writePixelBitData(java.io.FileOutputStream outStream)
                        throws java.io.IOException
Throws:
java.io.IOException

extractHeaderData

private void extractHeaderData()
Populates the global header fields with the appropriate values from the byte arrays.


printHeaderData

private void printHeaderData()

printArraySizes

private void printArraySizes()

extractPixelData

private void extractPixelData(java.io.FileInputStream inStream)
                       throws java.io.IOException
Stores the pixel data from the file in the 2-D pixels Pixel object array

Throws:
java.io.IOException

getDataValue

public static long getDataValue(byte[] bytes,
                                int start,
                                int end)
Bytes are expected to be in little endian format. Seven bytes at most can be handled. Returned value will be unsigned. Byte range includes byte start, byte end, and all bytes in-between.

Parameters:
bytes -
start -
end -
Returns:
Value of byte range taken from little endian format, or -1 if something is wrong with the byte range.

setDataValue

public static long setDataValue(long value,
                                byte[] bytes,
                                int start,
                                int end)
Bytes will be in little endian format. Input should be a positive integer. Will set the bytes in the specified range to the long value. Thus seven bytes at most can be set. Byte range includes byte start, byte end, and all bytes in-between.

Parameters:
bytes -
start -
end -
Returns:
Actual value to which the bytes have been set, or -1 if something is wrong with the byte range.

longToInt

private int longToInt(long val,
                      java.lang.String err)
Converts a long to an int, ensuring the value does not exceed max int value.

Parameters:
val -
err -
Returns:

handleException

private void handleException(java.lang.Exception e)

getPixelWidth

public int getPixelWidth()

getPixelHeight

public int getPixelHeight()

getPixelCount

public int getPixelCount()

isVerbose

public boolean isVerbose()
Returns:
current output verbosity boolean

setVerbose

public void setVerbose(boolean verbose)
Parameters:
verbose - sets verbose output boolean