All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.moaxcp.x11client.protocol.xproto.GetImage Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
package com.github.moaxcp.x11client.protocol.xproto;

import com.github.moaxcp.x11client.protocol.TwoWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.XReplyFunction;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Override;
import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class GetImage implements TwoWayRequest {
  public static final byte OPCODE = 73;

  private byte format;

  private int drawable;

  private short x;

  private short y;

  private short width;

  private short height;

  private int planeMask;

  public XReplyFunction getReplyFunction() {
    return (field, sequenceNumber, in) -> GetImageReply.readGetImageReply(field, sequenceNumber, in);
  }

  public byte getOpCode() {
    return OPCODE;
  }

  public static GetImage readGetImage(X11Input in) throws IOException {
    byte format = in.readCard8();
    short length = in.readCard16();
    int drawable = in.readCard32();
    short x = in.readInt16();
    short y = in.readInt16();
    short width = in.readCard16();
    short height = in.readCard16();
    int planeMask = in.readCard32();
    GetImage.GetImageBuilder javaBuilder = GetImage.builder();
    javaBuilder.format(format);
    javaBuilder.drawable(drawable);
    javaBuilder.x(x);
    javaBuilder.y(y);
    javaBuilder.width(width);
    javaBuilder.height(height);
    javaBuilder.planeMask(planeMask);
    return javaBuilder.build();
  }

  @Override
  public void write(byte offset, X11Output out) throws IOException {
    out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
    out.writeCard8(format);
    out.writeCard16((short) getLength());
    out.writeCard32(drawable);
    out.writeInt16(x);
    out.writeInt16(y);
    out.writeCard16(width);
    out.writeCard16(height);
    out.writeCard32(planeMask);
  }

  @Override
  public int getSize() {
    return 20;
  }

  public static class GetImageBuilder {
    public GetImage.GetImageBuilder format(ImageFormat format) {
      this.format = (byte) format.getValue();
      return this;
    }

    public GetImage.GetImageBuilder format(byte format) {
      this.format = format;
      return this;
    }

    public int getSize() {
      return 20;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy