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

📄 bitmap.java

📁 cygwin 是一个在windows平台上运行的unix模拟环境
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    x = 0;
                    height--;

                    previous = line;
                    prevY = previous / width;
                    line = height * width;
                }

                switch (opcode) {
                case 0: /* Fill */
                    if (insertmix) {
                        if (previous == -1) {
                            // pixel[line+x] = mix;
                            w.setRGB(left+x,top+height,mix);
                        } else {
                            w.setRGB(left+x,top+height,w.getRGB(left+x,top+prevY) ^ mix);
                            // pixel[line+x] = (pixel[previous+x] ^ mix);
                        }

                        insertmix = false;
                        count--;
                        x++;
                    }

                    if (previous == -1) {
                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                // pixel[line+x] = 0;
                                w.setRGB(left+x,top+height,0);
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            // pixel[line+x] = 0;
                            w.setRGB(left+x,top+height,0);
                            count--;
                            x++;
                        }
                    } else {
                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                // pixel[line + x] = pixel[previous + x];
                                w.setRGB(left+x,top+height, w.getRGB(left+x,top+prevY));
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            // pixel[line + x] = pixel[previous + x];
                            w.setRGB(left+x,top+height, w.getRGB(left+x,top+prevY));                          
                            count--;
                            x++;
                        }
                    }
                    break;

                case 1: /* Mix */
                    if (previous == -1) {
                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                // pixel[line + x] = mix;
                                w.setRGB(left+x,top+height,mix);
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            // pixel[line + x] = mix;
                            w.setRGB(left+x,top+height,mix);
                            count--;
                            x++;
                        }
                    } else {

                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                // pixel[line + x] = pixel[previous + x] ^ mix;
                                w.setRGB(left+x,top+height, w.getRGB(left+x,top+prevY) ^ mix);
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            // pixel[line + x] = pixel[previous + x] ^ mix;
                            w.setRGB(left+x,top+height, w.getRGB(left+x,top+prevY) ^ mix);
                            count--;
                            x++;
                        }

                    }
                    break;
                case 2: /* Fill or Mix */
                    if (previous == -1) {
                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                mixmask <<= 1;
                                if (mixmask == 0) {
                                    mask = (fom_mask != 0) ? (byte) fom_mask
                                            : compressed_pixel[input++];
                                    mixmask = 1;
                                }
                                if ((mask & mixmask) != 0){
                                    // pixel[line + x] = (byte) mix;
                                    w.setRGB(left+x,top+height,(byte) mix);
                                }
                                else{
                                    //pixel[line + x] = 0;
                                    w.setRGB(left+x,top+height,0);
                                }
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            mixmask <<= 1;
                            if (mixmask == 0) {
                                mask = (fom_mask != 0) ? (byte) fom_mask
                                        : compressed_pixel[input++];
                                mixmask = 1;
                            }
                            if ((mask & mixmask) != 0){
                                //pixel[line + x] = mix;
                                w.setRGB(left+x,top+height,mix);
                            }
                            else{
                                //pixel[line + x] = 0;
                                w.setRGB(left+x,top+height,0);
                            }
                            count--;
                            x++;
                        }
                    } else {
                        while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                            for (int i = 0; i < 8; i++) {
                                mixmask <<= 1;
                                if (mixmask == 0) {
                                    mask = (fom_mask != 0) ? (byte) fom_mask
                                            : compressed_pixel[input++];
                                    mixmask = 1;
                                }
                                if ((mask & mixmask) != 0){
                                    //pixel[line + x] = (pixel[previous + x] ^ mix);
                                    w.setRGB(left+x,top+height,w.getRGB(left+x,prevY+top) ^ mix);
                                } else{
                                    //pixel[line + x] = pixel[previous + x];
                                    w.setRGB(left+x,top+height,w.getRGB(left+x,prevY+top));
                                }
                                count--;
                                x++;
                            }
                        }
                        while ((count > 0) && (x < width)) {
                            mixmask <<= 1;
                            if (mixmask == 0) {
                                mask = (fom_mask != 0) ? (byte) fom_mask
                                        : compressed_pixel[input++];
                                mixmask = 1;
                            }
                            if ((mask & mixmask) != 0){
                                // pixel[line + x] = (pixel[previous + x] ^ mix);
                                w.setRGB(left+x,top+height,w.getRGB(left+x,prevY+top) ^ mix);
                            } else {
                                // pixel[line + x] = pixel[previous + x];
                                w.setRGB(left+x,top+height,w.getRGB(left+x,prevY+top));
                            }
                            count--;
                            x++;
                        }

                    }
                    break;

                case 3: /* Color */
                    while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                        for (int i = 0; i < 8; i++) {
                            // pixel[line + x] = color2;
                            w.setRGB(left+x,top+height,color2);
                            count--;
                            x++;
                        }
                    }
                    while ((count > 0) && (x < width)) {
                        // pixel[line + x] = color2;
                        w.setRGB(left+x,top+height,color2);
                        count--;
                        x++;
                    }

                    break;

                case 4: /* Copy */
                    while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                        for (int i = 0; i < 8; i++) {
                            // pixel[line + x] = cvalx(compressed_pixel, input, Bpp);
                            w.setRGB(left+x,top+height,cvalx(compressed_pixel, input, Bpp));
                            input += Bpp;
                            count--;
                            x++;
                        }
                    }
                    while ((count > 0) && (x < width)) {
                        // pixel[line + x] = cvalx(compressed_pixel, input, Bpp);
                        w.setRGB(left+x,top+height,cvalx(compressed_pixel, input, Bpp));
                        input += Bpp;
                        count--;
                        x++;
                    }
                    break;

                case 8: /* Bicolor */
                    while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                        for (int i = 0; i < 8; i++) {
                            if (bicolor) {
                                // pixel[line + x] = color2;
                                w.setRGB(left+x,top+height,color2);
                                bicolor = false;
                            } else {
                                // pixel[line + x] = color1;
                                w.setRGB(left+x,top+height,color1);
                                bicolor = true;
                                count++;
                            }
                            count--;
                            x++;
                        }
                    }
                    while ((count > 0) && (x < width)) {
                        if (bicolor) {
                            // pixel[line + x] = color2;
                            w.setRGB(left+x,top+height,color2);
                            bicolor = false;
                        } else {
                            // pixel[line + x] = color1;
                            w.setRGB(left+x,top+height,color1);
                            bicolor = true;
                            count++;
                        }
                        count--;
                        x++;
                    }

                    break;

                case 0xd: /* White */
                    while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                        for (int i = 0; i < 8; i++) {
                            // pixel[line + x] = 0xffffff;
                            w.setRGB(left+x,top+height,0xffffff);
                            count--;
                            x++;
                        }
                    }
                    while ((count > 0) && (x < width)) {
                        // pixel[line + x] = 0xffffff;
                        w.setRGB(left+x,top+height,0xffffff);
                        count--;
                        x++;
                    }
                    break;

                case 0xe: /* Black */
                    while (((count & ~0x7) != 0) && ((x + 8) < width)) {
                        for (int i = 0; i < 8; i++) {
                            // pixel[line + x] = 0x00;
                            w.setRGB(left+x,top+height,0x00);
                            count--;
                            x++;
                        }
                    }
                    while ((count > 0) && (x < width)) {
                        // pixel[line + x] = 0x00;
                        w.setRGB(left+x,top+height,0x00);
                        count--;
                        x++;
                    }

                    break;
                default:
                    throw new RdesktopException(
                            "Unimplemented decompress opcode " + opcode);// ;
                }
            }
        }

       /* if(Options.server_bpp == 16){
            for(int i = 0; i < pixel.length; i++) pixel[i] = Bitmap.convert16to24(pixel[i]);
        }*/
        
        return w;
    }
    
    /**
     * Decompress bitmap data from packet and output as an Image
     * @param width Width of bitmap
     * @param height Height of bitmap
     * @param size Size of compressed data in bytes
     * @param data Packet containing bitmap data
     * @param Bpp Bytes per-pixel for bitmap
     * @param cm Colour model for bitmap (if using indexed palette)
     * @return Decompressed bitmap as Image object
     * @throws RdesktopException
     */
    public static Image decompressImg(int width, int height, int size, RdpPacket_Localised data, int Bpp, IndexColorModel cm) throws RdesktopException {

        WrappedImage w = null;
        
        byte[] compressed_pixel = new byte[size];
        data.copyToByteArray(compressed_pixel, 0, data.getPosition(), size);
        data.incrementPosition(size);

        int previous = -1, line = 0, prevY = 0;
        int input = 0, end = size;
        int opcode = 0, count = 0, offset = 0, x = width;
        int lastopcode = -1, fom_mask = 0;
        int code = 0, color1 = 0, color2 = 0;
        byte mixmask = 0;
        int mask = 0;
        int mix = 0xffffffff;

        boolean insertmix = false, bicolor = false, isfillormix = false;

        if(cm == null)
            w = new WrappedImage(width, height, BufferedImage.TYPE_INT_RGB);
        else
            w = new WrappedImage(width, height, BufferedImage.TYPE_INT_RGB, cm);
        
        while (input < end) {
            fom_mask = 0;
            code = (compressed_pixel[input++] & 0x000000ff);
            opcode = code >> 4;

            /* Handle different opcode forms */
            switch (opcode) {
            case 0xc:
            case 0xd:
            case 0xe:
                opcode -= 6;
                count = code & 0xf;
                offset = 16;
                break;

            case 0xf:
                opcode = code & 0xf;
                if (opcode < 9) {
                    count = (compressed_pixel[input++] & 0xff);
                    count |= ((compressed_pixel[input++] & 0xff) << 8);
                } else {
                    count = (opcode < 0xb) ? 8 : 1;
                }
                offset = 0;
                break;

            default:
                opcode >>= 1;
                count = code & 0x1f;
                offset = 32;
                break;
            }

            /* Handle strange cases for counts */
            if (offset != 0) {
                isfillormix = ((opcode == 2) || (opcode == 7));

                if (count == 0) {
                    if (isfillormix)
                        count = (compressed_pixel[input++] & 0x000000ff) + 1;
                    else
                        count = (compressed_pixel[input++] & 0x000000ff)
                                + offset;
                } else if (isfillormix) {
                    count <<= 3;
                }
            }

            switch (opcode) {
            case 0: /* Fill */
                if ((lastopcode == opcode)
                        && !((x == width) && (previous == -1)))
                    insertmix = true;
                break;
            case 8: /* Bicolor */
                color1 = cvalx(compressed_pixel, input, Bpp);
                    //(compressed_pixel[input++]&0x000000ff);
                input += Bpp;

⌨️ 快捷键说明

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