InlineImage.java 32.4 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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.io.stream.IO
 *  com.adobe.internal.io.stream.InputByteStream
 *  com.adobe.internal.io.stream.StreamManager
 *  com.adobe.internal.pdftoolkit.core.cos.CosDocument
 *  com.adobe.internal.pdftoolkit.core.cos.CosObject
 *  com.adobe.internal.pdftoolkit.core.cos.CosOpenOptions
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidContentException
 *  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.exceptions.PDFUnableToCompleteOperationException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFUnsupportedFeatureException
 *  com.adobe.internal.pdftoolkit.core.filter.ASCII85InputStream
 *  com.adobe.internal.pdftoolkit.core.filter.ASCII85OutputStream
 *  com.adobe.internal.pdftoolkit.core.filter.ASCIIHexInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.ASCIIHexOutputStream
 *  com.adobe.internal.pdftoolkit.core.filter.CCITTFaxInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.CustomFilterRegistry
 *  com.adobe.internal.pdftoolkit.core.filter.DCTInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.FilterParams
 *  com.adobe.internal.pdftoolkit.core.filter.FilterStream
 *  com.adobe.internal.pdftoolkit.core.filter.LZWInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.LZWOutputStream
 *  com.adobe.internal.pdftoolkit.core.filter.RunLengthInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.RunLengthOutputStream
 *  com.adobe.internal.pdftoolkit.core.filter.TIFFInputStream
 *  com.adobe.internal.pdftoolkit.core.filter.TIFFOutputStream
 *  com.adobe.internal.pdftoolkit.core.filter.spi.CustomFilterException
 *  com.adobe.internal.pdftoolkit.core.types.ASArray
 *  com.adobe.internal.pdftoolkit.core.types.ASBoolean
 *  com.adobe.internal.pdftoolkit.core.types.ASDictionary
 *  com.adobe.internal.pdftoolkit.core.types.ASName
 *  com.adobe.internal.pdftoolkit.core.types.ASNull
 *  com.adobe.internal.pdftoolkit.core.types.ASNumber
 *  com.adobe.internal.pdftoolkit.core.types.ASObject
 *  com.adobe.internal.pdftoolkit.core.types.ASString
 */
package com.adobe.internal.pdftoolkit.pdf.inlineimage;

import com.adobe.internal.io.stream.IO;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.StreamManager;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosOpenOptions;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidContentException;
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.exceptions.PDFUnableToCompleteOperationException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFUnsupportedFeatureException;
import com.adobe.internal.pdftoolkit.core.filter.ASCII85InputStream;
import com.adobe.internal.pdftoolkit.core.filter.ASCII85OutputStream;
import com.adobe.internal.pdftoolkit.core.filter.ASCIIHexInputStream;
import com.adobe.internal.pdftoolkit.core.filter.ASCIIHexOutputStream;
import com.adobe.internal.pdftoolkit.core.filter.CCITTFaxInputStream;
import com.adobe.internal.pdftoolkit.core.filter.CustomFilterRegistry;
import com.adobe.internal.pdftoolkit.core.filter.DCTInputStream;
import com.adobe.internal.pdftoolkit.core.filter.FilterParams;
import com.adobe.internal.pdftoolkit.core.filter.FilterStream;
import com.adobe.internal.pdftoolkit.core.filter.LZWInputStream;
import com.adobe.internal.pdftoolkit.core.filter.LZWOutputStream;
import com.adobe.internal.pdftoolkit.core.filter.RunLengthInputStream;
import com.adobe.internal.pdftoolkit.core.filter.RunLengthOutputStream;
import com.adobe.internal.pdftoolkit.core.filter.TIFFInputStream;
import com.adobe.internal.pdftoolkit.core.filter.TIFFOutputStream;
import com.adobe.internal.pdftoolkit.core.filter.spi.CustomFilterException;
import com.adobe.internal.pdftoolkit.core.types.ASArray;
import com.adobe.internal.pdftoolkit.core.types.ASBoolean;
import com.adobe.internal.pdftoolkit.core.types.ASDictionary;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASNull;
import com.adobe.internal.pdftoolkit.core.types.ASNumber;
import com.adobe.internal.pdftoolkit.core.types.ASObject;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.pdf.content.Content;
import com.adobe.internal.pdftoolkit.pdf.contentmodify.ModifiableContent;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFResources;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpace;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpaceDeviceCMYK;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpaceDeviceGray;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpaceDeviceRGB;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFColorSpaceIndexed;
import com.adobe.internal.pdftoolkit.pdf.graphics.colorspaces.PDFRenderingIntent;
import com.adobe.internal.pdftoolkit.pdf.inlineimage.InlineImageColorSpace;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

public class InlineImage {
    Content content;
    private int height;
    private int width;
    private Integer bpc;
    private InlineImageColorSpace colorSpace;
    private PDFRenderingIntent intent;
    private boolean imageMask = false;
    private boolean interpolate = false;
    private double[] decode;
    private InputStream unencodedImageData;
    private InputByteStream encodedImageData;
    private ASObject decodeParams;
    private ASObject filters;

    private InlineImage(Content content, ASDictionary imageDict, InputByteStream encodedImageData) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.content = content;
        try {
            this.height = imageDict.getNumber(imageDict.containsKey((Object)ASName.k_H) ? ASName.k_H : ASName.k_Height).intValue();
            this.width = imageDict.getNumber(imageDict.containsKey((Object)ASName.k_W) ? ASName.k_W : ASName.k_Width).intValue();
            if (imageDict.containsKey((Object)ASName.k_BPC)) {
                this.bpc = imageDict.getNumber(ASName.k_BPC).intValue();
            } else if (imageDict.containsKey((Object)ASName.k_BitsPerComponent)) {
                this.bpc = imageDict.getNumber(ASName.k_BitsPerComponent).intValue();
            }
            if (imageDict.containsKey((Object)ASName.k_Intent)) {
                this.intent = PDFRenderingIntent.getIntentForValue(imageDict.getName(ASName.k_Intent));
            }
            if (imageDict.containsKey((Object)ASName.k_IM)) {
                this.imageMask = imageDict.getBoolean(ASName.k_IM).isTrue();
            } else if (imageDict.containsKey((Object)ASName.k_ImageMask)) {
                this.imageMask = imageDict.getBoolean(ASName.k_ImageMask).isTrue();
            }
            if (imageDict.containsKey((Object)ASName.k_I)) {
                this.interpolate = imageDict.getBoolean(ASName.k_I).isTrue();
            } else if (imageDict.containsKey((Object)ASName.k_Interpolate)) {
                this.interpolate = imageDict.getBoolean(ASName.k_Interpolate).isTrue();
            }
        }
        catch (PDFUnableToCompleteOperationException e) {
            throw new PDFInvalidContentException("Invalid Image Dict", (Throwable)e);
        }
        if (imageDict.containsKey((Object)ASName.k_CS)) {
            this.colorSpace = InlineImageColorSpace.createFromNameOrArray((Object)imageDict.get((Object)ASName.k_CS));
        } else if (imageDict.containsKey((Object)ASName.k_ColorSpace)) {
            this.colorSpace = InlineImageColorSpace.createFromNameOrArray((Object)imageDict.get((Object)ASName.k_ColorSpace));
        }
        if (imageDict.containsKey((Object)ASName.k_F)) {
            this.filters = imageDict.get((Object)ASName.k_F);
        } else if (imageDict.containsKey((Object)ASName.k_Filter)) {
            this.filters = imageDict.get((Object)ASName.k_Filter);
        }
        if (imageDict.containsKey((Object)ASName.k_DP)) {
            this.decodeParams = imageDict.get((Object)ASName.k_DP);
        } else if (imageDict.containsKey((Object)ASName.k_DecodeParms)) {
            this.decodeParams = imageDict.get((Object)ASName.k_DecodeParms);
        }
        this.unencodedImageData = null;
        this.encodedImageData = encodedImageData;
    }

    private PDFColorSpace getPDFColorSpace(Content content) throws PDFIOException, PDFInvalidParameterException {
        try {
            InlineImageColorSpace cs = this.getColorSpace();
            if (cs == null) {
                return null;
            }
            if (cs.isDeviceColorSpace()) {
                ASName deviceCS = cs.getDeviceColorSpaceName();
                return this.getDeviceColorSpace(content.getPDFDocument(), deviceCS);
            }
            if (cs.isIndexedColorSpace()) {
                ASArray csArray = cs.getIndexedColorSpace();
                if ((csArray.get(0) == ASName.k_Indexed || csArray.get(0) == ASName.k_I) && csArray.size() == 4) {
                    PDFColorSpaceIndexed csIndexed = PDFColorSpaceIndexed.newInstance(content.getPDFDocument());
                    csIndexed.setBaseColorSpace(this.getDeviceColorSpace(content.getPDFDocument(), csArray.getName(1)));
                    csIndexed.setHighValue(csArray.getNumber(2).intValue());
                    csIndexed.setLookupData(csArray.getString(3).getBytes());
                    return csIndexed;
                }
            } else {
                if (cs.isNewResourceColorSpace()) {
                    return cs.getNewResourceColorSpace();
                }
                PDFResources resources = content.getResources();
                if (resources != null) {
                    ASName name = cs.getExistingResourceColorSpaceName();
                    return resources.getColorSpace(name);
                }
            }
        }
        catch (PDFUnableToCompleteOperationException e) {
            throw new PDFInvalidParameterException((Throwable)e);
        }
        catch (PDFCosParseException e) {
            throw new PDFInvalidParameterException((Throwable)e);
        }
        catch (PDFSecurityException e) {
            throw new PDFInvalidParameterException((Throwable)e);
        }
        catch (PDFInvalidDocumentException e) {
            throw new PDFInvalidParameterException((Throwable)e);
        }
        return null;
    }

    private PDFColorSpace getDeviceColorSpace(PDFDocument pdfDoc, ASName deviceCS) throws PDFInvalidDocumentException {
        if (deviceCS == ASName.k_DeviceRGB || deviceCS == ASName.k_RGB) {
            return PDFColorSpaceDeviceRGB.newInstance(this.content.getPDFDocument());
        }
        if (deviceCS == ASName.k_DeviceGray || deviceCS == ASName.k_G) {
            return PDFColorSpaceDeviceGray.newInstance(this.content.getPDFDocument());
        }
        if (deviceCS == ASName.k_DeviceCMYK || deviceCS == ASName.k_CMYK) {
            return PDFColorSpaceDeviceCMYK.newInstance(this.content.getPDFDocument());
        }
        return null;
    }

    private InlineImage(InputByteStream unencodedImageData, int height, int width, Integer bpc, PDFColorSpace colorSpace, PDFRenderingIntent intent, boolean imageMask, boolean interpolate, double[] imageDecodeArray, ASArray filters, ASArray filtersDecodeParams) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
        this.height = height;
        this.width = width;
        this.bpc = bpc;
        this.colorSpace = new InlineImageColorSpace(colorSpace);
        this.intent = intent;
        this.imageMask = imageMask;
        this.interpolate = interpolate;
        this.decode = imageDecodeArray;
        this.filters = filters;
        this.decodeParams = filtersDecodeParams;
        try {
            this.unencodedImageData = unencodedImageData.toInputStream();
        }
        catch (IOException e) {
            throw new PDFIOException("Could not get the input stream for the unencoded image data", (Throwable)e);
        }
        this.encodedImageData = null;
    }

    public static InlineImage newInstance(Content content, ASDictionary imageDict, InputByteStream encodedImageData) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return new InlineImage(content, imageDict, encodedImageData);
    }

    public static InlineImage newInstance(ASArray filters, ASArray filtersDecodeParams, InputByteStream unencodedImageData, int height, int width, Integer bpc, PDFColorSpace colorSpace, PDFRenderingIntent intent, boolean imageMask, boolean interpolate, double[] imageDecodeArray) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
        return new InlineImage(unencodedImageData, height, width, bpc, colorSpace, intent, imageMask, interpolate, imageDecodeArray, filters, filtersDecodeParams);
    }

    public Content getContent() {
        return this.content;
    }

    public int getHeight() {
        return this.height;
    }

    public int getWidth() {
        return this.width;
    }

    public Integer getBitsPerComponent() {
        return this.bpc;
    }

    public InlineImageColorSpace getColorSpace() {
        return this.colorSpace;
    }

    public PDFRenderingIntent getIntent() {
        return this.intent;
    }

    public boolean isImageMask() {
        return this.imageMask;
    }

    public void setInterpolation(boolean interpolate) {
        this.interpolate = interpolate;
    }

    public boolean useInterpolation() {
        return this.interpolate;
    }

    public double[] getImageDecodeArray() {
        return this.decode;
    }

    public Object getStreamFiltersDecodeParams() {
        return this.decodeParams;
    }

    public Object getStreamFilters() {
        return this.filters;
    }

    public void setStreamFilters(ASName[] filterNames, ASDictionary[] decodeParamsArray) throws PDFIOException, PDFInvalidContentException {
        if (filterNames != null && filterNames.length > 0 && filterNames[0] != null) {
            if (filterNames.length == 1) {
                if (decodeParamsArray != null && decodeParamsArray.length > 0 && decodeParamsArray[0] != null) {
                    this.setStreamFilters(filterNames[0], decodeParamsArray[0]);
                } else {
                    this.setStreamFilters(filterNames[0], null);
                }
            } else {
                boolean decodeParamsHasNonNullValue = false;
                ASArray filters = new ASArray();
                ASArray decodeParams = new ASArray();
                for (int i = 0; i < filterNames.length; ++i) {
                    if (filterNames[i] == null) continue;
                    filters.add((ASObject)filterNames[i]);
                    if (decodeParamsArray != null && i < decodeParamsArray.length && decodeParamsArray[i] != null) {
                        decodeParams.add((ASObject)decodeParamsArray[i]);
                        decodeParamsHasNonNullValue = true;
                        continue;
                    }
                    decodeParams.add(null);
                }
                if (!decodeParamsHasNonNullValue) {
                    decodeParams = null;
                }
                this.setStreamFilters(filters, decodeParams);
            }
        } else {
            this.setStreamFilters((ASName)null, (ASDictionary)null);
        }
    }

    public void setStreamFilters(ASName filter, ASDictionary decodeParams) throws PDFIOException, PDFInvalidContentException {
        if (this.unencodedImageData == null) {
            this.unencodedImageData = this.getDecodedImageData();
        }
        this.encodedImageData = null;
        this.filters = filter;
        this.decodeParams = decodeParams;
    }

    public void setStreamFilters(ASArray filters, ASArray decodeParams) throws PDFIOException, PDFInvalidContentException {
        if (this.unencodedImageData == null) {
            this.unencodedImageData = this.getDecodedImageData();
        }
        this.encodedImageData = null;
        this.filters = filters;
        this.decodeParams = decodeParams;
    }

    public InputStream getImageData() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (this.unencodedImageData == null) {
            this.unencodedImageData = this.getDecodedImageData();
        }
        return this.unencodedImageData;
    }

    public InputByteStream getEncodedImageData(Content content) throws PDFIOException, PDFInvalidContentException {
        if (this.encodedImageData == null) {
            try {
                this.encodedImageData = this.createEncodedImageData(content);
            }
            catch (PDFInvalidParameterException e) {
                throw new PDFInvalidContentException((Throwable)e);
            }
        }
        return this.encodedImageData;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private InputByteStream createEncodedImageData(Content content) throws PDFIOException, PDFInvalidParameterException {
        ASName[] filterNames;
        block30 : {
            PaddedByteArrayOutputStream baos;
            if (content == null) {
                return null;
            }
            this.content = content;
            StreamManager stmMgr = content.getPDFDocument().getStreamManager();
            int maxSize = this.height * this.width * this.bpc / 8;
            OutputStream os = baos = new PaddedByteArrayOutputStream(maxSize);
            try {
                boolean emitLZWExtraPadding = false;
                if (this.filters != null) {
                    filterNames = null;
                    Object[] decodeParamDicts = null;
                    if (this.filters instanceof ASName) {
                        filterNames = new ASName[]{(ASName)this.filters};
                        if (this.decodeParams != null) {
                            decodeParamDicts = new ASObject[]{this.decodeParams};
                        }
                    } else if (this.filters instanceof ASArray) {
                        filterNames = new ASName[((ASArray)this.filters).size()];
                        filterNames = (ASName[])((ASArray)this.filters).toArray((Object[])filterNames);
                        if (this.decodeParams != null) {
                            decodeParamDicts = new ASObject[((ASArray)this.decodeParams).size()];
                            decodeParamDicts = (ASObject[])((ASArray)this.decodeParams).toArray(decodeParamDicts);
                        }
                    }
                    if (filterNames != null && filterNames.length != 0) {
                        PDFColorSpace colorspace = this.getPDFColorSpace(content);
                        for (int i = 0; i < filterNames.length; ++i) {
                            ASName filter = filterNames[i];
                            Object paramsDict = null;
                            if (decodeParamDicts != null && decodeParamDicts.length > 0 && i < decodeParamDicts.length) {
                                paramsDict = decodeParamDicts[i];
                            }
                            FilterParams filterParams = null;
                            if (paramsDict != null && !(paramsDict instanceof ASNull)) {
                                filterParams = FilterStream.buildFilterParams((ASObject)paramsDict);
                                filterParams.put((Object)"ColorSpace", (Object)(colorspace != null ? colorspace.getCosObject() : null));
                            }
                            if (filterParams == null) {
                                filterParams = new FilterParams();
                            }
                            if (filter == ASName.k_ASCIIHexDecode || filter == ASName.k_AHx) {
                                os = new ASCIIHexOutputStream(os, filterParams);
                                continue;
                            }
                            if (filter == ASName.k_ASCII85Decode || filter == ASName.k_A85) {
                                os = new ASCII85OutputStream(os, filterParams);
                                continue;
                            }
                            if (filter == ASName.k_LZWDecode || filter == ASName.k_LZW) {
                                os = new LZWOutputStream(os, filterParams);
                                if (filterNames[0] != ASName.k_LZWDecode && filterNames[0] != ASName.k_LZW) continue;
                                emitLZWExtraPadding = true;
                                continue;
                            }
                            if (filter == ASName.k_FlateDecode || filter == ASName.k_Fl) {
                                os = new DeflaterOutputStream(os, new Deflater(9));
                                if (filterParams == null || !filterParams.containsKey((Object)"Predictor") || (Integer)filterParams.get((Object)"Predictor") == 1) continue;
                                os = new TIFFOutputStream(os, filterParams);
                                continue;
                            }
                            if (filter == ASName.k_RunLengthDecode || filter == ASName.k_RL) {
                                os = new RunLengthOutputStream(os);
                                continue;
                            }
                            if (filter == ASName.k_CCITTFaxDecode || filter == ASName.k_CCF) {
                                throw new PDFUnsupportedFeatureException("CCITTFax encoding is not currently supported");
                            }
                            if (filter == ASName.k_DCTDecode || filter == ASName.k_DCT) {
                                if (!InlineImage.DCTFilterSupported(content.getPDFDocument()) || filterNames.length != 1) {
                                    throw new PDFUnsupportedFeatureException("DCT encoding is not currently supported");
                                }
                                CustomFilterRegistry filterReg = content.getPDFDocument().getCosDocument().getOptions().getCustomFilterRegistry();
                                if (!filterReg.isEncodeFilterRegistered(ASName.k_DCTDecode)) continue;
                                try {
                                    if (!this.unencodedImageData.markSupported()) {
                                        throw new CustomFilterException("Unable to encode using DCT filter");
                                    }
                                    os = filterReg.encode(ASName.k_DCTDecode, os, filterParams);
                                    this.unencodedImageData.reset();
                                    this.decodeParams = FilterStream.updateCustomFilterParams((ASName)filter, (ASDictionary)filterParams.toASDictionary(), (CustomFilterRegistry)filterReg);
                                    continue;
                                }
                                catch (CustomFilterException e) {
                                    throw new PDFIOException("Unable to use filter registry to encode stream that uses " + (Object)filter, (Throwable)e);
                                }
                            }
                            if (filter == null) continue;
                            throw new PDFUnsupportedFeatureException("Unrecognized filter \"" + (Object)filter + "\" not supported");
                        }
                    }
                }
                IO.copy((InputStream)this.unencodedImageData, (OutputStream)os);
                os.flush();
                if (emitLZWExtraPadding) {
                    baos.setPaddingByte(32);
                    baos.setPaddingSize(2);
                }
                os.close();
                os = null;
                filterNames = stmMgr.getInputByteStream(baos.toByteArray());
                if (os == null) break block30;
            }
            catch (Throwable var16_17) {
                try {
                    if (os != null) {
                        os.close();
                    }
                    throw var16_17;
                }
                catch (IOException e) {
                    throw new PDFIOException("A problem was encountered trying to encode inline image data.", (Throwable)e);
                }
            }
            os.close();
        }
        return filterNames;
    }

    public ASDictionary createImageDict(ModifiableContent content) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
        ASDictionary dict = new ASDictionary();
        dict.put(ASName.k_H, (ASObject)new ASNumber(this.height));
        dict.put(ASName.k_W, (ASObject)new ASNumber(this.width));
        if (this.bpc != null) {
            dict.put(ASName.k_BPC, (ASObject)new ASNumber((Number)this.bpc));
        } else if (!this.imageMask) {
            throw new PDFInvalidParameterException("BitsPerComponent must be specified for inline images that are not image masks");
        }
        if (this.imageMask) {
            dict.put(ASName.k_IM, (ASObject)new ASBoolean(this.imageMask));
            if (this.bpc != 1) {
                throw new PDFInvalidParameterException("BitsPerComponent must be set to 1 for image masks");
            }
            if (this.colorSpace != null) {
                throw new PDFInvalidParameterException("A color space should not be specified for image masks");
            }
        }
        if (this.colorSpace != null && this.colorSpace.isNewResourceColorSpace()) {
            PDFColorSpace newCS = this.colorSpace.getNewResourceColorSpace();
            if (newCS instanceof PDFColorSpaceDeviceRGB || newCS instanceof PDFColorSpaceDeviceCMYK || newCS instanceof PDFColorSpaceDeviceGray) {
                dict.put(ASName.k_CS, (ASObject)newCS.getName());
            } else {
                dict.put(ASName.k_CS, (ASObject)content.addResource(newCS));
            }
        } else if (this.colorSpace != null && this.colorSpace.isDeviceColorSpace()) {
            dict.put(ASName.k_CS, (ASObject)this.colorSpace.getDeviceColorSpaceName());
        } else if (this.colorSpace != null && this.colorSpace.isExistingResourceColorSpaceName()) {
            dict.put(ASName.k_CS, (ASObject)this.colorSpace.getExistingResourceColorSpaceName());
        } else if (this.colorSpace != null && this.colorSpace.isIndexedColorSpace()) {
            dict.put(ASName.k_CS, (ASObject)this.colorSpace.getIndexedColorSpace());
        } else if (!this.imageMask) {
            throw new PDFInvalidParameterException("A color space must be specified for inline images that are not image masks");
        }
        if (this.intent != null) {
            dict.put(ASName.k_Intent, (ASObject)this.intent.getValue());
        }
        if (this.interpolate) {
            dict.put(ASName.k_I, (ASObject)new ASBoolean(this.interpolate));
        }
        if (this.filters != null) {
            dict.put(ASName.k_F, this.filters);
        }
        if (this.decodeParams != null) {
            dict.put(ASName.k_DP, this.decodeParams);
        }
        return dict;
    }

    private InputStream getDecodedImageData() throws PDFIOException, PDFInvalidContentException {
        ASArray filterNames = new ASArray();
        if (this.filters instanceof ASName) {
            filterNames.add(this.filters);
        } else if (this.filters instanceof ASArray) {
            filterNames = (ASArray)this.filters;
        }
        FilterParams filterParams = null;
        try {
            filterParams = FilterStream.buildFilterParams((ASObject)this.decodeParams);
        }
        catch (PDFInvalidParameterException e1) {
            throw new PDFInvalidContentException("Invalid Decode Params Dict", (Throwable)e1);
        }
        if (filterParams == null) {
            filterParams = new FilterParams();
        }
        InputStream is = null;
        try {
            is = this.encodedImageData.toInputStream();
        }
        catch (IOException e) {
            throw new PDFIOException("Cannot get the input stream for an inline image's encoded image data", (Throwable)e);
        }
        if (filterNames != null && filterNames.size() != 0) {
            for (int i = 0; i < filterNames.size(); ++i) {
                ASName filter;
                try {
                    filter = filterNames.getName(i);
                }
                catch (PDFUnableToCompleteOperationException e) {
                    throw new PDFInvalidContentException("Invaid filters array", (Throwable)e);
                }
                if (filter == ASName.k_AHx || filter == ASName.k_ASCIIHexDecode) {
                    is = new ASCIIHexInputStream(is, filterParams);
                    continue;
                }
                if (filter == ASName.k_A85 || filter == ASName.k_ASCII85Decode) {
                    is = new ASCII85InputStream(is, filterParams);
                    continue;
                }
                if (filter == ASName.k_Fl || filter == ASName.k_FlateDecode) {
                    InflaterInputStream result = new InflaterInputStream(is);
                    if (filterParams != null && filterParams.containsKey((Object)"Predictor") && (Integer)filterParams.get((Object)"Predictor") != 1) {
                        is = new TIFFInputStream((InputStream)result, filterParams);
                        continue;
                    }
                    is = result;
                    continue;
                }
                if (filter == ASName.k_LZW || filter == ASName.k_LZWDecode) {
                    is = new LZWInputStream(is, filterParams);
                    continue;
                }
                if (filter == ASName.k_RL || filter == ASName.k_RunLengthDecode) {
                    is = new RunLengthInputStream(is, filterParams);
                    continue;
                }
                if (filter == ASName.k_CCF || filter == ASName.k_CCITTFaxDecode) {
                    is = new CCITTFaxInputStream(is, filterParams);
                    continue;
                }
                if (filter != ASName.k_DCT && filter != ASName.k_DCTDecode) continue;
                is = new DCTInputStream(is, filterParams);
            }
        }
        return is;
    }

    private static boolean DCTFilterSupported(PDFDocument doc) {
        CustomFilterRegistry registry = doc.getCosDocument().getOptions().getCustomFilterRegistry();
        if (registry != null) {
            return registry.isEncodeFilterRegistered(ASName.k_DCTDecode);
        }
        return false;
    }

    public void close() throws PDFIOException {
        try {
            if (this.unencodedImageData != null) {
                this.unencodedImageData.close();
            }
        }
        catch (IOException e) {
            throw new PDFIOException((Throwable)e);
        }
        finally {
            try {
                if (this.encodedImageData != null) {
                    this.encodedImageData.close();
                }
            }
            catch (IOException e) {
                throw new PDFIOException((Throwable)e);
            }
        }
    }

    static class PaddedByteArrayOutputStream
    extends ByteArrayOutputStream {
        private int paddingSize;
        private byte paddingByte = 32;

        PaddedByteArrayOutputStream() {
        }

        PaddedByteArrayOutputStream(int size) {
            super(size);
        }

        public void close() throws IOException {
            for (int i = 0; i < this.paddingSize; ++i) {
                this.write(32);
            }
            super.close();
        }

        void setPaddingSize(int paddingSize) {
            this.paddingSize = paddingSize;
        }

        int getPaddingSize() {
            return this.paddingSize;
        }

        void setPaddingByte(byte paddingByte) {
            this.paddingByte = paddingByte;
        }

        byte getPaddingByte() {
            return this.paddingByte;
        }
    }

}