#include <windows.h>
#include <cairo-win32.h>

#define DROPPER_WIDTH 17
#define DROPPER_HEIGHT 17
#define DROPPER_STRIDE 4

static const unsigned char dropper_bits[] = {
  0xff, 0x8f, 0x01, 0x00,  0xff, 0x77, 0x01, 0x00,
  0xff, 0xfb, 0x00, 0x00,  0xff, 0xf8, 0x00, 0x00,
  0x7f, 0xff, 0x00, 0x00,  0xff, 0x7e, 0x01, 0x00,
  0xff, 0x9d, 0x01, 0x00,  0xff, 0xd8, 0x01, 0x00,
  0x7f, 0xd4, 0x01, 0x00,  0x3f, 0xee, 0x01, 0x00,
  0x1f, 0xff, 0x01, 0x00,  0x8f, 0xff, 0x01, 0x00,
  0xc7, 0xff, 0x01, 0x00,  0xe3, 0xff, 0x01, 0x00,
  0xf3, 0xff, 0x01, 0x00,  0xfd, 0xff, 0x01, 0x00,
  0xff, 0xff, 0x01, 0x00 };

unsigned char *bits;

HBITMAP
bitmap_new (int width,
	    int height)
{
  BITMAPINFO bmi;
  HDC hdc;
  HWND hwnd;
  HBITMAP hbitmap;

  bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
  bmi.bmiHeader.biWidth = width;
  bmi.bmiHeader.biHeight = -height;
  bmi.bmiHeader.biPlanes = 1;
  bmi.bmiHeader.biBitCount = 1;
  bmi.bmiHeader.biCompression = BI_RGB;
  bmi.bmiHeader.biSizeImage = 0;
  bmi.bmiHeader.biXPelsPerMeter =
    bmi.bmiHeader.biYPelsPerMeter = 0;
  bmi.bmiHeader.biClrUsed = 0;
  bmi.bmiHeader.biClrImportant = 0;

  bmi.bmiColors[0].rgbBlue =
    bmi.bmiColors[0].rgbGreen =
    bmi.bmiColors[0].rgbRed = 0x00;
  bmi.bmiColors[0].rgbReserved = 0x00;

  bmi.bmiColors[1].rgbBlue =
    bmi.bmiColors[1].rgbGreen =
    bmi.bmiColors[1].rgbRed = 0xFF;
  bmi.bmiColors[1].rgbReserved = 0x00;

  hwnd = GetDesktopWindow ();
  hdc = GetDC (hwnd);
  hbitmap = CreateDIBSection (hdc, (BITMAPINFO *) &bmi,
			      DIB_RGB_COLORS, (PVOID *) &bits, NULL, 0);
  ReleaseDC (hwnd, hdc);

  return hbitmap;
}

int
main(int argc, char* argv[])
{
  HBITMAP bitmap;
  cairo_surface_t *image, *dest;
  cairo_t *cr;

  bitmap = bitmap_new (DROPPER_WIDTH, DROPPER_HEIGHT);

  if (1)
    {
      HDC hdc = CreateCompatibleDC (NULL);
      SelectObject (hdc, bitmap);
      dest = cairo_win32_surface_create (hdc);
      cr = cairo_create (dest);
    }
  else
    {
      dest = cairo_image_surface_create (CAIRO_FORMAT_A1,
					 DROPPER_WIDTH,
					 DROPPER_HEIGHT);
      cr = cairo_create (dest);

    }

  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  image = cairo_image_surface_create_for_data ((unsigned char *) dropper_bits,
					       CAIRO_FORMAT_A1,
					       DROPPER_WIDTH,
					       DROPPER_HEIGHT,
					       DROPPER_STRIDE);
  cairo_set_source_surface (cr, image, 0, 0);
  cairo_paint (cr);
  cairo_surface_write_to_png (dest, "test.png");

  cairo_surface_destroy (image);
  cairo_destroy (cr);
	
  return 0;
}
