PDFXObjectImage.java
15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
* com.adobe.internal.pdftoolkit.core.types.ASString
*/
package com.adobe.internal.pdftoolkit.pdf.graphics.xobject;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpace;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpaceFactory;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObject;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObjectAltImageList;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObjectImageMask;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObjectUtil;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFMeasure;
import com.adobe.internal.pdftoolkit.pdf.interactive.geospatial.PDFPointData;
import com.adobe.internal.pdftoolkit.pdf.interchange.prepress.PDFOPIVersion;
import com.adobe.internal.pdftoolkit.pdf.transparency.PDFXObjectImageSoftMask;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
public class PDFXObjectImage
extends PDFXObject {
protected static final ASName k_Image = ASName.create((String)"Image");
protected PDFXObjectImage(CosObject cosStream) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosStream);
}
public static PDFXObjectImage getInstance(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (PDFCosObject.checkNullCosObject(cosObject) == null) {
return null;
}
PDFXObjectImage pdfObject = PDFCosObject.getCachedInstance(cosObject, PDFXObjectImage.class);
if (pdfObject == null) {
pdfObject = new PDFXObjectImage(cosObject);
}
return pdfObject;
}
public static PDFXObjectImage newInstance(PDFDocument pdfDocument) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException {
CosStream cosObject = PDFCosObject.newCosStream(pdfDocument);
PDFXObjectImage pdfObject = new PDFXObjectImage((CosObject)cosObject);
pdfObject.setDictionaryNameValue(ASName.k_Type, ASName.k_XObject);
pdfObject.setDictionaryNameValue(ASName.k_Subtype, ASName.k_Image);
pdfObject.setType();
return pdfObject;
}
public static PDFXObjectImage newInstance(PDFDocument pdfDocument, int width, int height, PDFColorSpace colorSpace) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException, PDFInvalidParameterException {
PDFXObjectImage xobj = PDFXObjectImage.newInstance(pdfDocument);
xobj.setWidth(width);
xobj.setHeight(height);
if (colorSpace != null) {
xobj.setColorSpace(colorSpace);
}
xobj.setType();
xobj.setSubtype(k_Image);
return xobj;
}
public ASName getSubType() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Subtype);
}
public void setWidth(int width) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_Width, width);
}
public int getWidth() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryIntValue(ASName.k_Width);
}
public void setHeight(int height) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_Height, height);
}
public int getHeight() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryIntValue(ASName.k_Height);
}
public void setColorSpace(PDFColorSpace colorSpace) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_ColorSpace, colorSpace);
}
public PDFColorSpace getColorSpace() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosObject colorSpaceObj = this.getDictionaryCosObjectValue(ASName.k_ColorSpace);
return PDFColorSpaceFactory.getInstance(colorSpaceObj);
}
public void setBitsPerComponent(int bits) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.k_BitsPerComponent, bits);
}
public int getBitsPerComponent() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
Number value = PDFXObjectUtil.getValidBitsPerComponentValue(this);
if (value == null) {
throw new PDFInvalidDocumentException("Image XObject does not contain BitsPerComponent");
}
return value.intValue();
}
public void setIntent(ASName intent) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryNameValue(ASName.k_Intent, intent);
}
public ASName getIntent() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getDictionaryNameValue(ASName.k_Intent);
}
public void setDecode(double[] decodeArray) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
ArrayList<Double> decodeList = null;
if (decodeArray != null) {
decodeList = new ArrayList<Double>(decodeArray.length);
for (int indx = 0; indx < decodeArray.length; ++indx) {
decodeList.add(indx, new Double(decodeArray[indx]));
}
}
this.setDictionaryArrayValue(ASName.k_Decode, decodeList);
}
public double[] getDecode() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName decodeKey = ASName.k_Decode;
if (!this.dictionaryContains(decodeKey)) {
return null;
}
CosArray decodeList = this.getDictionaryArrayValue(decodeKey);
double[] result = decodeList.getArrayDouble();
return result;
}
public boolean hasDecodeArray() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Decode);
}
public void setIsInterpolate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName interpolateKey = ASName.k_Interpolate;
this.setDictionaryBooleanValue(interpolateKey, true);
}
public boolean getIsInterpolate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName interpolateKey = ASName.k_Interpolate;
boolean result = false;
if (this.dictionaryContains(interpolateKey)) {
result = this.getDictionaryBooleanValue(interpolateKey);
}
return result;
}
public void setIsImageMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryBooleanValue(ASName.k_ImageMask, true);
}
public boolean getIsImageMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
boolean result = false;
if (this.dictionaryContains(ASName.k_ImageMask)) {
result = this.getDictionaryBooleanValue(ASName.k_ImageMask);
}
return result;
}
public void setMask(PDFXObjectImageMask mask) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_Mask, mask);
}
public PDFXObjectImageMask getMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFXObjectImageMask.getInstance(this.getDictionaryCosObjectValue(ASName.k_Mask));
}
public boolean hasMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Mask);
}
public PDFXObjectImage getSMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFXObjectImage.getInstance(this.getDictionaryCosObjectValue(ASName.k_SMask));
}
public void setSMask(PDFXObjectImage image) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_SMask, image);
}
public PDFXObjectImage getMaskImage() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFXObjectImageMask mask = this.getMask();
return mask.getImageMask();
}
public void setMaskImage(PDFXObjectImage image) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFXObjectImageMask mask = PDFXObjectImageMask.getInstance(image.getCosObject());
this.setMask(mask);
}
public void setAlternatesList(PDFXObjectAltImageList alternates) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryArrayValue(ASName.k_Alternates, alternates);
}
public PDFXObjectAltImageList getAlternatesList() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFXObjectAltImageList result = null;
CosArray obj = this.getDictionaryArrayValue(ASName.k_Alternates);
if (obj != null) {
result = PDFXObjectAltImageList.getInstance((CosObject)obj);
}
return result;
}
public void setMaskInData(int code) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryIntValue(ASName.create((String)"SMaskInData"), code);
}
public int getMaskInData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
int result = 0;
ASName key = ASName.create((String)"SMaskInData");
if (this.dictionaryContains(key)) {
result = this.getDictionaryIntValue(key);
}
return result;
}
public void setID(String id) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryASStringValue(ASName.k_ID, new ASString(id));
}
public String getID() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASString asStr = this.getDictionaryStringValue(ASName.k_ID);
return asStr != null ? asStr.asString() : null;
}
public PDFOPIVersion getOPIVersion() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFOPIVersion.getInstance(this.getDictionaryCosObjectValue(ASName.k_OPI));
}
public void setOPIVersion(PDFOPIVersion opiVersion) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.setDictionaryValue(ASName.k_OPI, opiVersion);
}
public InputStream getImageStreamData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosStream().getStreamDecodedNoCopying();
}
public boolean hasImageStreamData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosStream().getStreamDecoded() != null;
}
public boolean getImageStreamData(OutputStream os) throws PDFCosParseException, PDFIOException, PDFSecurityException {
return this.getCosStream().copyStream((Object)os, false);
}
public void setImageStreamData(InputByteStream streamData) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
this.getCosStream().newDataDecoded(streamData);
}
public int getPredictor() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName decodeKey = ASName.create((String)"DecodeParm");
if (!this.dictionaryContains(decodeKey)) {
return 1;
}
CosDictionary decodeList = this.getDictionaryDictionaryValue(decodeKey);
if (decodeList != null) {
int i = -1;
i = decodeList.getInt(ASName.create((String)"Predictor"));
if (i != -1) {
return i;
}
}
return 1;
}
public boolean getBlackIs1() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ASName decodeKey = ASName.create((String)"DecodeParms");
boolean i = false;
if (!this.dictionaryContains(decodeKey)) {
return i;
}
CosDictionary decodeList = this.getDictionaryDictionaryValue(decodeKey);
if (decodeList != null && decodeList.containsKey((Object)ASName.create((String)"BlackIs1"))) {
i = decodeList.getBoolean(ASName.create((String)"BlackIs1"));
}
return i;
}
public PDFXObjectImageSoftMask getSoftMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFXObjectImageSoftMask.getInstance(this.getDictionaryCosObjectValue(ASName.k_SMask));
}
public void setSMask(PDFXObjectImageSoftMask value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.setDictionaryValue(ASName.k_SMask, value);
}
public PDFXObjectImageSoftMask procureSoftMask() throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (!this.hasSoftMask()) {
return PDFXObjectImageSoftMask.newInstance(this.getPDFDocument());
}
return this.getSoftMask();
}
public boolean hasSoftMask() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_SMask);
}
public PDFMeasure getMeasure() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFMeasure.getInstance(this.getDictionaryCosObjectValue(ASName.k_Measure));
}
public void setMeasure(PDFMeasure value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.setDictionaryValue(ASName.k_Measure, value);
}
public boolean hasMeasure() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.dictionaryContains(ASName.k_Measure);
}
public PDFPointData getPointData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFPointData.getInstance(this.getDictionaryCosObjectValue(ASName.k_PtData));
}
public void setPointData(PDFPointData pdfPointData) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
this.setDictionaryValue(ASName.k_PtData, pdfPointData);
}
}