Dillo v3.2.0-88-g47ab7c70
Loading...
Searching...
No Matches
dicache.c
Go to the documentation of this file.
1/*
2 * File: dicache.c
3 *
4 * Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
19#include <string.h> /* for memset */
20#include <stdlib.h>
21
22#include "msg.h"
23#include "image.hh"
24#include "imgbuf.hh"
25#include "web.hh"
26#include "dicache.h"
27#include "dpng.h"
28#include "dwebp.h"
29#include "dgif.h"
30#include "djpeg.h"
31#include "dsvg.h"
32
33enum {
40};
41
42static const char *format_name[DIC_MAX] = {
43 [DIC_Gif] = "gif",
44 [DIC_Png] = "png",
45 [DIC_Webp] = "webp",
46 [DIC_Jpeg] = "jpeg",
47 [DIC_Svg] = "svg"
48};
49
50static int disabled_formats[DIC_MAX] = { 0 };
51
56static Dlist *CachedIMGs = NULL;
57
58static uint_t dicache_size_total; /* invariant: dicache_size_total is
59 * the sum of the image sizes (3*w*h)
60 * of all the images in the dicache. */
61
65static int Dicache_entry_cmp(const void *v1, const void *v2)
66{
67 const DICacheEntry *e1 = v1, *e2 = v2;
68
69 int st = a_Url_cmp(e1->url, e2->url);
70 if (st == 0) {
71 if (e2->version == DIC_Last)
72 st = (e1->Flags & DIF_Last ? 0 : -1);
73 else
74 st = (e1->version - e2->version);
75 }
76 return st;
77}
78
83{
84 CachedIMGs = dList_new(256);
86
88 for (int i = 0; i < DIC_MAX; i++) {
90 disabled_formats[i] = 1;
91 _MSG("Image format %s disabled\n", format_name[i]);
92 }
93 }
94 }
95}
96
101{
102 DICacheEntry *entry = dNew(DICacheEntry, 1);
103
104 entry->width = 0;
105 entry->height = 0;
106 entry->Flags = DIF_Valid;
107 entry->SurvCleanup = 0;
109 entry->cmap = NULL;
110 entry->v_imgbuf = NULL;
111 entry->RefCount = 1;
112 entry->TotalSize = 0;
113 entry->ScanNumber = 0;
114 entry->BitVec = NULL;
115 entry->State = DIC_Empty;
116 entry->version = 1;
117
118 entry->Decoder = NULL;
119 entry->DecoderData = NULL;
120 entry->DecodedSize = 0;
121
122 return entry;
123}
124
130{
131 DICacheEntry e, *entry, *last;
132
133 entry = Dicache_entry_new();
134 e.url = (DilloUrl*)Url;
135 e.version = DIC_Last;
137 if (last) {
138 /* URL is already in CachedIMGs, make a new version */
139 last->Flags &= ~DIF_Last;
140 entry->version = last->version + 1;
141 }
142 entry->url = a_Url_dup(Url);
143 entry->Flags |= DIF_Last;
145
146 return entry;
147}
148
157{
158 DICacheEntry e;
159 DICacheEntry *entry = NULL;
160
161 dReturn_val_if_fail(version != 0, NULL);
162 e.url = (DilloUrl*)Url;
163 e.version = version;
165 if (entry && !(entry->Flags & DIF_Valid) && version == DIC_Last)
166 entry = NULL;
167 return entry;
168}
169
173static void Dicache_remove(const DilloUrl *Url, int version)
174{
175 DICacheEntry e, *entry;
176
177 _MSG("Dicache_remove url=%s\n", URL_STR(Url));
178 e.url = (DilloUrl*)Url;
179 e.version = version;
181 dReturn_if (entry == NULL);
182
183 _MSG("Dicache_remove Imgbuf=%p Decoder=%p DecoderData=%p\n",
184 entry->v_imgbuf, entry->Decoder, entry->DecoderData);
185 /* Eliminate this dicache entry */
186 dList_remove(CachedIMGs, entry);
188
189 /* entry cleanup */
190 a_Url_free(entry->url);
191 dFree(entry->cmap);
192 a_Bitvec_free(entry->BitVec);
193 a_Imgbuf_unref(entry->v_imgbuf);
194 if (entry->Decoder) {
195 entry->Decoder(CA_Abort, entry->DecoderData);
196 }
197 dFree(entry);
198}
199
201{
202 if (entry->v_imgbuf)
203 return a_Imgbuf_last_reference(entry->v_imgbuf);
204
205 return 0;
206}
207
214void a_Dicache_unref(const DilloUrl *Url, int version)
215{
216 DICacheEntry *entry;
217
218 if ((entry = a_Dicache_get_entry(Url, version))) {
219 _MSG("a_Dicache_unref: RefCount=%d State=%d ImgbufLastRef=%d\n",
220 entry->RefCount, entry->State,
221 entry->v_imgbuf ? a_Imgbuf_last_reference(entry->v_imgbuf) : -1);
222 if (entry->RefCount > 0) --entry->RefCount;
223 if (entry->RefCount == 0 && entry->v_imgbuf == NULL)
224 Dicache_remove(Url, version);
225 }
226}
227
231DICacheEntry* a_Dicache_ref(const DilloUrl *Url, int version)
232{
233 DICacheEntry *entry;
234
235 if ((entry = a_Dicache_get_entry(Url, version))) {
236 ++entry->RefCount;
237 }
238 return entry;
239}
240
247{
249 if (entry)
250 entry->Flags &= ~DIF_Valid;
251}
252
253
254/* ------------------------------------------------------------------------- */
255
262void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
263 uint_t width, uint_t height, DilloImgType type,
264 double gamma)
265{
266 DICacheEntry *DicEntry;
267
268 _MSG("a_Dicache_set_parms (%s)\n", URL_STR(url));
269 dReturn_if_fail ( Image != NULL && width && height );
270 /* Find the DicEntry for this Image */
271 DicEntry = a_Dicache_get_entry(url, version);
272 dReturn_if_fail ( DicEntry != NULL );
273 /* Parameters already set? Don't do it twice. */
274 dReturn_if_fail ( DicEntry->State < DIC_SetParms );
275
276 _MSG(" RefCount=%d version=%d\n", DicEntry->RefCount, DicEntry->version);
277
278 /* BUG: there's just one image-type now */
279 #define I_RGB 0
280 DicEntry->v_imgbuf =
281 a_Imgbuf_new(Image->layout, I_RGB, width, height, gamma);
282
283 DicEntry->TotalSize = width * height * 3;
284 DicEntry->width = width;
285 DicEntry->height = height;
286 DicEntry->type = type;
287 DicEntry->BitVec = a_Bitvec_new((int)height);
288 DicEntry->State = DIC_SetParms;
289
290 dicache_size_total += DicEntry->TotalSize;
291}
292
296void a_Dicache_set_cmap(DilloUrl *url, int version, int bg_color,
297 const uchar_t *cmap, uint_t num_colors,
298 int num_colors_max, int bg_index)
299{
300 DICacheEntry *DicEntry = a_Dicache_get_entry(url, version);
301
302 _MSG("a_Dicache_set_cmap\n");
303 dReturn_if_fail ( DicEntry != NULL );
304
305 dFree(DicEntry->cmap);
306 DicEntry->cmap = dNew0(uchar_t, 3 * num_colors_max);
307 memcpy(DicEntry->cmap, cmap, 3 * num_colors);
308 if (bg_index >= 0 && (uint_t)bg_index < num_colors) {
309 DicEntry->cmap[bg_index * 3] = (bg_color >> 16) & 0xff;
310 DicEntry->cmap[bg_index * 3 + 1] = (bg_color >> 8) & 0xff;
311 DicEntry->cmap[bg_index * 3 + 2] = (bg_color) & 0xff;
312 }
313
314 DicEntry->State = DIC_SetCmap;
315}
316
320void a_Dicache_new_scan(const DilloUrl *url, int version)
321{
322 DICacheEntry *DicEntry;
323
324 _MSG("a_Dicache_new_scan\n");
325 dReturn_if_fail ( url != NULL );
326 DicEntry = a_Dicache_get_entry(url, version);
327 dReturn_if_fail ( DicEntry != NULL );
328 if (DicEntry->State < DIC_SetParms) {
329 MSG("a_Dicache_new_scan before DIC_SetParms\n");
330 exit(1);
331 }
332 a_Bitvec_clear(DicEntry->BitVec);
333 DicEntry->ScanNumber++;
334 a_Imgbuf_new_scan(DicEntry->v_imgbuf);
335}
336
343void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
344{
345 DICacheEntry *DicEntry;
346
347 _MSG("a_Dicache_write\n");
348 DicEntry = a_Dicache_get_entry(url, version);
349 dReturn_if_fail ( DicEntry != NULL );
350 dReturn_if_fail ( DicEntry->width > 0 && DicEntry->height > 0 );
351
352 /* update the common buffer in the imgbuf */
353 a_Imgbuf_update(DicEntry->v_imgbuf, buf, DicEntry->type,
354 DicEntry->cmap, DicEntry->width, DicEntry->height, Y);
355
356 a_Bitvec_set_bit(DicEntry->BitVec, (int)Y);
357 DicEntry->State = DIC_Write;
358}
359
363void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
364{
365 DilloWeb *Web = Client->Web;
366 DICacheEntry *DicEntry = a_Dicache_get_entry(url, version);
367
368 dReturn_if_fail ( DicEntry != NULL );
369
370 /* a_Dicache_unref() may free DicEntry */
371 _MSG("a_Dicache_close RefCount=%d\n", DicEntry->RefCount - 1);
372 _MSG("a_Dicache_close DIC_Close=%d State=%d\n", DIC_Close, DicEntry->State);
373 _MSG(" a_Dicache_close imgbuf=%p Decoder=%p DecoderData=%p\n",
374 DicEntry->v_imgbuf, DicEntry->Decoder, DicEntry->DecoderData);
375
376 if (DicEntry->State < DIC_Close) {
377 DicEntry->State = DIC_Close;
378 dFree(DicEntry->cmap);
379 DicEntry->cmap = NULL;
380 DicEntry->Decoder = NULL;
381 DicEntry->DecoderData = NULL;
382 }
383 a_Dicache_unref(url, version);
384
385 a_Bw_close_client(Web->bw, Client->Key);
386}
387
388/* ------------------------------------------------------------------------- */
389
400static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
401 CA_Callback_t *Call, void **Data)
402{
403 DilloWeb *web = Ptr;
404 DICacheEntry *DicEntry;
405
406 dReturn_val_if_fail(MimeType && Ptr, NULL);
407
408 if (ImgType >= 0 && ImgType < DIC_MAX && disabled_formats[ImgType]) {
409 _MSG("Ignoring image format %s\n", format_name[ImgType]);
410 return NULL;
411 }
412
413 if (!web->Image) {
414 web->Image =
415 a_Image_new_with_dw(web->bw->render_layout, NULL, web->bgColor, 0);
416 a_Image_ref(web->Image);
417 }
418
419 DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
420 if (!DicEntry) {
421 /* Create an entry for this image... */
422 DicEntry = Dicache_add_entry(web->url);
423 /* Attach a decoder */
424 if (ImgType == DIC_Jpeg) {
426 DicEntry->DecoderData =
427 a_Jpeg_new(web->Image, DicEntry->url, DicEntry->version);
428 } else if (ImgType == DIC_Gif) {
430 DicEntry->DecoderData =
431 a_Gif_new(web->Image, DicEntry->url, DicEntry->version);
432 } else if (ImgType == DIC_Webp) {
434 DicEntry->DecoderData =
435 a_Webp_new(web->Image, DicEntry->url, DicEntry->version);
436 } else if (ImgType == DIC_Png) {
438 DicEntry->DecoderData =
439 a_Png_new(web->Image, DicEntry->url, DicEntry->version);
440 } else if (ImgType == DIC_Svg) {
442 DicEntry->DecoderData =
443 a_Svg_new(web->Image, DicEntry->url, DicEntry->version);
444 }
445 } else {
446 /* Repeated image */
447 a_Dicache_ref(DicEntry->url, DicEntry->version);
448 }
449 /* Survive three cleanup passes (set to zero = old behaviour). */
450 DicEntry->SurvCleanup = 3;
451
452 *Data = DicEntry->DecoderData;
454
455 return (a_Image_get_dw (web->Image));
456}
457
461void *a_Dicache_png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
462 void **Data)
463{
464 return Dicache_image(DIC_Png, Type, Ptr, Call, Data);
465}
466
470void *a_Dicache_webp_image(const char *Type, void *Ptr, CA_Callback_t *Call,
471 void **Data)
472{
473 return Dicache_image(DIC_Webp, Type, Ptr, Call, Data);
474}
475
479void *a_Dicache_gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
480 void **Data)
481{
482 return Dicache_image(DIC_Gif, Type, Ptr, Call, Data);
483}
484
488void *a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
489 void **Data)
490{
491 return Dicache_image(DIC_Jpeg, Type, Ptr, Call, Data);
492}
493
497void *a_Dicache_svg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
498 void **Data)
499{
500 return Dicache_image(DIC_Svg, Type, Ptr, Call, Data);
501}
502
507{
508 uint_t i;
509 DilloWeb *Web = Client->Web;
510 DilloImage *Image = Web->Image;
511 DICacheEntry *DicEntry = a_Dicache_get_entry(Web->url, DIC_Last);
512
513 dReturn_if_fail ( DicEntry != NULL );
514
515 /* Copy the version number in the Client */
516 if (Client->Version == 0)
517 Client->Version = DicEntry->version;
518
519 /* Only call the decoder when necessary */
520 if (Op == CA_Send && DicEntry->State < DIC_Close &&
521 DicEntry->DecodedSize < Client->BufSize) {
522 DicEntry->Decoder(Op, Client);
523 DicEntry->DecodedSize = Client->BufSize;
524 } else if (Op == CA_Close || Op == CA_Abort) {
525 if (DicEntry->State < DIC_Close) {
526 DicEntry->Decoder(Op, Client);
527 } else {
528 a_Dicache_close(DicEntry->url, DicEntry->version, Client);
529 }
530 }
531
532 /* when the data stream is not an image 'v_imgbuf' remains NULL */
533 if (Op == CA_Send && DicEntry->v_imgbuf) {
534 if (Image->height == 0 && DicEntry->State >= DIC_SetParms) {
535 /* Set parms */
537 Image, DicEntry->v_imgbuf, DicEntry->url,
538 DicEntry->version, DicEntry->width, DicEntry->height,
539 DicEntry->type);
540 }
541 if (DicEntry->State == DIC_Write) {
542 if (DicEntry->ScanNumber == Image->ScanNumber) {
543 for (i = 0; i < DicEntry->height; ++i)
544 if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) &&
545 !a_Bitvec_get_bit(Image->BitVec, (int)i) )
546 a_Image_write(Image, i);
547 } else {
548 for (i = 0; i < DicEntry->height; ++i) {
549 if (a_Bitvec_get_bit(DicEntry->BitVec, (int)i) ||
550 !a_Bitvec_get_bit(Image->BitVec, (int)i) ||
551 DicEntry->ScanNumber > Image->ScanNumber + 1) {
552 a_Image_write(Image, i);
553 }
554 if (!a_Bitvec_get_bit(DicEntry->BitVec, (int)i))
555 a_Bitvec_clear_bit(Image->BitVec, (int)i);
556 }
557 Image->ScanNumber = DicEntry->ScanNumber;
558 }
559 }
560 } else if (Op == CA_Close) {
561 a_Image_close(Image);
562 a_Bw_close_client(Web->bw, Client->Key);
563 } else if (Op == CA_Abort) {
564 a_Image_abort(Image);
565 a_Bw_close_client(Web->bw, Client->Key);
566 }
567}
568
569/* ------------------------------------------------------------------------- */
570
575{
576 int i;
577 DICacheEntry *entry;
578
579 for (i = 0; (entry = dList_nth_data(CachedIMGs, i)); ++i) {
580 _MSG(" SurvCleanup = %d\n", entry->SurvCleanup);
581 if (entry->RefCount == 0 &&
582 (!entry->v_imgbuf || a_Imgbuf_last_reference(entry->v_imgbuf))) {
583 if (--entry->SurvCleanup >= 0)
584 continue; /* keep the entry one more pass */
585
586 /* free this unused entry */
587 Dicache_remove(entry->url, entry->version);
588 --i; /* adjust counter */
589 }
590 }
591 _MSG("a_Dicache_cleanup: length = %d\n", dList_length(CachedIMGs));
592}
593
594/* ------------------------------------------------------------------------- */
595
601{
602 DICacheEntry *entry;
603
604 /* Remove all the dicache entries */
605 while ((entry = dList_nth_data(CachedIMGs, dList_length(CachedIMGs)-1))) {
607 a_Url_free(entry->url);
608 dFree(entry->cmap);
609 a_Bitvec_free(entry->BitVec);
610 a_Imgbuf_unref(entry->v_imgbuf);
612 dFree(entry);
613 }
615}
616
618{
619 long bytesCached = 0L;
620 Dstr *s = dStr_new(
621 "<!DOCTYPE HTML>\n"
622 "<html>\n"
623 "<head><title>Decompressed Image Cache</title></head>\n"
624 "<body>\n");
625
626 int n = dList_length(CachedIMGs);
627 dStr_sprintfa(s, "<h1>Decompressed Image Cache (%d)</h1>\n", n);
628
629 dStr_append(s, "<table>\n");
630 dStr_append(s, "<tr>\n");
631 dStr_append(s, "<th><span title='Survival Counter'>S</span></th>\n");
632 dStr_append(s, "<th><span title='Last Reference'>L</span></th>\n");
633 dStr_append(s, "<th>Area</th>\n");
634 dStr_append(s, "<th>Size</th>\n");
635 dStr_append(s, "<th>URL</th>\n");
636 dStr_append(s, "</tr>\n");
637 for (int i = 0; i < n; i++) {
639 dStr_append(s, "<tr>\n");
640 dStr_sprintfa(s, "<td style='text-align:right'>%hd</td>", e->SurvCleanup);
641 dStr_sprintfa(s, "<td style='text-align:right'>%d</td>", Dicache_is_last_ref(e));
642 dStr_sprintfa(s, "<td style='text-align:right'>%ux%u</td>", e->width, e->height);
643 dStr_sprintfa(s, "<td style='text-align:right'>%.2f KiB</td>\n",
644 e->TotalSize / 1024.0f);
645 dStr_sprintfa(s, "<td><a href='%s'>", URL_STR(e->url));
646 dStr_shorten(s, URL_STR(e->url), 60);
647 dStr_append(s, "</a></td>\n");
648 dStr_append(s, "</tr>\n");
649 bytesCached += (long) e->TotalSize;
650 }
651 dStr_append(s, "</table>\n");
652 float mb = (float) bytesCached / (1024.0f * 1024.0f);
653
654 dStr_sprintfa(s, "<p>Total cached: %.2f MiB</p>\n", mb);
655
656 dStr_append(s,
657 "</body>\n"
658 "</html>\n");
659
660 return s;
661}
void a_Bitvec_clear(bitvec_t *bvec)
Clear a bitvec.
Definition bitvec.c:35
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
int a_Bitvec_get_bit(bitvec_t *bvec, int pos)
Get a bit.
Definition bitvec.c:54
#define a_Bitvec_clear_bit(bvec, pos)
Definition bitvec.h:31
#define _MSG(...)
Definition bookmarks.c:45
#define MSG(...)
Definition bookmarks.c:46
void a_Bw_close_client(BrowserWindow *bw, int ClientKey)
Close a cache-client upon successful retrieval.
Definition bw.c:167
#define CA_Send
Definition cache.h:27
void(* CA_Callback_t)(int Op, CacheClient_t *Client)
Callback type for cache clients.
Definition cache.h:55
#define CA_Abort
Definition cache.h:29
#define CA_Close
Definition cache.h:28
unsigned char uchar_t
Definition d_size.h:17
unsigned int uint_t
Definition d_size.h:20
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image, uint_t width, uint_t height, DilloImgType type, double gamma)
Set image's width, height & type.
Definition dicache.c:262
DICacheEntry * a_Dicache_get_entry(const DilloUrl *Url, int version)
Search a particular version of a URL in the Dicache.
Definition dicache.c:156
void a_Dicache_cleanup(void)
Free the imgbuf (RGB data) of unused entries.
Definition dicache.c:574
static Dlist * CachedIMGs
List of DICacheEntry.
Definition dicache.c:56
static DICacheEntry * Dicache_entry_new(void)
Create, and initialize a new, empty, dicache entry.
Definition dicache.c:100
@ DIC_Svg
Definition dicache.c:38
@ DIC_MAX
Definition dicache.c:39
@ DIC_Jpeg
Definition dicache.c:37
@ DIC_Png
Definition dicache.c:35
@ DIC_Webp
Definition dicache.c:36
@ DIC_Gif
Definition dicache.c:34
void a_Dicache_invalidate_entry(const DilloUrl *Url)
Invalidate this entry.
Definition dicache.c:246
#define I_RGB
static const char * format_name[DIC_MAX]
Definition dicache.c:42
DICacheEntry * a_Dicache_ref(const DilloUrl *Url, int version)
Refs the counter of a dicache entry.
Definition dicache.c:231
void a_Dicache_new_scan(const DilloUrl *url, int version)
Reset for a new scan from a multiple-scan image.
Definition dicache.c:320
void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
Implement the close method of the decoding process.
Definition dicache.c:363
void * a_Dicache_svg_image(const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
SVG wrapper for Dicache_image()
Definition dicache.c:497
void a_Dicache_init(void)
Initialize dicache data.
Definition dicache.c:82
void a_Dicache_unref(const DilloUrl *Url, int version)
Unrefs the counter of a dicache entry (it counts cache clients).
Definition dicache.c:214
void a_Dicache_callback(int Op, CacheClient_t *Client)
This function is a cache client; (but feeds its clients from dicache)
Definition dicache.c:506
void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
Implement the write method (Write a scan line into the Dicache entry) buf: row buffer Y : row number.
Definition dicache.c:343
static int Dicache_entry_cmp(const void *v1, const void *v2)
Compare function for image entries.
Definition dicache.c:65
static void * Dicache_image(int ImgType, const char *MimeType, void *Ptr, CA_Callback_t *Call, void **Data)
Generic MIME handler for GIF, JPEG, PNG and SVG.
Definition dicache.c:400
void a_Dicache_freeall(void)
Deallocate memory used by dicache module (Call this one at exit time, with no cache clients queued)
Definition dicache.c:600
static uint_t dicache_size_total
Definition dicache.c:58
void a_Dicache_set_cmap(DilloUrl *url, int version, int bg_color, const uchar_t *cmap, uint_t num_colors, int num_colors_max, int bg_index)
Implement the set_cmap method for the Image.
Definition dicache.c:296
static void Dicache_remove(const DilloUrl *Url, int version)
Actually free a dicache entry, given the URL and the version number.
Definition dicache.c:173
void * a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
JPEG wrapper for Dicache_image()
Definition dicache.c:488
static DICacheEntry * Dicache_add_entry(const DilloUrl *Url)
Add a new entry in the dicache (a single URL may have several entries)
Definition dicache.c:129
static int Dicache_is_last_ref(DICacheEntry *entry)
Definition dicache.c:200
Dstr * a_Dicache_stats(void)
Definition dicache.c:617
void * a_Dicache_webp_image(const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
WEBP wrapper for Dicache_image()
Definition dicache.c:470
void * a_Dicache_gif_image(const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
GIF wrapper for Dicache_image()
Definition dicache.c:479
static int disabled_formats[DIC_MAX]
Definition dicache.c:50
void * a_Dicache_png_image(const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
PNG wrapper for Dicache_image()
Definition dicache.c:461
#define DIF_Last
Flags: Last version, Valid entry.
Definition dicache.h:29
#define DIF_Valid
Definition dicache.h:30
@ DIC_Close
Whole image got!
Definition dicache.h:39
@ DIC_SetCmap
Color map set.
Definition dicache.h:37
@ DIC_SetParms
Parameters set.
Definition dicache.h:36
@ DIC_Write
Feeding the entry.
Definition dicache.h:38
@ DIC_Empty
Just created the entry.
Definition dicache.h:35
#define DIC_Last
Symbolic name to request the last version of an image.
Definition dicache.h:27
void dList_insert_sorted(Dlist *lp, void *data, dCompareFunc func)
Insert an element into a sorted list.
Definition dlib.c:797
void dFree(void *mem)
Definition dlib.c:68
void dStr_sprintfa(Dstr *ds, const char *format,...)
Printf-like function that appends.
Definition dlib.c:464
void dStr_append(Dstr *ds, const char *s)
Append a C string to a Dstr.
Definition dlib.c:316
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:576
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:641
void dStr_shorten(Dstr *dst, const char *src, int n)
Shorten string so it fits in n characters.
Definition dlib.c:551
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:690
void dList_remove_fast(Dlist *lp, const void *data)
Remove a data item without preserving order.
Definition dlib.c:651
char * dStriAsciiStr(const char *haystack, const char *needle)
Case insensitive strstr.
Definition dlib.c:184
Dstr * dStr_new(const char *s)
Create a new string.
Definition dlib.c:325
void * dList_find_sorted(Dlist *lp, const void *data, dCompareFunc func)
Search a sorted list.
Definition dlib.c:824
void dList_free(Dlist *lp)
Free a list (not its elements)
Definition dlib.c:592
void dList_remove(Dlist *lp, const void *data)
Definition dlib.c:669
#define dReturn_if_fail(expr)
Definition dlib.h:84
#define dNew0(type, count)
Definition dlib.h:63
#define dReturn_val_if_fail(expr, val)
Definition dlib.h:88
#define dReturn_if(expr)
Definition dlib.h:76
#define dNew(type, count)
Definition dlib.h:61
void * a_Png_new(DilloImage *Image, DilloUrl *url, int version)
Create the image state data that must be kept between calls.
Definition png.c:448
void a_Png_callback(int Op, CacheClient_t *Client)
void a_Gif_callback()
Definition gif.c:1024
void * a_Gif_new()
Definition gif.c:1023
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
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
void a_Jpeg_callback()
Definition jpeg.c:423
void * a_Jpeg_new()
Definition jpeg.c:422
DilloPrefs prefs
Global Data.
Definition prefs.c:33
void a_Image_ref(DilloImage *Image)
Add a reference to an Image struct Do nothing if the argument is NULL.
Definition image.cc:100
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
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
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
@ DILLO_IMG_TYPE_NOTSET
Definition image.hh:47
void * render_layout
All the rendering is done by this.
Definition bw.h:34
Data structure for cache clients.
Definition cache.h:60
int Key
Primary Key for this client.
Definition cache.h:61
int Version
Dicache version of this Url (0 if not used)
Definition cache.h:63
uint_t BufSize
Valid size of cache-data.
Definition cache.h:65
void * Web
Pointer to the Web structure of our client.
Definition cache.h:68
int RefCount
Reference Counter.
Definition dicache.h:55
uint_t ScanNumber
Current decoding scan.
Definition dicache.h:52
int version
Version number, used for different versions of the same URL image.
Definition dicache.h:56
uchar_t * cmap
Color map.
Definition dicache.h:49
uint_t DecodedSize
Size of already decoded data.
Definition dicache.h:59
short SurvCleanup
Cleanup-pass survival for unused images.
Definition dicache.h:48
DilloImgType type
Image type.
Definition dicache.h:45
short Flags
See Flags.
Definition dicache.h:47
DicEntryState State
Current status for this entry.
Definition dicache.h:54
DilloUrl * url
Image URL for this entry.
Definition dicache.h:44
CA_Callback_t Decoder
Client function.
Definition dicache.h:60
uint_t TotalSize
Amount of memory the image takes up.
Definition dicache.h:51
uint_t width
Definition dicache.h:46
bitvec_t * BitVec
Bit vector for decoded rows.
Definition dicache.h:53
uint_t height
As taken from image data.
Definition dicache.h:46
void * DecoderData
Client function data.
Definition dicache.h:61
void * v_imgbuf
Void pointer to an Imgbuf object.
Definition dicache.h:50
char * ignore_image_formats
Definition prefs.h:100
Definition url.h:88
Definition dlib.h:144
Definition dlib.h:114
void * layout
Definition image.hh:61
uint_t ScanNumber
Current decoding scan.
Definition image.hh:71
uint_t height
Definition image.hh:65
bitvec_t * BitVec
Bit vector for decoded rows.
Definition image.hh:70
DilloUrl * url
Requested URL.
Definition web.hh:25
BrowserWindow * bw
The requesting browser window [reference].
Definition web.hh:28
DilloImage * Image
For image urls [reference].
Definition web.hh:31
int32_t bgColor
for image backgrounds
Definition web.hh:33
void a_Svg_callback()
Definition svg.c:168
void * a_Svg_new()
Definition svg.c:167
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
Compare two Url's to check if they're the same, or which one is bigger.
Definition url.c:506
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477
#define URL_STR(u)
Definition url.h:76
void a_Webp_callback()
Definition webp.c:217
void * a_Webp_new()
Definition webp.c:216