// Path: xpra-common/src/main/java/xpra/compression/CompressionException.java
// public class CompressionException extends IOException {
// 
//     public CompressionException(String s) {
//         super(s);
//     }
// 
//     public CompressionException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// }
// 
// Path: xpra-common/src/main/java/xpra/compression/Decompressor.java
// public interface Decompressor {
// 
//     boolean decompress(byte[] inputData, byte[] outputData) throws CompressionException;
// }
// 
// Path: xpra-common/src/main/java/xpra/compression/Decompressors.java
// public class Decompressors {
// 
//     public static final String COMP_ZLIB = "zlib";
// 
//     public static Decompressor zlib() {
//         return new ZLib();
//     }
// 
//     public static Decompressor getByName(String compressionName) {
//         switch (compressionName) {
//             case COMP_ZLIB: return zlib();
//             default:
//                 throw new UnsupportedOperationException("Unsupported compressor used: " + compressionName);
//         }
//     }
// }
// 
// Path: xpra-common/src/main/java/xpra/protocol/PictureEncoding.java
// public enum PictureEncoding {
//     rgb24,
//     rgb32,
//     premult_argb32,
//     jpeg,
//     png,
//     pngP("png/P"),
//     pngL("png/L");
// 
//     private static final PictureEncoding[] values = values();
//     private final String code;
// 
//     PictureEncoding() {
//         code = name();
//     }
// 
//     PictureEncoding(String code) {
//         this.code = code;
//     }
// 
//     @Override
//     public String toString() {
//         return code;
//     }
// 
//     public static PictureEncoding decode(String code) {
//         for (PictureEncoding encoding : values) {
//             if (encoding.code.equals(code)) {
//                 return encoding;
//             }
//         }
//         throw new IllegalArgumentException("Unsupported picture encoding: " + code);
//     }
// 
//     public static String[] toString(PictureEncoding[] encodings) {
//         final String[] array = new String[encodings.length];
//         for (int i = 0; i < encodings.length; ++i) {
//             array[i] = encodings[i].toString();
//         }
//         return array;
//     }
// 
// }


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import xpra.compression.CompressionException;
import xpra.compression.Decompressor;
import xpra.compression.Decompressors;
import xpra.protocol.PictureEncoding;
/*
 * Copyright (C) 2020 Jakub Ksiezniak
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License along
 *     with this program; if not, write to the Free Software Foundation, Inc.,
 *     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package xpra.protocol.packets;



public class DrawPacket extends WindowPacket {

    public int x;
    public int y;
    public int w;
    public int h;
    public PictureEncoding encoding;
    public byte[] data;
    public int packet_sequence;
    public int rowstride;

    public Map<String, Object> options = new HashMap<>();

    public DrawPacket() {
        super("draw");
    }

    @Override
    public void deserialize(Iterator<Object> iter) {
        super.deserialize(iter);
        x = asInt(iter.next());
        y = asInt(iter.next());
        w = asInt(iter.next());
        h = asInt(iter.next());
        encoding = PictureEncoding.decode(asString(iter.next()));
        data = asByteArray(iter.next());
        packet_sequence = asInt(iter.next());
        rowstride = asInt(iter.next());
        if (iter.hasNext()) {
            options = asMap(iter.next());
        }
    }

    public byte[] readPixels() throws CompressionException {
// Path: xpra-common/src/main/java/xpra/compression/CompressionException.java
// public class CompressionException extends IOException {
// 
//     public CompressionException(String s) {
//         super(s);
//     }
// 
//     public CompressionException(String s, Throwable throwable) {
//         super(s, throwable);
//     }
// }
// 
// Path: xpra-common/src/main/java/xpra/compression/Decompressor.java
// public interface Decompressor {
// 
//     boolean decompress(byte[] inputData, byte[] outputData) throws CompressionException;
// }
// 
// Path: xpra-common/src/main/java/xpra/compression/Decompressors.java
// public class Decompressors {
// 
//     public static final String COMP_ZLIB = "zlib";
// 
//     public static Decompressor zlib() {
//         return new ZLib();
//     }
// 
//     public static Decompressor getByName(String compressionName) {
//         switch (compressionName) {
//             case COMP_ZLIB: return zlib();
//             default:
//                 throw new UnsupportedOperationException("Unsupported compressor used: " + compressionName);
//         }
//     }
// }
// 
// Path: xpra-common/src/main/java/xpra/protocol/PictureEncoding.java
// public enum PictureEncoding {
//     rgb24,
//     rgb32,
//     premult_argb32,
//     jpeg,
//     png,
//     pngP("png/P"),
//     pngL("png/L");
// 
//     private static final PictureEncoding[] values = values();
//     private final String code;
// 
//     PictureEncoding() {
//         code = name();
//     }
// 
//     PictureEncoding(String code) {
//         this.code = code;
//     }
// 
//     @Override
//     public String toString() {
//         return code;
//     }
// 
//     public static PictureEncoding decode(String code) {
//         for (PictureEncoding encoding : values) {
//             if (encoding.code.equals(code)) {
//                 return encoding;
//             }
//         }
//         throw new IllegalArgumentException("Unsupported picture encoding: " + code);
//     }
// 
//     public static String[] toString(PictureEncoding[] encodings) {
//         final String[] array = new String[encodings.length];
//         for (int i = 0; i < encodings.length; ++i) {
//             array[i] = encodings[i].toString();
//         }
//         return array;
//     }
// 
// }


// Path: xpra-common/src/main/java/xpra/protocol/packets/DrawPacket.java
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import xpra.compression.CompressionException;
import xpra.compression.Decompressor;
import xpra.compression.Decompressors;
import xpra.protocol.PictureEncoding;

/*
 * Copyright (C) 2020 Jakub Ksiezniak
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License along
 *     with this program; if not, write to the Free Software Foundation, Inc.,
 *     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package xpra.protocol.packets;



public class DrawPacket extends WindowPacket {

    public int x;
    public int y;
    public int w;
    public int h;
    public PictureEncoding encoding;
    public byte[] data;
    public int packet_sequence;
    public int rowstride;

    public Map<String, Object> options = new HashMap<>();

    public DrawPacket() {
        super("draw");
    }

    @Override
    public void deserialize(Iterator<Object> iter) {
        super.deserialize(iter);
        x = asInt(iter.next());
        y = asInt(iter.next());
        w = asInt(iter.next());
        h = asInt(iter.next());
        encoding = PictureEncoding.decode(asString(iter.next()));
        data = asByteArray(iter.next());
        packet_sequence = asInt(iter.next());
        rowstride = asInt(iter.next());
        if (iter.hasNext()) {
            options = asMap(iter.next());
        }
    }

    public byte[] readPixels() throws CompressionException {
        if (options.containsKey(Decompressors.COMP_ZLIB)) {