選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

GifJpegImage.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* modified by JKT to integrate into 0.12.0 */
  2. //Title: BoBoGi FOP
  3. //Version:
  4. //Copyright: Copyright (c) 1999
  5. //Author: Sergio Botti
  6. //Company: Dibe Elsag
  7. //Description: xml to pdf converter
  8. package org.apache.xml.fop.image;
  9. import java.util.Hashtable;
  10. import java.net.URL;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.awt.image.*;
  14. import java.awt.Image;
  15. import java.awt.Toolkit;
  16. public class GifJpegImage implements FopImage {
  17. int X;
  18. int Y;
  19. int width;
  20. int height;
  21. int pixelwidth;
  22. int pixelheight;
  23. String ref;
  24. boolean color=true;
  25. int bitperpixel=8;
  26. int[] imagemap;
  27. int[] tempmap;
  28. /*
  29. Costructor read the header of the bmp file to get the size
  30. and the other data
  31. SB
  32. */
  33. public GifJpegImage(String href,int x,int y,int w,int h)
  34. {
  35. this.ref=href;
  36. this.X=x;
  37. this.Y=y;
  38. this.pixelheight=-1;
  39. this.pixelwidth=-1;
  40. try {
  41. URL url = new URL(href);
  42. ImageProducer ip = (ImageProducer)url.getContent();
  43. FopImageConsumer consumer = new FopImageConsumer();
  44. ip.startProduction(consumer);
  45. while ((this.pixelheight = consumer.getHeight())==-1) {}
  46. while ((this.pixelwidth = consumer.getWidth())==-1) {}
  47. this.tempmap = new int[this.pixelwidth*this.pixelheight];
  48. //Image img=Toolkit.getDefaultToolkit().getImage("prova.gif");
  49. // Image img=Toolkit.getDefaultToolkit().getImage(url);
  50. PixelGrabber pg = new PixelGrabber(ip,0,0,this.pixelwidth,this.pixelheight,this.tempmap,0,w);
  51. try {
  52. pg.grabPixels();
  53. }catch (InterruptedException e) {System.err.println("Image grabbing interrupted");}
  54. } catch (ClassCastException e) {System.err.println("Image format not supported: " + href);
  55. } catch (Exception e) {System.err.println("Error loading image " + href + " : " +e);
  56. }
  57. if (w==0)
  58. this.width=this.pixelwidth*1000;
  59. else
  60. this.width=w;
  61. if (h==0)
  62. this.height=this.pixelheight*1000;
  63. else
  64. this.height=h;
  65. }
  66. //
  67. public static class FopImageConsumer implements ImageConsumer {
  68. int width = -1;
  69. int height = -1;
  70. public void imageComplete(int status) {}
  71. public void setColorModel(ColorModel model) {}
  72. public void setDimensions(int width, int height) {
  73. this.width = width;
  74. this.height = height;
  75. }
  76. public void setHints(int hintflags) {}
  77. public void setPixels(int x, int y, int w, int h,ColorModel model, byte[] pixels,int off, int scansize) {}
  78. public void setPixels(int x, int y, int w, int h,ColorModel model, int[] pixels,int off, int scansize) {}
  79. public void setProperties(Hashtable props) {}
  80. public int getWidth() { return this.width; }
  81. public int getHeight() { return this.height; }
  82. }
  83. //
  84. public String gethref() { return this.ref; }
  85. public int getWidth() { return this.width; }
  86. public int getHeight() { return this.height; }
  87. public int getpixelwidth() { return this.pixelwidth; }
  88. public int getpixelheight() { return this.pixelheight; }
  89. public int getX(){ return this.X; }
  90. public int getY(){ return this.Y; }
  91. public int[] getimagemap(){
  92. this.imagemap=new int[this.pixelheight*this.pixelwidth*3];
  93. int count=0;
  94. int i;
  95. for(i=0;i<(this.pixelheight*this.pixelwidth);i++)
  96. {
  97. int red = ((this.tempmap[i]>>16) & 0xff);
  98. int green = ((this.tempmap[i]>> 8) & 0xff);
  99. int blue = ((this.tempmap[i] ) & 0xff);
  100. this.imagemap[count++]=red;
  101. this.imagemap[count++]=green;
  102. this.imagemap[count++]=blue;
  103. }
  104. return imagemap;
  105. }
  106. public boolean getcolor(){return true;}
  107. public int getbitperpixel() {return this.bitperpixel;}
  108. }