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.

ImageSegment.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.afp.ioca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.Factory;
  22. import org.apache.fop.afp.modca.AbstractNamedAFPObject;
  23. /**
  24. * An Image Segment is represented by a set of self-defining fields, fields
  25. * that describe their own contents. It starts with a Begin Segment, and
  26. * ends with an End Segment.
  27. *
  28. * Between the Begin Segment and End Segment is the image information to
  29. * be processed, called the Image Content.
  30. *
  31. * Only one Image Content can exist within a single IOCA Image Segment.
  32. */
  33. public class ImageSegment extends AbstractNamedAFPObject {
  34. /**
  35. * The ImageContent for the image segment
  36. */
  37. private ImageContent imageContent;
  38. private final Factory factory;
  39. /**
  40. * Constructor for the image segment with the specified name,
  41. * the name must be a fixed length of eight characters.
  42. * @param factory the object factory
  43. *
  44. * @param name the name of the image.
  45. */
  46. public ImageSegment(Factory factory, String name) {
  47. super(name);
  48. this.factory = factory;
  49. }
  50. /**
  51. * Returns the image content object associated with this image segment.
  52. * @return the image content
  53. */
  54. public ImageContent getImageContent() {
  55. if (imageContent == null) {
  56. this.imageContent = factory.createImageContent();
  57. }
  58. return imageContent;
  59. }
  60. /**
  61. * Sets the image size parameters resolution, hsize and vsize.
  62. *
  63. * @param hsize The horizontal size of the image.
  64. * @param vsize The vertical size of the image.
  65. * @param hresol The horizontal resolution of the image.
  66. * @param vresol The vertical resolution of the image.
  67. */
  68. public void setImageSize(int hsize, int vsize, int hresol, int vresol) {
  69. ImageSizeParameter imageSizeParameter
  70. = factory.createImageSizeParameter(hsize, vsize, hresol, vresol);
  71. getImageContent().setImageSizeParameter(imageSizeParameter);
  72. }
  73. /**
  74. * Sets the image encoding.
  75. *
  76. * @param encoding The image encoding.
  77. */
  78. public void setEncoding(byte encoding) {
  79. getImageContent().setImageEncoding(encoding);
  80. }
  81. /**
  82. * Sets the image compression.
  83. *
  84. * @param compression The image compression.
  85. */
  86. public void setCompression(byte compression) {
  87. getImageContent().setImageCompression(compression);
  88. }
  89. /**
  90. * Sets the image IDE size.
  91. *
  92. * @param size The IDE size.
  93. */
  94. public void setIDESize(byte size) {
  95. getImageContent().setImageIDESize(size);
  96. }
  97. /**
  98. * Sets the image IDE color model.
  99. *
  100. * @param colorModel the IDE color model.
  101. * @deprecated Use {@link IDEStructureParameter#setColorModel(byte)} instead.
  102. */
  103. public void setIDEColorModel(byte colorModel) {
  104. getImageContent().setImageIDEColorModel(colorModel);
  105. }
  106. /**
  107. * Set either additive or subtractive mode (used for ASFLAG).
  108. * @param subtractive true for subtractive mode, false for additive mode
  109. * @deprecated Use {@link IDEStructureParameter#setSubtractive(boolean)} instead.
  110. */
  111. public void setSubtractive(boolean subtractive) {
  112. getImageContent().setSubtractive(subtractive);
  113. }
  114. /**
  115. * Set the data image data.
  116. *
  117. * @param imageData the image data
  118. */
  119. public void setData(byte[] imageData) {
  120. getImageContent().setImageData(imageData);
  121. }
  122. /** {@inheritDoc} */
  123. public void writeContent(OutputStream os) throws IOException {
  124. if (imageContent != null) {
  125. imageContent.writeToStream(os);
  126. }
  127. }
  128. private static final int NAME_LENGTH = 4;
  129. /** {@inheritDoc} */
  130. protected int getNameLength() {
  131. return NAME_LENGTH;
  132. }
  133. /** {@inheritDoc} */
  134. protected void writeStart(OutputStream os) throws IOException {
  135. //Name disabled, it's optional and not referenced by our code
  136. //byte[] nameBytes = getNameBytes();
  137. byte[] data = new byte[] {
  138. 0x70, // ID
  139. 0x00, // Length
  140. /*
  141. nameBytes[0], // Name byte 1
  142. nameBytes[1], // Name byte 2
  143. nameBytes[2], // Name byte 3
  144. nameBytes[3], // Name byte 4
  145. */
  146. };
  147. os.write(data);
  148. }
  149. /** {@inheritDoc} */
  150. protected void writeEnd(OutputStream os) throws IOException {
  151. byte[] data = new byte[] {
  152. 0x71, // ID
  153. 0x00, // Length
  154. };
  155. os.write(data);
  156. }
  157. }