<%pre>

#include <setup.h>

using namespace vdrlive;

</%pre>
<%args>
int quality = 80;
int width = 729;
int height = 480;
</%args>
<%session scope="global">
bool logged_in(false);
</%session>
<%cpp>
  if (!logged_in && LiveSetup().UseAuth()) {
    cToSvConcat targetUrl = "/login.html?redirect=";
    targetUrl.appendUrlEscaped(request.getQuery());
    return reply.redirect(targetUrl.data());
  }
  reply.setContentType("image/jpg");

  cDevice* device = cDevice::PrimaryDevice();
  if (device) {
    int size = 0;
    uchar* image = device->GrabImage(size, true, quality, width, height);
    if (image) {
      reply.out().write(reinterpret_cast<const char*>(image), size);
      free(image);
    }
  }
</%cpp>
