⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpegimagewriter.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                            if (!alpha) {                                if (jfif != null) {                                    outCsType = JPEG.JCS_YCbCr;                                    if (JPEG.isNonStandardICC(cs)                                         || ((cs instanceof ICC_ColorSpace)                                             && (jfif.iccSegment != null))) {                                        iccProfile =                                             ((ICC_ColorSpace) cs).getProfile();                                    }                                } else if (adobe != null) {                                    switch (adobe.transform) {                                     case JPEG.ADOBE_UNKNOWN:                                        outCsType = JPEG.JCS_RGB;                                        break;                                    case JPEG.ADOBE_YCC:                                        outCsType = JPEG.JCS_YCbCr;                                        break;                                    default:                                        warningOccurred                                        (WARNING_IMAGE_METADATA_ADOBE_MISMATCH);                                        newAdobeTransform = JPEG.ADOBE_UNKNOWN;                                        outCsType = JPEG.JCS_RGB;                                        break;                                    }                                } else {                                    // consult the ids                                    int outCS = sof.getIDencodedCSType();                                    // if they don't resolve it,                                    // consult the sampling factors                                    if (outCS != JPEG.JCS_UNKNOWN) {                                        outCsType = outCS;                                    } else {                                        boolean subsampled =                                         isSubsampled(sof.componentSpecs);                                        if (subsampled) {                                            outCsType = JPEG.JCS_YCbCr;                                        } else {                                            outCsType = JPEG.JCS_RGB;                                        }                                    }                                }                            } else { // RGBA                                if (jfif != null) {                                    ignoreJFIF = true;                                    warningOccurred                                    (WARNING_IMAGE_METADATA_JFIF_MISMATCH);                                }                                if (adobe != null) {                                    if (adobe.transform                                         != JPEG.ADOBE_UNKNOWN) {                                        newAdobeTransform = JPEG.ADOBE_UNKNOWN;                                        warningOccurred                                        (WARNING_IMAGE_METADATA_ADOBE_MISMATCH);                                    }                                    outCsType = JPEG.JCS_RGBA;                                } else {                                    // consult the ids                                    int outCS = sof.getIDencodedCSType();                                    // if they don't resolve it,                                    // consult the sampling factors                                    if (outCS != JPEG.JCS_UNKNOWN) {                                        outCsType = outCS;                                    } else {                                        boolean subsampled =                                         isSubsampled(sof.componentSpecs);                                        outCsType = subsampled ?                                             JPEG.JCS_YCbCrA : JPEG.JCS_RGBA;                                    }                                }                            }                            break;                        case ColorSpace.TYPE_3CLR:                            if (cs == JPEG.YCC) {                                if (!alpha) {                                    if (jfif != null) {                                        convertTosRGB = true;                                        convertOp =                                         new ColorConvertOp(cs,                                                            JPEG.sRGB,                                                            null);                                        outCsType = JPEG.JCS_YCbCr;                                    } else if (adobe != null) {                                        if (adobe.transform                                             != JPEG.ADOBE_YCC) {                                            newAdobeTransform = JPEG.ADOBE_YCC;                                            warningOccurred                                            (WARNING_IMAGE_METADATA_ADOBE_MISMATCH);                                        }                                        outCsType = JPEG.JCS_YCC;                                    } else {                                        outCsType = JPEG.JCS_YCC;                                    }                                } else { // PhotoYCCA                                    if (jfif != null) {                                        ignoreJFIF = true;                                        warningOccurred                                        (WARNING_IMAGE_METADATA_JFIF_MISMATCH);                                    } else if (adobe != null) {                                        if (adobe.transform                                             != JPEG.ADOBE_UNKNOWN) {                                            newAdobeTransform                                             = JPEG.ADOBE_UNKNOWN;                                            warningOccurred                                            (WARNING_IMAGE_METADATA_ADOBE_MISMATCH);                                        }                                    }                                    outCsType = JPEG.JCS_YCCA;                                }                            }                        }                    }                } // else no dest, metadata, not an image.  Defaults ok            }        }        boolean metadataProgressive = false;        int [] scans = null;        if (metadata != null) {            if (sof == null) {                sof = (SOFMarkerSegment) metadata.findMarkerSegment                    (SOFMarkerSegment.class, true);            }            if ((sof != null) && (sof.tag == JPEG.SOF2)) {                metadataProgressive = true;                if (progressiveMode == ImageWriteParam.MODE_COPY_FROM_METADATA) {                    scans = collectScans(metadata, sof);  // Might still be null                } else {                    numScans = 0;                }            }            if (jfif == null) {                jfif = (JFIFMarkerSegment) metadata.findMarkerSegment                    (JFIFMarkerSegment.class, true);            }        }        thumbnails = image.getThumbnails();        int numThumbs = image.getNumThumbnails();        forceJFIF = false;        // determine if thumbnails can be written        // If we are going to add a default JFIF marker segment,        // then thumbnails can be written        if (!writeDefaultJFIF) {            // If there is no metadata, then we can't write thumbnails            if (metadata == null) {                thumbnails = null;                if (numThumbs != 0) {                    warningOccurred(WARNING_IGNORING_THUMBS);                }            } else {                // There is metadata                // If we are writing a raster or subbands,                // then the user must specify JFIF on the metadata                if (fullImage == false) {                    if (jfif == null) {                        thumbnails = null;  // Or we can't include thumbnails                        if (numThumbs != 0) {                            warningOccurred(WARNING_IGNORING_THUMBS);                        }                    }                } else {  // It is a full image, and there is metadata                    if (jfif == null) {  // Not JFIF                        // Can it have JFIF?                        if ((outCsType == JPEG.JCS_GRAYSCALE)                            || (outCsType == JPEG.JCS_YCbCr)) {                            if (numThumbs != 0) {                                forceJFIF = true;                                warningOccurred(WARNING_FORCING_JFIF);                            }                        } else {  // Nope, not JFIF-compatible                            thumbnails = null;                            if (numThumbs != 0) {                                warningOccurred(WARNING_IGNORING_THUMBS);                            }                        }                    }                }            }        }        // Set up a boolean to indicate whether we need to call back to         // write metadata        boolean haveMetadata =             ((metadata != null) || writeDefaultJFIF || writeAdobe);        // Now that we have dealt with metadata, finalize our tables set up        // Are we going to write tables?  By default, yes.        boolean writeDQT = true;        boolean writeDHT = true;        // But if the metadata has no tables, no.        DQTMarkerSegment dqt = null;        DHTMarkerSegment dht = null;        int restartInterval = 0;        if (metadata != null) {            dqt = (DQTMarkerSegment) metadata.findMarkerSegment                (DQTMarkerSegment.class, true);            dht = (DHTMarkerSegment) metadata.findMarkerSegment                (DHTMarkerSegment.class, true);            DRIMarkerSegment dri =                 (DRIMarkerSegment) metadata.findMarkerSegment                (DRIMarkerSegment.class, true);            if (dri != null) {                restartInterval = dri.restartInterval;            }            if (dqt == null) {                writeDQT = false;            }            if (dht == null) {                writeDHT = false;  // Ignored if optimizeHuffman is true            }        }        // Whether we write tables or not, we need to figure out which ones         // to use        if (qTables == null) { // Get them from metadata, or use defaults            if (dqt != null) {                qTables = collectQTablesFromMetadata(metadata);            } else if (streamQTables != null) {                 qTables = streamQTables;            } else if ((jparam != null) && (jparam.areTablesSet())) {                qTables = jparam.getQTables();            } else {                qTables = JPEG.getDefaultQTables();            }        }        // If we are optimizing, we don't want any tables.        if (optimizeHuffman == false) {            // If they were for progressive scans, we can't use them.            if ((dht != null) && (metadataProgressive == false)) {                DCHuffmanTables = collectHTablesFromMetadata(metadata, true);                ACHuffmanTables = collectHTablesFromMetadata(metadata, false);            } else if (streamDCHuffmanTables != null) {                 DCHuffmanTables = streamDCHuffmanTables;                ACHuffmanTables = streamACHuffmanTables;            } else if ((jparam != null) && (jparam.areTablesSet())) {                DCHuffmanTables = jparam.getDCHuffmanTables();                ACHuffmanTables = jparam.getACHuffmanTables();            } else {                DCHuffmanTables = JPEG.getDefaultHuffmanTables(true);                ACHuffmanTables = JPEG.getDefaultHuffmanTables(false);            }        }        // By default, ids are 1 - N, no subsampling        int [] componentIds = new int[numBandsUsed];        int [] HsamplingFactors = new int[numBandsUsed];        int [] VsamplingFactors = new int[numBandsUsed];        int [] QtableSelectors = new int[numBandsUsed];        for (int i = 0; i < numBandsUsed; i++) {            componentIds[i] = i+1; // JFIF compatible            HsamplingFactors[i] = 1;            VsamplingFactors[i] = 1;            QtableSelectors[i] = 0;        }        // Now override them with the contents of sof, if there is one,        if (sof != null) {            for (int i = 0; i < numBandsUsed; i++) {                if (forceJFIF == false) {  // else use JFIF-compatible default                    componentIds[i] = sof.componentSpecs[i].componentId;                }                HsamplingFactors[i] = sof.componentSpecs[i].HsamplingFactor;                VsamplingFactors[i] = sof.componentSpecs[i].VsamplingFactor;                QtableSelectors[i] = sof.componentSpecs[i].QtableSelector;            }        }        sourceXOffset += gridX;        sourceWidth -= gridX;        sourceYOffset += gridY;        sourceHeight -= gridY;        int destWidth = (sourceWidth + periodX - 1)/periodX;        int destHeight = (sourceHeight + periodY - 1)/periodY;        // Create an appropriate 1-line databuffer for writing        int lineSize = sourceWidth*numBandsUsed;                DataBufferByte buffer = new DataBufferByte(lineSize);        // Create a raster from that        int [] bandOffs = JPEG.bandOffsets[numBandsUsed-1];                raster = Raster.createInterleavedRaster(buffer,                                                 sourceWidth, 1,                                                 lineSize,                                                numBandsUsed,                                                bandOffs,                                                null);        // Call the writer, who will call back for every scanline        processImageStarted(currentImage);                    boolean aborted = false;        if (debug) {            System.out.println("inCsType: " + inCsType);            System.out.println("outCsType: " + outCsType);        }        aborted = writeImage(structPointer,                             buffer.getData(),                              inCsType, outCsType,                             numBandsUsed,                             bandSizes,                             sourceWidth,                             destWidth, destHeight,                             periodX, periodY,                             qTables,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -