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.

AFPImageHandlerRawCCITTFax.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.afp;
  19. import java.awt.Rectangle;
  20. import java.io.IOException;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.xmlgraphics.image.loader.Image;
  24. import org.apache.xmlgraphics.image.loader.ImageFlavor;
  25. import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
  26. import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
  27. import org.apache.xmlgraphics.util.MimeConstants;
  28. import org.apache.fop.afp.AFPDataObjectInfo;
  29. import org.apache.fop.afp.AFPImageObjectInfo;
  30. import org.apache.fop.render.RenderingContext;
  31. /**
  32. * AFPImageHandler implementation which handles CCITT encoded images (CCITT fax group 3/4).
  33. */
  34. public class AFPImageHandlerRawCCITTFax extends AbstractAFPImageHandlerRawStream {
  35. private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
  36. ImageFlavor.RAW_CCITTFAX,
  37. };
  38. /** logging instance */
  39. private final Log log = LogFactory.getLog(AFPImageHandlerRawJPEG.class);
  40. /** {@inheritDoc} */
  41. @Override
  42. protected void setAdditionalParameters(AFPDataObjectInfo dataObjectInfo,
  43. ImageRawStream image) {
  44. AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo;
  45. ImageRawCCITTFax ccitt = (ImageRawCCITTFax)image;
  46. int compression = ccitt.getCompression();
  47. imageObjectInfo.setCompression(compression);
  48. imageObjectInfo.setBitsPerPixel(1);
  49. //CCITTFax flavor doesn't have TIFF associated but the AFP library listens to
  50. //that to identify CCITT encoded images. CCITT is not exclusive to TIFF.
  51. imageObjectInfo.setMimeType(MimeConstants.MIME_TIFF);
  52. }
  53. /** {@inheritDoc} */
  54. @Override
  55. public void handleImage(RenderingContext context, Image image, Rectangle pos)
  56. throws IOException {
  57. log.debug("Embedding undecoded CCITT data as data container...");
  58. super.handleImage(context, image, pos);
  59. }
  60. /** {@inheritDoc} */
  61. @Override
  62. protected AFPDataObjectInfo createDataObjectInfo() {
  63. return new AFPImageObjectInfo();
  64. }
  65. /** {@inheritDoc} */
  66. public int getPriority() {
  67. return 400;
  68. }
  69. /** {@inheritDoc} */
  70. public Class getSupportedImageClass() {
  71. return ImageRawCCITTFax.class;
  72. }
  73. /** {@inheritDoc} */
  74. public ImageFlavor[] getSupportedImageFlavors() {
  75. return FLAVORS;
  76. }
  77. /** {@inheritDoc} */
  78. public boolean isCompatible(RenderingContext targetContext, Image image) {
  79. if (targetContext instanceof AFPRenderingContext) {
  80. AFPRenderingContext afpContext = (AFPRenderingContext)targetContext;
  81. return (afpContext.getPaintingState().isNativeImagesSupported())
  82. && (image == null || image instanceof ImageRawCCITTFax);
  83. }
  84. return false;
  85. }
  86. }