Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
image.cc
Go to the documentation of this file.
1/*
2 * File: image.cc
3 *
4 * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org>,
5 * Sebastian Geerken <sgeerken@dillo.org>
6 * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 */
13
14/* @file
15 * Implements image data transfer methods. It handles the transfer
16 * of data from an Image to a DwImage widget.
17 */
18
19#include "msg.h"
20
21#include "image.hh"
22#include "dw/core.hh"
23#include "dw/image.hh"
24
25using namespace dw::core;
26
28#define I2IR(Image) ((dw::core::ImgRenderer*)(Image->img_rndr))
29
30
34DilloImage *a_Image_new(void *layout, void *img_rndr,
35 int32_t bg_color, int32_t fg_color)
36{
38
39 Image = dNew(DilloImage, 1);
41 Image->img_rndr = img_rndr;
42 Image->width = 0;
43 Image->height = 0;
44 Image->dpi = ((Layout *) layout)->dpiX();
45 Image->bg_color = bg_color;
46 Image->fg_color = fg_color;
47 Image->ScanNumber = 0;
48 Image->BitVec = NULL;
49 Image->State = IMG_Empty;
50
51 Image->RefCount = 0;
52
53 return Image;
54}
55
59DilloImage *a_Image_new_with_dw(void *layout, const char *alt_text,
60 int32_t bg_color, int32_t fg_color)
61{
62 dw::Image *dw = new dw::Image(alt_text);
63 return a_Image_new(layout, (void*)(dw::core::ImgRenderer*)dw, bg_color, fg_color);
64}
65
73{
74 return (dw::Image*)(dw::core::ImgRenderer*)Image->img_rndr;
75}
80{
81 a_Bitvec_free(Image->BitVec);
82 dFree(Image);
83}
84
90{
91 _MSG(" %d ", Image->RefCount);
92 if (Image && --Image->RefCount == 0)
94}
95
101{
102 if (Image)
103 ++Image->RefCount;
104}
105
109void a_Image_set_parms(DilloImage *Image, void *v_imgbuf, DilloUrl *url,
110 int version, uint_t width, uint_t height,
111 DilloImgType type)
112{
113 _MSG("a_Image_set_parms: width=%d height=%d iw=%d ih=%d\n",
114 width, height, Image->width, Image->height);
115
116 /* Resize from 0,0 to width,height */
117 bool resize = true;
118 I2IR(Image)->setBuffer((Imgbuf*)v_imgbuf, resize);
119
120 if (!Image->BitVec)
121 Image->BitVec = a_Bitvec_new(height);
122 Image->width = width;
123 Image->height = height;
124 Image->State = IMG_SetParms;
125}
126
131{
132 _MSG("a_Image_write\n");
133 dReturn_if_fail ( y < Image->height );
134
135 /* Update the row in DwImage */
136 I2IR(Image)->drawRow(y);
137 a_Bitvec_set_bit(Image->BitVec, y);
138 Image->State = IMG_Write;
139}
140
145{
146 _MSG("a_Image_close\n");
147 I2IR(Image)->finish();
148}
149
154{
155 _MSG("a_Image_abort\n");
156 I2IR(Image)->fatal();
157}
158
bitvec_t * a_Bitvec_new(int num_bits)
Create a new bitvec with 'num_bits' size.
Definition bitvec.c:23
void a_Bitvec_set_bit(bitvec_t *bvec, int pos)
Set a bit.
Definition bitvec.c:63
void a_Bitvec_free(bitvec_t *bvec)
Free a bitvec.
Definition bitvec.c:43
#define _MSG(...)
Definition bookmarks.c:45
Displays an instance of dw::core::Imgbuf.
Definition image.hh:120
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
Layout * layout
Definition widget.hh:209
unsigned int uint_t
Definition d_size.h:20
void dFree(void *mem)
Definition dlib.c:68
#define dReturn_if_fail(expr)
Definition dlib.h:72
#define dNew(type, count)
Definition dlib.h:49
static Layout * layout
The core of Dw is defined in this namespace.
Definition core.hh:23
Dw is in this namespace, or sub namespaces of this one.
#define I2IR(Image)
Image to Object-ImgRenderer macro.
Definition image.cc:28
void a_Image_ref(DilloImage *Image)
Add a reference to an Image struct Do nothing if the argument is NULL.
Definition image.cc:100
void a_Image_unref(DilloImage *Image)
Unref and free if necessary Do nothing if the argument is NULL.
Definition image.cc:89
DilloImage * a_Image_new_with_dw(void *layout, const char *alt_text, int32_t bg_color, int32_t fg_color)
Create and initialize a new image structure with an image widget.
Definition image.cc:59
void * a_Image_get_dw(DilloImage *Image)
Return the image renderer as a widget.
Definition image.cc:72
static void Image_free(DilloImage *Image)
Deallocate an Image structure.
Definition image.cc:79
void a_Image_abort(DilloImage *Image)
Implement the abort method.
Definition image.cc:153
void a_Image_write(DilloImage *Image, uint_t y)
Implement the write method.
Definition image.cc:130
DilloImage * a_Image_new(void *layout, void *img_rndr, int32_t bg_color, int32_t fg_color)
Create and initialize a new image structure.
Definition image.cc:34
void a_Image_close(DilloImage *Image)
Implement the close method.
Definition image.cc:144
void a_Image_set_parms(DilloImage *Image, void *v_imgbuf, DilloUrl *url, int version, uint_t width, uint_t height, DilloImgType type)
Set initial parameters of the image.
Definition image.cc:109
The DilloImage data-structure and methods.
DilloImgType
Definition image.hh:42
@ IMG_Write
Feeding the entry.
Definition image.hh:55
@ IMG_SetParms
Parameters set.
Definition image.hh:53
@ IMG_Empty
Just created the entry.
Definition image.hh:52
Definition url.h:88