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.

DefaultMonochromeBitmapConverter.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.pcl;
  18. import java.awt.RenderingHints;
  19. import java.awt.color.ColorSpace;
  20. import java.awt.image.BufferedImage;
  21. import java.awt.image.ColorConvertOp;
  22. import java.awt.image.RenderedImage;
  23. /**
  24. * Default implementation of the MonochromeBitmapConverter which uses the Java Class Library
  25. * to convert grayscale bitmaps to monochrome bitmaps.
  26. */
  27. public class DefaultMonochromeBitmapConverter implements
  28. MonochromeBitmapConverter {
  29. /** @see MonochromeBitmapConverter#setHint(java.lang.String, java.lang.String) */
  30. public void setHint(String name, String value) {
  31. //ignore, not supported
  32. }
  33. /** @see MonochromeBitmapConverter#convertToMonochrome(java.awt.image.BufferedImage) */
  34. public RenderedImage convertToMonochrome(BufferedImage img) {
  35. BufferedImage buf = new BufferedImage(img.getWidth(), img.getHeight(),
  36. BufferedImage.TYPE_BYTE_BINARY);
  37. RenderingHints hints = new RenderingHints(null);
  38. //This hint doesn't seem to make a difference :-(
  39. hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
  40. ColorConvertOp op = new ColorConvertOp(
  41. ColorSpace.getInstance(ColorSpace.CS_GRAY), hints);
  42. op.filter(img, buf);
  43. return buf;
  44. }
  45. }