public boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
      throws Exception {
    DecoderState state = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
    if (state == null) {
      state = new DecoderState();
      session.setAttribute(DECODER_STATE_KEY, state);
    }

    if (state.image1 == null) {
      if (in.prefixedDataAvailable(4, MAX_IMAGE_SIZE)) {
        state.image1 = readImage(in);
      } else {
        return false;
      }
    }

    if (state.image1 != null) {
      if (in.prefixedDataAvailable(4, MAX_IMAGE_SIZE)) {
        BufferedImage image = readImage(in);
        ImageResponse response = new ImageResponse(state.image1, image);
        out.write(response);
        state.image1 = null;
        return true;
      } else {
        return false;
      }
    }
    return false;
  }