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

📄 skinromizationtool.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    + "raw file " + '"' + rawFormat + '"'                     + ", color " + '"' + colorFormat + '"');        }    }        /**     * Collects single skin property element.     *     * @param n DOM node corresponding to skin property description     * in XML file     * @exception Exception if there was an error during romization     */    private void collectSkinProperty(Node n)         throws Exception {        if (n instanceof Element) {            SkinPropertyBase p = SkinPropertyBase.valueOf(n);            // ID of the property is the index into skinProperties vector            if (allProps.size() < p.id + 1) {                allProps.setSize(p.id + 1);            }            if (allProps.elementAt(p.id) != null) {                throw new IllegalArgumentException(                        "Duplicate skin property " + p.idName);            }            allProps.setElementAt(p, p.id);            if (p instanceof IntSeqSkinProperty) {                intSeqProps.add(p);            } else if (p instanceof StringSkinProperty) {                stringProps.add(p);            } else if (p instanceof FontSkinProperty) {                fontProps.add(p);            } else if (p instanceof ImageSkinProperty) {                ImageSkinProperty ip = (ImageSkinProperty)p;                if (romizationJob.imageRomOverride.equals("all") ||                        romizationJob.romizeAll) {                    ip.isRomized = true;                } else if (romizationJob.imageRomOverride.equals("none")) {                    ip.isRomized = false;                }                                imageProps.add(p);            } else if (p instanceof CompositeImageSkinProperty) {                CompositeImageSkinProperty ip = (CompositeImageSkinProperty)p;                if (romizationJob.imageRomOverride.equals("all") ||                        romizationJob.romizeAll) {                    ip.isRomized = true;                } else if (romizationJob.imageRomOverride.equals("none")) {                    ip.isRomized = false;                }                                compImageProps.add(p);            }        }    }        /**     * Assigns offsets into properties values array     *     * @param props properties to assign offsets for     * @param startOffset offset to start from     * @return offset past the last property value     */    private static int assignPropertiesValuesOffsets(Vector props,             int startOffset) {        // current (last) offset in the values array        int curOffset = startOffset;                for (int i = 0; i < props.size(); ++i) {            SkinPropertyBase curP = (SkinPropertyBase)props.elementAt(i);            // properties with same values share same offset,            // so look if there already was property with same value            int sameValueOffset = -1;            for (int j = i - 1; j >= 0; --j) {                SkinPropertyBase p = (SkinPropertyBase)props.elementAt(j);                if (p.isEqualValue(curP)) {                    sameValueOffset = p.valueOffset;                    break;                }            }            if (sameValueOffset != -1) {                // use offset from property with same value                curP.valueOffset = sameValueOffset;            } else {                // this value is new, give it current offset                 curP.valueOffset = curOffset;                curOffset += curP.getValueOffsetDelta();            }        }        return curOffset;    }    /**     * Romizes images     *     * @exception IOException if there was IO error during romization     */    private void romizeImages()         throws IOException {        int maxOffset = -1;        for (int i = 0; i < imageProps.size(); ++i) {            ImageSkinProperty p = (ImageSkinProperty)imageProps.elementAt(i);            if (!(p.isRomized) || !p.hasValue) {                continue;            }            // this property has the same value as some other             // property seen before, so skip it            if (p.valueOffset <= maxOffset) {                continue;            }            romizeImage(p.value, p.valueOffset);            maxOffset = p.valueOffset;        }        for (int i = 0; i < compImageProps.size(); ++i) {            CompositeImageSkinProperty p =                 (CompositeImageSkinProperty)compImageProps.elementAt(i);            if (!(p.isRomized) || !p.hasValue) {                continue;            }            // this property has the same value as some other             // property seen before, so skip it            if (p.valueOffset <= maxOffset) {                continue;            }            for (int j = 0; j < p.value.length; ++j) {                romizeImage(p.value[j], p.valueOffset + j);            }            maxOffset = p.valueOffset;        }    }    /**     * Romizes single image     *     * @param imageName of the image to romize without extension     * @param imageIndex romized image index     * @exception IOException if there was IO error during romization     */    private void romizeImage(String imageName, int imageIndex)         throws IOException {        // we romize png images only        String imageFileName = imageName + ".png";        imageFileName = romizationJob.skinImagesDirName + File.separator +             imageFileName;        System.out.println("     " + imageFileName);                // load image        BufferedImage image = javax.imageio.ImageIO.read(                new File(imageFileName));        // and romize it        RomizedImage ri = romizedImageFactory.createFromBufferedImage(image,                imageIndex);        romizedImages.set(imageIndex, ri);    }    /**     * Writes RomizedSkin class file header     */    private void writeBinHeader()         throws IOException {        // write magic sequence        int magicLength = SkinResourcesConstants.CHAM_BIN_MAGIC.length;        for (int i = 0; i < magicLength; ++i) {            byte b = (byte)(SkinResourcesConstants.CHAM_BIN_MAGIC[i] & 0xFF);            outputStream.writeByte(b);        }        // write version info as an array         outputStream.writeInt(1); // array size        outputStream.writeInt(SkinResourcesConstants.CHAM_BIN_FORMAT_VERSION);    }    /**     *  Writes romized images C file header     */    private void writeCHeader() {        writeCopyright();        pl("");        pl("#include <string.h>");        pl("#include <kni.h>");        pl("#include <midpError.h>");        pl("#include <midpMalloc.h>");        pl("#include <midpServices.h>\n");    }        /**     * Writes romized properties data     * @exception Exception if there was an error during output     */    private void writeRomizedProperties()         throws Exception {                    outputStream.writeInt(allProps.size());        for (int i = 0; i < allProps.size(); ++i) {            SkinPropertyBase p = (SkinPropertyBase)allProps.elementAt(i);            if (p instanceof IntSkinProperty) {                IntSkinProperty intP = (IntSkinProperty)p;                // for integer property the array holds actual property's                 // value, not an offset into values array                p.outputValue(outputStream);            } else {                // for all other properties the array holds an offset into                // values array, in which actual values are stored                outputStream.writeInt(p.valueOffset);            }        }        writePropertiesValues(intSeqProps);        writePropertiesValues(stringProps);        writePropertiesValues(fontProps);        Vector v = new Vector(imageProps);        v.addAll(compImageProps);        writePropertiesValues(v);        writeRomizedImagesIndexes();    }        /**     * Writes properties values array entries     *     * @param props properties to write entries for      */    private void writePropertiesValues(Vector props)         throws java.io.IOException {        int maxOffset = -1;        int totalValues = 0;        for (int i = 0; i < props.size(); ++i) {            SkinPropertyBase p = (SkinPropertyBase)props.elementAt(i);            // this property has the same value as some other             // property printed before, so skip it            if (p.valueOffset <= maxOffset) {                continue;            }            totalValues += p.getValueOffsetDelta();            maxOffset = p.valueOffset;        }        outputStream.writeInt(totalValues);        maxOffset = -1;        for (int i = 0; i < props.size(); ++i) {            SkinPropertyBase p = (SkinPropertyBase)props.elementAt(i);            // this property has the same value as some other             // property outputed before, so skip it            if (p.valueOffset <= maxOffset) {                continue;            }            p.outputValue(outputStream);            maxOffset = p.valueOffset;        }    }        /**     * Writes indexes for romized images.      */    private void writeRomizedImagesIndexes()         throws java.io.IOException {        outputStream.writeInt(romizedImages.size());        for (int i = 0; i < romizedImages.size(); ++i) {            Object o = romizedImages.elementAt(i);            // image with index = i isn't romized            if (o == null) {                outputStream.writeInt(-1);            } else {                RomizedImage ri = (RomizedImage)o;                outputStream.writeInt(ri.imageIndex);            }        }    }        /**     *  Writes romized images data     */    private void writeRomizedImagesData() {        int totalRomizedImages = 0;        for (int i = 0; i < romizedImages.size(); ++i) {            if (romizedImages.elementAt(i) != null) {                ++totalRomizedImages;            }        }                pl("");        pl("static const int NUM_ROM_IMAGES = " + totalRomizedImages + ";");                if (totalRomizedImages != 0) {            // output a structure declaration used for storing             // romized images data in it            pl("");            pl("struct romized_images_data {");            for (int i = 0; i < romizedImages.size(); ++i) {                Object o = romizedImages.elementAt(i);                if (o != null) {                    RomizedImage ri = (RomizedImage)o;                    // this field ensures proper alignment of                     // subsequent data array                    pl("    " + "const int align_" + ri.imageIndex + ";");                    String dataArrayName = "romized_image" + ri.imageIndex;                    int dataArrayLength = ri.size();                    pl("    " + "const unsigned char " + dataArrayName +                             "[" + dataArrayLength + "];");                }            }            pl("};");            pl("");            pl("static const struct romized_images_data " +                     "romized_images_data = {");            for (int i = 0; i < romizedImages.size(); ++i) {                Object o = romizedImages.elementAt(i);                if (o != null) {                    // alignemnt field                    pl("    " + "0,");                    RomizedImage ri = (RomizedImage)o;                    String dataArrayName = "romized_image" + ri.imageIndex;                    // romized image data field                    pl("    " + "/* " + dataArrayName + " */");                    pl("    " +"{");                    ri.printDataArray(writer, "        ", 11);                    pl(" },");                }            }            pl("};");        }        pl("");        pl("static const unsigned char* image_cache[] = {");        // if there are no romized images, print dummy value        // to make array non empty and keep compilers happy        if (totalRomizedImages == 0) {            pl("    NULL");        } else {            for (int i = 0; i < romizedImages.size(); ++i) {                Object o = romizedImages.elementAt(i);                if (o != null) {                    RomizedImage ri = (RomizedImage)o;                    String dataArrayName =                         "romized_images_data.romized_image" + ri.imageIndex;                    pl("    " + dataArrayName + ",");                }            }        }        pl("};");        pl("");        pl("static const int image_size[] = {");         // if there are no romized images, print dummy value        // to make array non empty and keep compilers happy        if (totalRomizedImages == 0) {            pl("    0");        } else {            for (int i = 0; i < romizedImages.size(); ++i) {                Object o = romizedImages.elementAt(i);                if (o != null) {                    RomizedImage ri = (RomizedImage)o;                    String dataArrayName =                         "romized_images_data.romized_image" + ri.imageIndex;                    pl("    sizeof(" + dataArrayName + "),");                }            }        }        pl("};");    }    /**     * Writes get method for obtaining romized image data     */    void writeGetMethod() {        pl("");        pl("/**");        pl(" * Loads a native image from rom, if present.");         pl(" *");        pl(" * @param imageId    The image id");        pl(" * @param **bufPtr   Pointer where a buffer will be "		    + "allocated and data stored");        pl(" * @return           -1 if failed, else length of buffer");        pl(" */");        pl("int lfj_load_image_from_rom(int imageId, "		    + "unsigned char** bufPtr) {\n");        pl("    int len = -1;");        pl("    if ((imageId < 0) || (imageId > NUM_ROM_IMAGES)) {");        pl("        REPORT_WARN1(LC_LOWUI,");         pl("            \"Warning: could not load romized" +		    "image for index %d; \", imageId); ");        pl("        return len;");        pl("    }\n");        pl("    *bufPtr = (unsigned char*)image_cache[imageId];");        pl("    len = image_size[imageId];");        pl("    return len;");        pl("}");    }    /**     *     * @param data data to convert into the C array, can be null     */    void writeSkinDescription(byte[] data) {        pl("");        pl("static const unsigned char skin_description[] = {");        if (data != null) {            new RomizedByteArray(data).printDataArray(writer, "        ", 11);        } else {            pl("    0");        }        pl("};");        pl("");        pl("/**");        pl(" * Loads a ROMized skin description from ROM, if present.");        pl(" *");        pl(" * @return NULL if failed, otherwise a pointer to the skin " +                "description data");        pl(" */");        pl("const unsigned char* lfj_get_skin_description() {");        if (data != null) {            pl("    return skin_description;");        } else {            pl("    return NULL;");        }        pl("}");        pl("");        pl("/**");        pl(" * Retrieves the size of the skin description data.");        pl(" *");        pl(" * @return -1 if failed, otherwise a size of the skin " +                "description data");        pl(" */");        pl("int lfj_get_skin_description_size() {");        if (data != null) {            pl("    return " + data.length + ";");        } else {            pl("    return -1;");        }        pl("}");    }    /**     * Creates a directory structure.     *     * @param fullFileName Full path to the file to be created. If directory     * in which file is to be created doesn't exists, it will be created     * @exception IOException is thrown if directory couldn't be created      */    private void makeDirectoryTree(String fullFileName)         throws IOException {        if (debug == true) {            System.out.println("mkdir: " + fullFileName);        }        int index = fullFileName.lastIndexOf(File.separatorChar);        if (index == -1) {            // To be compatible with MKS-hosted build on win32, which            // does not translate / to \.            index = fullFileName.lastIndexOf('/');        }        File outputDirectory = new File(fullFileName.substring(0, index));        if (!(outputDirectory).exists()) {            if (!(outputDirectory).mkdirs()) {                throw new IOException("failed to create output directory");            }        }    }}

⌨️ 快捷键说明

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