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.

ImageInputDescriptor.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.modca.AbstractAFPObject;
  22. import org.apache.fop.afp.util.BinaryUtils;
  23. /**
  24. * The IM Image Input Descriptor structured field contains the
  25. * descriptor data for an IM image data object. This data specifies
  26. * the resolution, size, and color of the IM image.
  27. */
  28. public class ImageInputDescriptor extends AbstractAFPObject {
  29. /** the resolution of the raster image (default 240) */
  30. private int resolution = 240;
  31. /** {@inheritDoc} */
  32. public void writeToStream(OutputStream os) throws IOException {
  33. byte[] data = new byte[45];
  34. copySF(data, Type.DESCRIPTOR, Category.IM_IMAGE);
  35. data[1] = 0x00; // length
  36. data[2] = 0x2C;
  37. // Constant data.
  38. data[9] = 0x00;
  39. data[10] = 0x00;
  40. data[11] = 0x09;
  41. data[12] = 0x60;
  42. data[13] = 0x09;
  43. data[14] = 0x60;
  44. data[15] = 0x00;
  45. data[16] = 0x00;
  46. data[17] = 0x00;
  47. data[18] = 0x00;
  48. data[19] = 0x00;
  49. data[20] = 0x00;
  50. // X Base (Fixed x00)
  51. data[21] = 0x00;
  52. // Y Base (Fixed x00)
  53. data[22] = 0x00;
  54. byte[] imagepoints = BinaryUtils.convert(resolution * 10, 2);
  55. /**
  56. * Specifies the number of image points per unit base for the X axis
  57. * of the image. This value is ten times the resolution of the image
  58. * in the X direction.
  59. */
  60. data[23] = imagepoints[0];
  61. data[24] = imagepoints[1];
  62. /**
  63. * Specifies the number of image points per unit base for the Y axis
  64. * of the image. This value is ten times the resolution of the image
  65. * in the Y direction.
  66. */
  67. data[25] = imagepoints[0];
  68. data[26] = imagepoints[1];
  69. /**
  70. * Specifies the extent in the X direction, in image points, of an
  71. * non-celled (simple) image.
  72. */
  73. data[27] = 0x00;
  74. data[28] = 0x01;
  75. /**
  76. * Specifies the extent in the Y direction, in image points, of an
  77. * non-celled (simple) image.
  78. */
  79. data[29] = 0x00;
  80. data[30] = 0x01;
  81. // Constant Data
  82. data[31] = 0x00;
  83. data[32] = 0x00;
  84. data[33] = 0x00;
  85. data[34] = 0x00;
  86. data[35] = 0x2D;
  87. data[36] = 0x00;
  88. // Default size of image cell in X direction
  89. data[37] = 0x00;
  90. data[38] = 0x01;
  91. // Default size of image cell in Y direction
  92. data[39] = 0x00;
  93. data[40] = 0x01;
  94. // Constant Data
  95. data[41] = 0x00;
  96. data[42] = 0x01;
  97. // Image Color
  98. data[43] = (byte)0xFF;
  99. data[44] = (byte)0xFF;
  100. os.write(data);
  101. }
  102. /**
  103. * Sets the resolution information for the raster image
  104. * the default value is a resolution of 240 dpi.
  105. *
  106. * @param resolution The resolution value
  107. */
  108. public void setResolution(int resolution) {
  109. this.resolution = resolution;
  110. }
  111. }