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.

PDFCIELabColorSpace.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.pdf;
  19. /**
  20. * This class represents a "CIE L*a*b*" color space. It is expected that the components have
  21. * the following ranges: L* [0..100], a* and b* [-127..127]
  22. */
  23. public class PDFCIELabColorSpace extends PDFArray implements PDFColorSpace {
  24. /**
  25. * Creates a new "CIE L*a*b*" color space. Valid value ranges for the white and black point
  26. * are [0..1] as per the PDF spec.
  27. * @param whitePoint the white point
  28. * @param blackPoint the optional black point (may be null)
  29. */
  30. public PDFCIELabColorSpace(float[] whitePoint, float[] blackPoint) {
  31. super();
  32. add(new PDFName("Lab"));
  33. PDFDictionary dict = new PDFDictionary();
  34. dict.put("WhitePoint", toPDFArray("White point", whitePoint));
  35. if (whitePoint[1] != 1f) {
  36. throw new IllegalArgumentException("The white point's Y coordinate must be 1.0");
  37. }
  38. if (blackPoint != null) {
  39. dict.put("BlackPoint", toPDFArray("Black point", blackPoint));
  40. }
  41. dict.put("Range", new PDFArray(dict, new int[] {-128, 128, -128, 128}));
  42. add(dict);
  43. }
  44. private PDFArray toPDFArray(String name, float[] whitePoint) {
  45. PDFArray wp = new PDFArray();
  46. if (whitePoint == null || whitePoint.length != 3) {
  47. throw new IllegalArgumentException(name + " must be given an have 3 components");
  48. }
  49. for (int i = 0; i < 3; i++) {
  50. wp.add(whitePoint[i]);
  51. }
  52. return wp;
  53. }
  54. /** {@inheritDoc} */
  55. public String getName() {
  56. return "CS" + this.getObjectNumber();
  57. }
  58. /** {@inheritDoc} */
  59. public int getNumComponents() {
  60. return 3;
  61. }
  62. /** {@inheritDoc} */
  63. public boolean isCMYKColorSpace() {
  64. return false;
  65. }
  66. /** {@inheritDoc} */
  67. public boolean isDeviceColorSpace() {
  68. return false;
  69. }
  70. /** {@inheritDoc} */
  71. public boolean isGrayColorSpace() {
  72. return false;
  73. }
  74. /** {@inheritDoc} */
  75. public boolean isRGBColorSpace() {
  76. return false;
  77. }
  78. }