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.

JPEG.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.blip;
  16. import org.apache.poi.ddf.EscherBSERecord;
  17. import org.apache.poi.ddf.EscherContainerRecord;
  18. import org.apache.poi.hslf.usermodel.HSLFSlideShow;
  19. import org.apache.poi.util.Internal;
  20. import org.apache.poi.util.Removal;
  21. /**
  22. * Represents a JPEG picture data in a PPT file
  23. */
  24. public final class JPEG extends Bitmap {
  25. public enum ColorSpace { rgb, cymk }
  26. private ColorSpace colorSpace = ColorSpace.rgb;
  27. /**
  28. * @deprecated Use {@link HSLFSlideShow#addPicture(byte[], PictureType)} or one of it's overloads to create new
  29. * {@link JPEG}. This API led to detached {@link JPEG} instances (See Bugzilla
  30. * 46122) and prevented adding additional functionality.
  31. */
  32. @Deprecated
  33. @Removal(version = "5.3")
  34. public JPEG() {
  35. this(new EscherContainerRecord(), new EscherBSERecord());
  36. }
  37. /**
  38. * Creates a new instance.
  39. *
  40. * @param recordContainer Record tracking all pictures. Should be attached to the slideshow that this picture is
  41. * linked to.
  42. * @param bse Record referencing this picture. Should be attached to the slideshow that this picture is linked to.
  43. */
  44. @Internal
  45. public JPEG(EscherContainerRecord recordContainer, EscherBSERecord bse) {
  46. super(recordContainer, bse);
  47. }
  48. @Override
  49. public PictureType getType(){
  50. return PictureType.JPEG;
  51. }
  52. public ColorSpace getColorSpace() {
  53. return colorSpace;
  54. }
  55. public void setColorSpace(ColorSpace colorSpace) {
  56. this.colorSpace = colorSpace;
  57. }
  58. /**
  59. * JPEG signature is one of {@code 0x46A0, 0x46B0, 0x6E20, 0x6E30}
  60. *
  61. * @return JPEG signature ({@code 0x46A0, 0x46B0, 0x6E20, 0x6E30})
  62. */
  63. public int getSignature(){
  64. return (colorSpace == ColorSpace.rgb)
  65. ? (getUIDInstanceCount() == 1 ? 0x46A0 : 0x46B0)
  66. : (getUIDInstanceCount() == 1 ? 0x6E20 : 0x6E30);
  67. }
  68. /**
  69. * Sets the PICT signature - either {@code 0x5420} or {@code 0x5430}
  70. */
  71. public void setSignature(int signature) {
  72. switch (signature) {
  73. case 0x46A0:
  74. setUIDInstanceCount(1);
  75. colorSpace = ColorSpace.rgb;
  76. break;
  77. case 0x46B0:
  78. setUIDInstanceCount(2);
  79. colorSpace = ColorSpace.rgb;
  80. break;
  81. case 0x6E20:
  82. setUIDInstanceCount(1);
  83. colorSpace = ColorSpace.cymk;
  84. break;
  85. case 0x6E30:
  86. setUIDInstanceCount(2);
  87. colorSpace = ColorSpace.cymk;
  88. break;
  89. default:
  90. throw new IllegalArgumentException(signature+" is not a valid instance/signature value for JPEG");
  91. }
  92. }
  93. }