summaryrefslogtreecommitdiff
path: root/src/gutenprintui2/print-image-thumbnail.c
blob: 51fd136dfb22514502836de8503622006dc87749 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * "$Id: print-image-thumbnail.c,v 1.1 2004/09/17 18:38:14 rleigh Exp $"
 *
 *   Print plug-in for the GIMP.
 *
 *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
 *	Robert Krawitz (rlk@alum.mit.edu)
 *   Copyright 2000 Charles Briscoe-Smith <cpbs@debian.org>
 *
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 2 of the License, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *   for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <string.h>

#include <gutenprintui2/gutenprintui.h>
#include "gutenprintui-internal.h"

/* Concrete type to represent image */
typedef struct
{
  const guchar *data;
  gint w, h, bpp;
  gint32 real_bpp;
} thumbnail_image_t;

static const char *Thumbnail_get_appname(stp_image_t *image);
static void Thumbnail_conclude(stp_image_t *image);
static stp_image_status_t Thumbnail_get_row(stp_image_t *image,
					    unsigned char *data,
					    size_t byte_limit, int row);
static int Thumbnail_height(stp_image_t *image);
static int Thumbnail_width(stp_image_t *image);
static void Thumbnail_reset(stp_image_t *image);
static void Thumbnail_init(stp_image_t *image);

static stp_image_t theImage =
{
  Thumbnail_init,
  Thumbnail_reset,
  Thumbnail_width,
  Thumbnail_height,
  Thumbnail_get_row,
  Thumbnail_get_appname,
  Thumbnail_conclude,
  NULL
};

stp_image_t *
stpui_image_thumbnail_new(const guchar *data, gint w, gint h, gint bpp)
{
  thumbnail_image_t *im;
  if (! theImage.rep)
    theImage.rep = stp_malloc(sizeof(thumbnail_image_t));
  im = (thumbnail_image_t *) (theImage.rep);
  memset(im, 0, sizeof(thumbnail_image_t));
  im->data = data;
  im->w = w;
  im->h = h;
  im->bpp = bpp;

  theImage.reset(&theImage);
  return &theImage;
}

static int
Thumbnail_width(stp_image_t *image)
{
  thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
  return im->w;
}

static int
Thumbnail_height(stp_image_t *image)
{
  thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
  return im->h;
}

static stp_image_status_t
Thumbnail_get_row(stp_image_t *image, unsigned char *data,
		  size_t byte_limit, int row)
{
  thumbnail_image_t *im = (thumbnail_image_t *) (image->rep);
  const guchar *where = im->data + (row * im->w * im->bpp);
  memcpy(data, where, im->w * im->bpp);
  return STP_IMAGE_STATUS_OK;
}

static void
Thumbnail_init(stp_image_t *image)
{
  /* Nothing to do. */
}

static void
Thumbnail_reset(stp_image_t *image)
{
}

static void
Thumbnail_conclude(stp_image_t *image)
{
}

static const char *
Thumbnail_get_appname(stp_image_t *image)
{
  static char pluginname[] = "Thumbnail V" VERSION " - " RELEASE_DATE;
  return pluginname;
}

/*
 * End of "$Id: print-image-thumbnail.c,v 1.1 2004/09/17 18:38:14 rleigh Exp $".
 */