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.

PNG.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.hslf.model.Picture;
  17. import org.apache.poi.util.PngUtils;
  18. /**
  19. * Represents a PNG picture data in a PPT file
  20. *
  21. * @author Yegor Kozlov
  22. */
  23. public final class PNG extends Bitmap {
  24. /**
  25. * @return PNG data
  26. */
  27. public byte[] getData() {
  28. byte[] data = super.getData();
  29. //PNG created on MAC may have a 16-byte prefix which prevents successful reading.
  30. //Just cut it off!.
  31. if (PngUtils.matchesPngHeader(data, 16)) {
  32. byte[] png = new byte[data.length-16];
  33. System.arraycopy(data, 16, png, 0, png.length);
  34. data = png;
  35. }
  36. return data;
  37. }
  38. /**
  39. * @return type of this picture
  40. * @see org.apache.poi.hslf.model.Picture#PNG
  41. */
  42. public int getType(){
  43. return Picture.PNG;
  44. }
  45. /**
  46. * PNG signature is {@code 0x6E00} or {@code 0x6E10}
  47. *
  48. * @return PNG signature ({@code 0x6E00} or {@code 0x6E10})
  49. */
  50. public int getSignature(){
  51. return (uidInstanceCount == 1 ? 0x6E00 : 0x6E10);
  52. }
  53. /**
  54. * Sets the PNG signature - either {@code 0x6E00} or {@code 0x6E10}
  55. */
  56. public void setSignature(int signature) {
  57. switch (signature) {
  58. case 0x6E00:
  59. uidInstanceCount = 1;
  60. break;
  61. case 0x6E10:
  62. uidInstanceCount = 2;
  63. break;
  64. default:
  65. throw new IllegalArgumentException(signature+" is not a valid instance/signature value for PNG");
  66. }
  67. }
  68. }