1 19 20 package jxl.biff.drawing; 21 22 import java.io.FileInputStream ; 23 import java.io.IOException ; 24 import common.Assert; 25 import jxl.biff.IntegerHelper; 26 27 30 class BlipStoreEntry extends EscherAtom 31 { 32 35 private BlipType type; 36 37 38 41 private byte[] data; 42 43 46 private int imageDataLength; 47 48 51 private int referenceCount; 52 53 57 private boolean write; 58 59 62 private final static int IMAGE_DATA_OFFSET = 61; 63 64 69 public BlipStoreEntry(EscherRecordData erd) 70 { 71 super(erd); 72 type = BlipType.getType(getInstance()); 73 write = false; 74 byte[] bytes = getBytes(); 75 referenceCount = IntegerHelper.getInt(bytes[24], bytes[25], 76 bytes[26], bytes[27]); 77 } 78 79 85 public BlipStoreEntry(Drawing d) 86 throws IOException 87 { 88 super(EscherRecordType.BSE); 89 type = BlipType.PNG; 90 setVersion(2); 91 setInstance(type.getValue()); 92 93 byte[] imageData = d.getImageBytes(); 94 imageDataLength = imageData.length; 95 data = new byte[imageDataLength + IMAGE_DATA_OFFSET]; 96 System.arraycopy(imageData, 0, data, IMAGE_DATA_OFFSET, imageDataLength); 97 referenceCount = d.getReferenceCount(); 98 write = true; 99 } 100 101 106 public BlipType getBlipType() 107 { 108 return type; 109 } 110 111 116 public byte[] getData() 117 { 118 if (write) 119 { 120 122 data[0] = (byte) type.getValue(); 124 125 data[1] = (byte) type.getValue(); 127 128 131 134 IntegerHelper.getFourBytes(imageDataLength + 8 + 17, data, 20); 136 137 IntegerHelper.getFourBytes(referenceCount, data, 24); 139 140 IntegerHelper.getFourBytes(0, data, 28); 142 143 data[32] = (byte) 0; 145 146 data[33] = (byte) 0; 148 149 data[34] = (byte) 0x7e; 151 data[35] = (byte) 0x01; 152 153 data[36] = (byte) 0; 155 data[37] = (byte) 0x6e; 156 157 IntegerHelper.getTwoBytes(0xf01e, data, 38); 159 160 IntegerHelper.getFourBytes(imageDataLength + 17, data, 40); 163 164 } 167 else 168 { 169 data = getBytes(); 171 } 172 173 return setHeaderData(data); 174 } 175 176 180 void dereference() 181 { 182 referenceCount--; 183 Assert.verify(referenceCount >= 0); 184 } 185 186 191 int getReferenceCount() 192 { 193 return referenceCount; 194 } 195 196 201 byte[] getImageData() 202 { 203 byte[] allData = getBytes(); 204 byte[] imageData = new byte[allData.length - IMAGE_DATA_OFFSET]; 205 System.arraycopy(allData, IMAGE_DATA_OFFSET, 206 imageData, 0, imageData.length); 207 return imageData; 208 } 209 } 210 | Popular Tags |