Dillo v3.2.0-143-gabad1053
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#include "prefs.h"
25
26using namespace dw::core;
27
29#define I2IR(Image) ((dw::core::ImgRenderer*)(Image->img_rndr))
30
31
35DilloImage *a_Image_new(void *layout, void *img_rndr,
36 int32_t bg_color, int32_t fg_color)
37{
39
40 Image = dNew(DilloImage, 1);
42 Image->img_rndr = img_rndr;
43 Image->width = 0;
44 Image->height = 0;
45 Image->dpi = ((Layout *) layout)->dpiX();
46 Image->bg_color = bg_color;
47 Image->fg_color = fg_color;
48 Image->ScanNumber = 0;
49 Image->BitVec = NULL;
50 Image->State = IMG_Empty;
51
52 Image->RefCount = 0;
53
54 return Image;
55}
56
60DilloImage *a_Image_new_with_dw(void *layout, const char *alt_text,
61 int32_t bg_color, int32_t fg_color)
62{
64 return a_Image_new(layout, (void*)(dw::core::ImgRenderer*)dw, bg_color, fg_color);
65}
66
74{
75 return (dw::Image*)(dw::core::ImgRenderer*)Image->img_rndr;
76}
81{
82 a_Bitvec_free(Image->BitVec);
83 dFree(Image);
84}
85
91{
92 _MSG(" %d ", Image->RefCount);
93 if (Image && --Image->RefCount == 0)
95}
96
102{
103 if (Image)
104 ++Image->RefCount;
105}
106
110void a_Image_set_parms(DilloImage *Image, void *v_imgbuf, DilloUrl *url,
111 int version, uint_t width, uint_t height,
112 DilloImgType type)
113{
114 _MSG("a_Image_set_parms: width=%d height=%d iw=%d ih=%d\n",
115 width, height, Image->width, Image->height);
116
117 /* Resize from 0,0 to width,height */
118 bool resize = true;
119 I2IR(Image)->setBuffer((Imgbuf*)v_imgbuf, resize);
120
121 if (!Image->BitVec)
122 Image->BitVec = a_Bitvec_new(height);
123 Image->width = width;
124 Image->height = height;
125 Image->State = IMG_SetParms;
126}
127
132{
133 _MSG("a_Image_write\n");
134 dReturn_if_fail ( y < Image->height );
135
136 /* Update the row in DwImage */
137 I2IR(Image)->drawRow(y);
138 a_Bitvec_set_bit(Image->BitVec, y);
139 Image->State = IMG_Write;
140}
141
146{
147 _MSG("a_Image_close\n");
148 I2IR(Image)->finish();
149}
150
155{
156 _MSG("a_Image_abort\n");
157 I2IR(Image)->fatal();
158}
159
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:140
The platform independent interface for image buffers.
Definition imgbuf.hh:162
The central class for managing and drawing a widget tree.
Definition layout.hh:37
Layout * layout
Definition widget.hh:216
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:90
#define dNew(type, count)
Definition dlib.h:67
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.
DilloPrefs prefs
Global Data.
Definition prefs.c:33
#define I2IR(Image)
Image to Object-ImgRenderer macro.
Definition image.cc:29
void a_Image_ref(DilloImage *Image)
Add a reference to an Image struct Do nothing if the argument is NULL.
Definition image.cc:101
void a_Image_unref(DilloImage *Image)
Unref and free if necessary Do nothing if the argument is NULL.
Definition image.cc:90
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:60
void * a_Image_get_dw(DilloImage *Image)
Return the image renderer as a widget.
Definition image.cc:73
static void Image_free(DilloImage *Image)
Deallocate an Image structure.
Definition image.cc:80
void a_Image_abort(DilloImage *Image)
Implement the abort method.
Definition image.cc:154
void a_Image_write(DilloImage *Image, uint_t y)
Implement the write method.
Definition image.cc:131
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:35
void a_Image_close(DilloImage *Image)
Implement the close method.
Definition image.cc:145
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:110
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
bool_t mark_unloaded_images
Definition prefs.h:101
Definition url.h:88