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

📄 pngmetadata.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
             * use PNG_COLOR_PALETTE color type for large images.             */             if (isGray && hasAlpha && (bitDepth == 8 || bitDepth == 16)) {                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;            } else if (isGray && !hasAlpha) {                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY;            } else {                IHDR_colorType = PNGImageReader.PNG_COLOR_PALETTE;                PLTE_present = true;                PLTE_order = null;                PLTE_red = (byte[])reds.clone();                PLTE_green = (byte[])greens.clone();                PLTE_blue = (byte[])blues.clone();                if (hasAlpha) {                    tRNS_present = true;                    tRNS_colorType = PNGImageReader.PNG_COLOR_PALETTE;                    PLTE_order = new int[alpha.length];                    // Reorder the palette so that non-opaque entries                    // come first.  Since the tRNS chunk does not have                    // to store trailing 255's, this can save a                    // considerable amount of space when encoding                    // images with only one transparent pixel value,                    // e.g., images from GIF sources.                    byte[] newAlpha = new byte[alpha.length];                    // Scan for non-opaque entries and assign them                    // positions starting at 0.                    int newIndex = 0;                    for (int i = 0; i < alpha.length; i++) {                        if (alpha[i] != (byte)255) {                            PLTE_order[i] = newIndex;                            newAlpha[newIndex] = alpha[i];                            ++newIndex;                        }                    }                    int numTransparent = newIndex;                    // Scan for opaque entries and assign them                    // positions following the non-opaque entries.                    for (int i = 0; i < alpha.length; i++) {                        if (alpha[i] == (byte)255) {                            PLTE_order[i] = newIndex++;                        }                    }                    // Reorder the palettes                    byte[] oldRed = PLTE_red;                    byte[] oldGreen = PLTE_green;                    byte[] oldBlue = PLTE_blue;                    int len = oldRed.length; // All have the same length                    PLTE_red = new byte[len];                    PLTE_green = new byte[len];                    PLTE_blue = new byte[len];                    for (int i = 0; i < len; i++) {                        PLTE_red[PLTE_order[i]] = oldRed[i];                        PLTE_green[PLTE_order[i]] = oldGreen[i];                        PLTE_blue[PLTE_order[i]] = oldBlue[i];                    }                    // Copy only the transparent entries into tRNS_alpha                    tRNS_alpha = new byte[numTransparent];                    System.arraycopy(newAlpha, 0,                                     tRNS_alpha, 0, numTransparent);                }            }        } else {            if (numBands == 1) {                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY;            } else if (numBands == 2) {                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;            } else if (numBands == 3) {                IHDR_colorType = PNGImageReader.PNG_COLOR_RGB;            } else if (numBands == 4) {                IHDR_colorType = PNGImageReader.PNG_COLOR_RGB_ALPHA;            } else {                throw new RuntimeException("Number of bands not 1-4!");            }        }        IHDR_present = true;    }    public boolean isReadOnly() {        return false;    }    private ArrayList cloneBytesArrayList(ArrayList in) {        if (in == null) {            return null;        } else {            ArrayList list = new ArrayList(in.size());            Iterator iter = in.iterator();            while (iter.hasNext()) {                Object o = iter.next();                if (o == null) {                    list.add(null);                } else {                    list.add(((byte[])o).clone());                }            }            return list;        }    }    // Deep clone    public Object clone() {        PNGMetadata metadata;        try {            metadata = (PNGMetadata)super.clone();        } catch (CloneNotSupportedException e) {            return null;        }                // unknownChunkData needs deep clone        metadata.unknownChunkData =            cloneBytesArrayList(this.unknownChunkData);        return metadata;    }    public Node getAsTree(String formatName) {        if (formatName.equals(nativeMetadataFormatName)) {            return getNativeTree();        } else if (formatName.equals                   (IIOMetadataFormatImpl.standardMetadataFormatName)) {            return getStandardTree();        } else {            throw new IllegalArgumentException("Not a recognized format!");        }    }    private Node getNativeTree() {        IIOMetadataNode node = null; // scratch node        IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);                // IHDR        if (IHDR_present) {            IIOMetadataNode IHDR_node = new IIOMetadataNode("IHDR");            IHDR_node.setAttribute("width", Integer.toString(IHDR_width));            IHDR_node.setAttribute("height", Integer.toString(IHDR_height));            IHDR_node.setAttribute("bitDepth",                                   Integer.toString(IHDR_bitDepth));            IHDR_node.setAttribute("colorType",                                   IHDR_colorTypeNames[IHDR_colorType]);            // IHDR_compressionMethod must be 0 in PNG 1.1            IHDR_node.setAttribute("compressionMethod",                          IHDR_compressionMethodNames[IHDR_compressionMethod]);            // IHDR_filterMethod must be 0 in PNG 1.1            IHDR_node.setAttribute("filterMethod",                                    IHDR_filterMethodNames[IHDR_filterMethod]);            IHDR_node.setAttribute("interlaceMethod",                              IHDR_interlaceMethodNames[IHDR_interlaceMethod]);            root.appendChild(IHDR_node);        }        // PLTE        if (PLTE_present) {            IIOMetadataNode PLTE_node = new IIOMetadataNode("PLTE");            int numEntries = PLTE_red.length;            for (int i = 0; i < numEntries; i++) {                IIOMetadataNode entry = new IIOMetadataNode("PLTEEntry");                entry.setAttribute("index", Integer.toString(i));                entry.setAttribute("red",                                   Integer.toString(PLTE_red[i] & 0xff));                entry.setAttribute("green",                                   Integer.toString(PLTE_green[i] & 0xff));                entry.setAttribute("blue",                                   Integer.toString(PLTE_blue[i] & 0xff));                PLTE_node.appendChild(entry);            }            root.appendChild(PLTE_node);        }        // bKGD        if (bKGD_present) {            IIOMetadataNode bKGD_node = new IIOMetadataNode("bKGD");                        if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {                node = new IIOMetadataNode("bKGD_Palette");                node.setAttribute("index", Integer.toString(bKGD_index));            } else if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {                node = new IIOMetadataNode("bKGD_Grayscale");                node.setAttribute("gray", Integer.toString(bKGD_gray));            } else if (bKGD_colorType == PNGImageReader.PNG_COLOR_RGB) {                node = new IIOMetadataNode("bKGD_RGB");                node.setAttribute("red", Integer.toString(bKGD_red));                node.setAttribute("green", Integer.toString(bKGD_green));                node.setAttribute("blue", Integer.toString(bKGD_blue));            }            bKGD_node.appendChild(node);            root.appendChild(bKGD_node);        }        // cHRM        if (cHRM_present) {            IIOMetadataNode cHRM_node = new IIOMetadataNode("cHRM");            cHRM_node.setAttribute("whitePointX",                              Integer.toString(cHRM_whitePointX));            cHRM_node.setAttribute("whitePointY",                              Integer.toString(cHRM_whitePointY));            cHRM_node.setAttribute("redX", Integer.toString(cHRM_redX));            cHRM_node.setAttribute("redY", Integer.toString(cHRM_redY));            cHRM_node.setAttribute("greenX", Integer.toString(cHRM_greenX));            cHRM_node.setAttribute("greenY", Integer.toString(cHRM_greenY));            cHRM_node.setAttribute("blueX", Integer.toString(cHRM_blueX));            cHRM_node.setAttribute("blueY", Integer.toString(cHRM_blueY));            root.appendChild(cHRM_node);        }        // gAMA        if (gAMA_present) {            IIOMetadataNode gAMA_node = new IIOMetadataNode("gAMA");            gAMA_node.setAttribute("value", Integer.toString(gAMA_gamma));            root.appendChild(gAMA_node);        }        // hIST        if (hIST_present) {            IIOMetadataNode hIST_node = new IIOMetadataNode("hIST");            for (int i = 0; i < hIST_histogram.length; i++) {                IIOMetadataNode hist =                    new IIOMetadataNode("hISTEntry");                hist.setAttribute("index", Integer.toString(i));                hist.setAttribute("value",                                  Integer.toString(hIST_histogram[i]));                hIST_node.appendChild(hist);            }            root.appendChild(hIST_node);        }        // iCCP        if (iCCP_present) {            IIOMetadataNode iCCP_node = new IIOMetadataNode("iCCP");            iCCP_node.setAttribute("profileName", iCCP_profileName);            iCCP_node.setAttribute("compressionMethod",                          iCCP_compressionMethodNames[iCCP_compressionMethod]);            Object profile = iCCP_compressedProfile;            if (profile != null) {                profile = ((byte[])profile).clone();            }            iCCP_node.setUserObject(profile);            root.appendChild(iCCP_node);        }        // iTXt        if (iTXt_keyword.size() > 0) {            IIOMetadataNode iTXt_parent = new IIOMetadataNode("iTXt");            for (int i = 0; i < iTXt_keyword.size(); i++) {                Integer val;                                IIOMetadataNode iTXt_node = new IIOMetadataNode("iTXtEntry");                iTXt_node.setAttribute("keyword", (String)iTXt_keyword.get(i));                val = (Integer)iTXt_compressionFlag.get(i);                iTXt_node.setAttribute("compressionFlag", val.toString());                val = (Integer)iTXt_compressionMethod.get(i);                iTXt_node.setAttribute("compressionMethod", val.toString());                iTXt_node.setAttribute("languageTag",                                       (String)iTXt_languageTag.get(i));                iTXt_node.setAttribute("translatedKeyword",                                       (String)iTXt_translatedKeyword.get(i));                iTXt_node.setAttribute("text", (String)iTXt_text.get(i));                                iTXt_parent.appendChild(iTXt_node);            }                        root.appendChild(iTXt_parent);        }        // pHYs        if (pHYs_present) {            IIOMetadataNode pHYs_node = new IIOMetadataNode("pHYs");            pHYs_node.setAttribute("pixelsPerUnitXAxis",                              Integer.toString(pHYs_pixelsPerUnitXAxis));            pHYs_node.setAttribute("pixelsPerUnitYAxis",                                   Integer.toString(pHYs_pixelsPerUnitYAxis));            pHYs_node.setAttribute("unitSpecifier",                                   unitSpecifierNames[pHYs_unitSpecifier]);            root.appendChild(pHYs_node);        }        // sBIT        if (sBIT_present) {            IIOMetadataNode sBIT_node = new IIOMetadataNode("sBIT");            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY) {                node = new IIOMetadataNode("sBIT_Grayscale");                node.setAttribute("gray",                                  Integer.toString(sBIT_grayBits));            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {                node = new IIOMetadataNode("sBIT_GrayAlpha");                node.setAttribute("gray",                                  Integer.toString(sBIT_grayBits));                node.setAttribute("alpha",                                  Integer.toString(sBIT_alphaBits));            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB) {                node = new IIOMetadataNode("sBIT_RGB");                node.setAttribute("red",                                  Integer.toString(sBIT_redBits));                node.setAttribute("green",                                  Integer.toString(sBIT_greenBits));                node.setAttribute("blue",                                  Integer.toString(sBIT_blueBits));            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {                node = new IIOMetadataNode("sBIT_RGBAlpha");                node.setAttribute("red",                                  Integer.toString(sBIT_redBits));                node.setAttribute("green",

⌨️ 快捷键说明

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