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.

OCAColorSpace.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.util;
  19. import java.awt.color.ColorSpace;
  20. import org.apache.fop.util.OCAColor.OCAColorValue;
  21. /**
  22. * The OCA color space is a subset of RGB that includes a limited set of colors.
  23. * The color value is specified with one unsigned binary component that
  24. * specifies a named color using a two-byte value from the Standard
  25. * OCA Color Value table.
  26. *
  27. */
  28. public class OCAColorSpace extends ColorSpace {
  29. private static final long serialVersionUID = 1L;
  30. protected OCAColorSpace() {
  31. super(ColorSpace.TYPE_RGB, 1);
  32. }
  33. public float[] fromCIEXYZ(float[] colorvalue) {
  34. throw new UnsupportedOperationException("Color conversion from CIE XYZ to OCA is not possible");
  35. }
  36. public float[] fromRGB(float[] rgbvalue) {
  37. throw new UnsupportedOperationException("Color conversion from RGB to OCA is not possible");
  38. }
  39. public float[] toCIEXYZ(float[] colorvalue) {
  40. float[] rgb = toRGB(colorvalue);
  41. ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
  42. return sRGB.toCIEXYZ(rgb);
  43. }
  44. public float[] toRGB(float[] colorvalue) {
  45. int oca = (int) colorvalue[0];
  46. if (oca == OCAColorValue.BLACK.value) {
  47. return new float[]{0, 0, 0};
  48. } else if (oca == OCAColorValue.BLUE.value) {
  49. return new float[]{0, 0, 1.0f};
  50. } else if (oca == OCAColorValue.BROWN.value) {
  51. return new float[]{0.565f, 0.188f, 0};
  52. } else if (oca == OCAColorValue.CYAN.value) {
  53. return new float[]{0, 1.0f, 1.0f};
  54. } else if (oca == OCAColorValue.GREEN.value) {
  55. return new float[]{0, 1.0f, 0};
  56. } else if (oca == OCAColorValue.MAGENTA.value) {
  57. return new float[]{1.0f, 0, 1.0f};
  58. } else if (oca == OCAColorValue.RED.value) {
  59. return new float[]{1.0f, 0, 0};
  60. } else if (oca == OCAColorValue.YELLOW.value) {
  61. return new float[]{1.0f, 1.0f, 0};
  62. }
  63. return null;
  64. }
  65. }