Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "Fop" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. /* modified by JKT to integrate into 0.12.0 */
  41. //Title: BoBoGi FOP
  42. //Version:
  43. //Copyright: Copyright (c) 1999
  44. //Author: Sergio Botti
  45. //Company: Dibe Elsag
  46. //Description: xml to pdf converter
  47. package org.apache.xml.fop.image;
  48. import java.io.FileInputStream;
  49. import java.io.IOException;
  50. import java.io.PrintWriter;
  51. public class BmpBwImage implements FopImage {
  52. int X;
  53. int Y;
  54. int width;
  55. int height;
  56. int pixelwidth;
  57. int pixelheight;
  58. String ref;
  59. boolean color;
  60. int bitperpixel;
  61. int[] imagemap;
  62. int imagestart;
  63. /*
  64. Costructor read the header of the bmp file to get the size
  65. and the other data
  66. SB
  67. */
  68. public BmpBwImage(String href,int x,int y,int w,int h)
  69. {
  70. this.ref=href;
  71. this.X=x;
  72. this.Y=y;
  73. int wpos=18;
  74. int hpos=22; //offset positioning for w and height in bmp files
  75. int [] headermap = new int[54];
  76. try{
  77. FileInputStream file=new FileInputStream(ref);
  78. boolean eof=false;
  79. int count=0;
  80. while ((!eof) && (count<54) ) {
  81. int input =file.read();
  82. if (input==-1)
  83. eof=true;
  84. else
  85. headermap[count++]=input;
  86. }
  87. file.close();
  88. }catch (IOException e) {System.err.println("Image not found");}
  89. // gets h & w from headermap
  90. this.pixelwidth = headermap[wpos]+headermap[wpos+1]*256+headermap[wpos+2]*256*256+headermap[wpos+3]*256*256*256;
  91. this.pixelheight = headermap[hpos]+headermap[hpos+1]*256+headermap[hpos+2]*256*256+headermap[hpos+3]*256*256*256;
  92. if (w==0)
  93. this.width=this.pixelwidth*1000;
  94. else
  95. this.width=w;
  96. if (h==0)
  97. this.height=this.pixelheight*1000;
  98. else
  99. this.height=h;
  100. this.imagestart =headermap[10]+headermap[11]*256+headermap[12]*256*256+headermap[13]*256*256*256;
  101. this.bitperpixel=headermap[28];
  102. }
  103. public String gethref() { return this.ref; }
  104. public int getWidth() { return this.width; }
  105. public int getHeight() { return this.height; }
  106. public int getpixelwidth() { return this.pixelwidth; }
  107. public int getpixelheight() { return this.pixelheight; }
  108. public int getX(){ return this.X; }
  109. public int getY(){ return this.Y; }
  110. public int[] getimagemap(){
  111. int input;
  112. int[] temp = new int[nextfourdiv(this.pixelwidth)*(this.pixelheight)];
  113. try {
  114. FileInputStream file = new FileInputStream(this.ref);
  115. int count = 0;
  116. file.skip((long) this.imagestart);
  117. while ((input = file.read()) != -1) {
  118. temp[count++] = input;
  119. }
  120. file.close();
  121. } catch (IOException e) {
  122. System.err.println("Image not found");
  123. }
  124. int[] map = new int[this.pixelheight * this.pixelwidth];
  125. int k = 0;
  126. for (int y = 0; y < this.pixelheight; y++) {
  127. for (int x = 0; x < this.pixelwidth; x++)
  128. map[k++] = temp[y * nextfourdiv(this.pixelwidth) + x];
  129. }
  130. return map;
  131. }
  132. public boolean getcolor(){return false;}
  133. public int getbitperpixel() {return this.bitperpixel;}
  134. private int nextfourdiv(int number) {
  135. return ((number/4)+1)*4;
  136. }
  137. }