You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FopImageConsumer.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. // Author: Eric SCHAEFFER
  8. // Description: implement ImageConsumer for FopImage classes
  9. package org.apache.fop.image;
  10. // Java
  11. import java.util.Hashtable;
  12. import java.awt.image.*;
  13. import java.awt.*;
  14. import java.lang.reflect.Array;
  15. // CONSUMER CLASS
  16. public class FopImageConsumer implements ImageConsumer {
  17. protected int width = -1;
  18. protected int height = -1;
  19. protected Integer imageStatus = new Integer(-1);
  20. protected int hints = 0;
  21. protected Hashtable properties = null;
  22. protected ColorModel cm = null;
  23. protected ImageProducer ip = null;
  24. public FopImageConsumer(ImageProducer iprod) {
  25. this.ip = iprod;
  26. }
  27. public void imageComplete(int status) {
  28. /*
  29. * log.error("Status ");
  30. * if (status == ImageConsumer.COMPLETESCANLINES) {
  31. * log.error("CompleteScanLines");
  32. * } else if (status == ImageConsumer.IMAGEABORTED) {
  33. * log.error("ImageAborted");
  34. * } else if (status == ImageConsumer.IMAGEERROR) {
  35. * log.error("ImageError");
  36. * } else if (status == ImageConsumer.RANDOMPIXELORDER) {
  37. * log.error("RandomPixelOrder");
  38. * } else if (status == ImageConsumer.SINGLEFRAME) {
  39. * log.error("SingleFrame");
  40. * } else if (status == ImageConsumer.SINGLEFRAMEDONE) {
  41. * log.error("SingleFrameDone");
  42. * } else if (status == ImageConsumer.SINGLEPASS) {
  43. * log.error("SinglePass");
  44. * } else if (status == ImageConsumer.STATICIMAGEDONE) {
  45. * log.error("StaticImageDone");
  46. * } else if (status == ImageConsumer.TOPDOWNLEFTRIGHT) {
  47. * log.error("TopDownLeftRight");
  48. * }
  49. */
  50. synchronized (this.imageStatus) {
  51. // Need to stop status if image done
  52. if (imageStatus.intValue() != ImageConsumer.STATICIMAGEDONE &&
  53. imageStatus.intValue() != ImageConsumer.SINGLEFRAMEDONE)
  54. this.imageStatus = new Integer(status);
  55. }
  56. }
  57. public void setColorModel(ColorModel model) {
  58. // log.error("setColorModel: " + model);
  59. this.cm = model;
  60. }
  61. public void setDimensions(int width, int height) {
  62. // log.error("setDimension: w=" + width + " h=" + height);
  63. this.width = width;
  64. this.height = height;
  65. }
  66. public void setHints(int hintflags) {
  67. // log.error("setHints: " + hintflags);
  68. this.hints = hintflags;
  69. }
  70. public void setProperties(Hashtable props) {
  71. // log.error("setProperties: " + props);
  72. this.properties = props;
  73. }
  74. public void setPixels(int x, int y, int w, int h, ColorModel model,
  75. byte[] pixels, int off, int scansize) {}
  76. public void setPixels(int x, int y, int w, int h, ColorModel model,
  77. int[] pixels, int off, int scansize) {}
  78. public boolean isImageReady() throws Exception {
  79. synchronized (this.imageStatus) {
  80. if (this.imageStatus.intValue() == ImageConsumer.IMAGEABORTED)
  81. throw new Exception("Image aborted");
  82. if (this.imageStatus.intValue() == ImageConsumer.IMAGEERROR)
  83. throw new Exception("Image error");
  84. if (imageStatus.intValue() == ImageConsumer.STATICIMAGEDONE ||
  85. imageStatus.intValue() == ImageConsumer.SINGLEFRAMEDONE)
  86. return true;
  87. return false;
  88. }
  89. }
  90. public int getWidth() {
  91. return this.width;
  92. }
  93. public int getHeight() {
  94. return this.height;
  95. }
  96. public ColorModel getColorModel() {
  97. return this.cm;
  98. }
  99. public int[] getImage() throws Exception {
  100. int tmpMap[] = new int[this.width * this.height];
  101. PixelGrabber pg = new PixelGrabber(this.ip, 0, 0, this.width,
  102. this.height, tmpMap, 0, this.width);
  103. pg.setDimensions(this.width, this.height);
  104. pg.setColorModel(this.cm);
  105. pg.setHints(this.hints);
  106. pg.setProperties(this.properties);
  107. try {
  108. pg.grabPixels();
  109. } catch (InterruptedException intex) {
  110. throw new Exception("Image grabbing interrupted : " +
  111. intex.getMessage());
  112. }
  113. return tmpMap;
  114. }
  115. }