summaryrefslogtreecommitdiff
path: root/poppler/CairoOutputDevImage.cc
blob: ec66ff7ffc19e333d7c19daeff55ec0cecc54321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//========================================================================
//
// CairoOutputDevImage.cc
//
// Copyright 2003 Glyph & Cog, LLC
// Copyright 2004 Red Hat, Inc
//
//========================================================================

#include <config.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include <string.h>
#include <math.h>
#include <cairo.h>

#include "goo/gfile.h"
#include "GlobalParams.h"
#include "Error.h"
#include "Object.h"
#include <fofi/FoFiTrueType.h>
#include <splash/SplashBitmap.h>
#include "CairoOutputDevImage.h"

//------------------------------------------------------------------------
// CairoOutputDevImage
//------------------------------------------------------------------------

CairoOutputDevImage::CairoOutputDevImage(void) {
  pixels = NULL;
  createCairo (NULL);
}

CairoOutputDevImage::~CairoOutputDevImage() {
  gfree (pixels);
}

void
CairoOutputDevImage::createCairo(GfxState *state) {
  int w, h;

  w = state ? (int)(state->getPageWidth() + 0.5) : 1;
  h = state ? (int)(state->getPageHeight() + 0.5) : 1;

  if (!pixels || w != pixels_w || h != pixels_h) {
    if (pixels) {
      gfree(pixels);
    }
    pixels_w = w;
    pixels_h = h;
    pixels = (unsigned char *)gmalloc (pixels_w * pixels_h * 4);
  }

  memset (pixels, 0xff, pixels_w * pixels_h * 4);

  cairo = cairo_create ();
  cairo_set_target_image (cairo, (char *)pixels, CAIRO_FORMAT_ARGB32,
			  pixels_w, pixels_h,
			  pixels_w*4);
  
}


void CairoOutputDevImage::getBitmap(unsigned char **data,
				    int *width, int *height,
				    int *rowstride) {
  SplashBitmap *bitmap;
  int w, h;
  unsigned char *src;
  unsigned int *dest;

  *data = pixels;
  *width = pixels_w;
  *height = pixels_h;
  *rowstride = 4 * pixels_w;
}