Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
imgbuf.cc
Go to the documentation of this file.
1/*
2 * File: imgbuf.cc
3 *
4 * Copyright (C) 2008 Jorge Arellano Cid <jcid@dillo.org>,
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
12#include "msg.h"
13#include "imgbuf.hh"
14#include "dw/core.hh"
15#include "dw/image.hh"
16
17using namespace dw::core;
18
19/*
20 * Local data
21 */
22static size_t linebuf_size = 0;
23static uchar_t *linebuf = NULL;
24
25
26/*
27 * Decode 'buf' (an image line) into RGB format.
28 */
29static uchar_t *Imgbuf_rgb_line(const uchar_t *buf,
30 DilloImgType type, uchar_t *cmap,
31 uint_t width, uint_t y)
32{
33 uint_t x;
34
35 switch (type) {
37 if (cmap) {
38 for (x = 0; x < width; x++)
39 memcpy(linebuf + x * 3, cmap + buf[x] * 3, 3);
40 } else {
41 MSG_WARN("Gif:: image lacks a color map\n");
42 }
43 break;
45 for (x = 0; x < width; x++)
46 memset(linebuf + x * 3, buf[x], 3);
47 break;
49 /*
50 * We treat CMYK as if it were "RGBW", and it works. Everyone who is
51 * trying to handle CMYK jpegs is confused by this, and supposedly
52 * the issue is that Adobe CMYK is "wrong" but ubiquitous.
53 */
54 for (x = 0; x < width; x++) {
55 uint_t white = buf[x * 4 + 3];
56 linebuf[x * 3] = buf[x * 4] * white / 0x100;
57 linebuf[x * 3 + 1] = buf[x * 4 + 1] * white / 0x100;
58 linebuf[x * 3 + 2] = buf[x * 4 + 2] * white / 0x100;
59 }
60 break;
62 /* avoid a memcpy here! --Jcid */
63 return (uchar_t *)buf;
65 MSG_ERR("Imgbuf_rgb_line: type not set...\n");
66 break;
67 }
68 return linebuf;
69}
70
71// Wrappers for Imgbuf -------------------------------------------------------
72
76void a_Imgbuf_ref(void *v_imgbuf)
77{
78 ((Imgbuf*)v_imgbuf)->ref();
79}
80
84void a_Imgbuf_unref(void *v_imgbuf)
85{
86 if (v_imgbuf)
87 ((Imgbuf*)v_imgbuf)->unref();
88}
89
93void *a_Imgbuf_new(void *layout, int img_type, uint_t width, uint_t height,
94 double gamma)
95{
96 if (!layout) {
97 MSG_ERR("a_Imgbuf_new: layout is NULL.\n");
98 exit(1);
99 }
100 // Assert linebuf is wide enough.
101 if (3 * width > linebuf_size) {
102 linebuf_size = 3 * width;
104 }
105
106 return (void*)((Layout*)layout)->createImgbuf(Imgbuf::RGB, width, height,
107 gamma);
108}
109
113int a_Imgbuf_last_reference(void *v_imgbuf)
114{
115 return ((Imgbuf*)v_imgbuf)->lastReference () ? 1 : 0;
116}
117
121void a_Imgbuf_update(void *v_imgbuf, const uchar_t *buf, DilloImgType type,
122 uchar_t *cmap, uint_t width, uint_t height, uint_t y)
123
124{
125 dReturn_if_fail ( y < height );
126
127 /* Decode 'buf' and copy it into the imgbuf */
128 uchar_t *newbuf = Imgbuf_rgb_line(buf, type, cmap, width, y);
129 ((Imgbuf*)v_imgbuf)->copyRow(y, (byte *)newbuf);
130}
131
135void a_Imgbuf_new_scan(void *v_imgbuf)
136{
137 ((Imgbuf*)v_imgbuf)->newScan();
138}
139
The platform independent interface for image buffers.
Definition imgbuf.hh:162
The central class for managing and drawing a widget tree.
Definition layout.hh:17
unsigned char uchar_t
Definition d_size.h:17
unsigned int uint_t
Definition d_size.h:20
void * dRealloc(void *mem, size_t size)
Definition dlib.c:53
#define dReturn_if_fail(expr)
Definition dlib.h:72
#define MSG_ERR(...)
Definition dpid_common.h:23
static Layout * layout
static size_t linebuf_size
Definition imgbuf.cc:22
void * a_Imgbuf_new(void *layout, int img_type, uint_t width, uint_t height, double gamma)
Create a new Imgbuf.
Definition imgbuf.cc:93
static uchar_t * linebuf
Definition imgbuf.cc:23
void a_Imgbuf_ref(void *v_imgbuf)
Increment reference count for an Imgbuf.
Definition imgbuf.cc:76
static uchar_t * Imgbuf_rgb_line(const uchar_t *buf, DilloImgType type, uchar_t *cmap, uint_t width, uint_t y)
Definition imgbuf.cc:29
void a_Imgbuf_update(void *v_imgbuf, const uchar_t *buf, DilloImgType type, uchar_t *cmap, uint_t width, uint_t height, uint_t y)
Update the root buffer of an imgbuf.
Definition imgbuf.cc:121
int a_Imgbuf_last_reference(void *v_imgbuf)
Last reference for this Imgbuf?
Definition imgbuf.cc:113
void a_Imgbuf_unref(void *v_imgbuf)
Decrement reference count for an Imgbuf.
Definition imgbuf.cc:84
void a_Imgbuf_new_scan(void *v_imgbuf)
Reset for a new scan from a multiple-scan image.
Definition imgbuf.cc:135
#define MSG_WARN(...)
Definition msg.h:26
The core of Dw is defined in this namespace.
Definition core.hh:23
DilloImgType
Definition image.hh:42
@ DILLO_IMG_TYPE_GRAY
Definition image.hh:45
@ DILLO_IMG_TYPE_CMYK_INV
Definition image.hh:46
@ DILLO_IMG_TYPE_RGB
Definition image.hh:44
@ DILLO_IMG_TYPE_INDEXED
Definition image.hh:43
@ DILLO_IMG_TYPE_NOTSET
Definition image.hh:47