blob: a5608413596a8098e465985dc69b1099daeffde8 [file] [log] [blame]
/* modified by JKT to integrate into 0.12.0 */
//Title: BoBoGi FOP
//Version:
//Copyright: Copyright (c) 1999
//Author: Sergio Botti
//Company: Dibe Elsag
//Description: xml to pdf converter
package org.apache.xml.fop.image;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class BmpBwImage implements FopImage {
int X;
int Y;
int width;
int height;
int pixelwidth;
int pixelheight;
String ref;
boolean color;
int bitperpixel;
int[] imagemap;
int imagestart;
/*
Costructor read the header of the bmp file to get the size
and the other data
SB
*/
public BmpBwImage(String href,int x,int y,int w,int h)
{
this.ref=href;
this.X=x;
this.Y=y;
int wpos=18;
int hpos=22; //offset positioning for w and height in bmp files
int [] headermap = new int[54];
try{
FileInputStream file=new FileInputStream(ref);
boolean eof=false;
int count=0;
while ((!eof) && (count<54) ) {
int input =file.read();
if (input==-1)
eof=true;
else
headermap[count++]=input;
}
file.close();
}catch (IOException e) {System.err.println("Image not found");}
// gets h & w from headermap
this.pixelwidth = headermap[wpos]+headermap[wpos+1]*256+headermap[wpos+2]*256*256+headermap[wpos+3]*256*256*256;
this.pixelheight = headermap[hpos]+headermap[hpos+1]*256+headermap[hpos+2]*256*256+headermap[hpos+3]*256*256*256;
if (w==0)
this.width=this.pixelwidth*1000;
else
this.width=w;
if (h==0)
this.height=this.pixelheight*1000;
else
this.height=h;
this.imagestart =headermap[10]+headermap[11]*256+headermap[12]*256*256+headermap[13]*256*256*256;
this.bitperpixel=headermap[28];
}
public String gethref() { return this.ref; }
public int getWidth() { return this.width; }
public int getHeight() { return this.height; }
public int getpixelwidth() { return this.pixelwidth; }
public int getpixelheight() { return this.pixelheight; }
public int getX(){ return this.X; }
public int getY(){ return this.Y; }
public int[] getimagemap(){
int input;
int[] temp = new int[nextfourdiv(this.pixelwidth)*(this.pixelheight)];
try {
FileInputStream file = new FileInputStream(this.ref);
int count = 0;
file.skip((long) this.imagestart);
while ((input = file.read()) != -1) {
temp[count++] = input;
}
file.close();
} catch (IOException e) {
System.err.println("Image not found");
}
int[] map = new int[this.pixelheight * this.pixelwidth];
int k = 0;
for (int y = 0; y < this.pixelheight; y++) {
for (int x = 0; x < this.pixelwidth; x++)
map[k++] = temp[y * nextfourdiv(this.pixelwidth) + x];
}
return map;
}
public boolean getcolor(){return false;}
public int getbitperpixel() {return this.bitperpixel;}
private int nextfourdiv(int number) {
return ((number/4)+1)*4;
}
}