Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dicache.c File Reference
#include <string.h>
#include <stdlib.h>
#include "msg.h"
#include "image.hh"
#include "imgbuf.hh"
#include "web.hh"
#include "dicache.h"
#include "dpng.h"
#include "dwebp.h"
#include "dgif.h"
#include "djpeg.h"
#include "dsvg.h"
Include dependency graph for dicache.c:

Go to the source code of this file.

Macros

#define I_RGB   0
 

Enumerations

enum  {
  DIC_Gif = 0 , DIC_Png , DIC_Webp , DIC_Jpeg ,
  DIC_Svg , DIC_MAX
}
 

Functions

static int Dicache_entry_cmp (const void *v1, const void *v2)
 Compare function for image entries.
 
void a_Dicache_init (void)
 Initialize dicache data.
 
static DICacheEntryDicache_entry_new (void)
 Create, and initialize a new, empty, dicache entry.
 
static DICacheEntryDicache_add_entry (const DilloUrl *Url)
 Add a new entry in the dicache (a single URL may have several entries)
 
DICacheEntrya_Dicache_get_entry (const DilloUrl *Url, int version)
 Search a particular version of a URL in the Dicache.
 
static void Dicache_remove (const DilloUrl *Url, int version)
 Actually free a dicache entry, given the URL and the version number.
 
void a_Dicache_unref (const DilloUrl *Url, int version)
 Unrefs the counter of a dicache entry (it counts cache clients).
 
DICacheEntrya_Dicache_ref (const DilloUrl *Url, int version)
 Refs the counter of a dicache entry.
 
void a_Dicache_invalidate_entry (const DilloUrl *Url)
 Invalidate this entry.
 
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.
 
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.
 
void a_Dicache_new_scan (const DilloUrl *url, int version)
 Reset for a new scan from a multiple-scan image.
 
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.
 
void a_Dicache_close (DilloUrl *url, int version, CacheClient_t *Client)
 Implement the close method of the decoding process.
 
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.
 
void * a_Dicache_png_image (const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
 PNG wrapper for Dicache_image()
 
void * a_Dicache_webp_image (const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
 WEBP wrapper for Dicache_image()
 
void * a_Dicache_gif_image (const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
 GIF wrapper for Dicache_image()
 
void * a_Dicache_jpeg_image (const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
 JPEG wrapper for Dicache_image()
 
void * a_Dicache_svg_image (const char *Type, void *Ptr, CA_Callback_t *Call, void **Data)
 SVG wrapper for Dicache_image()
 
void a_Dicache_callback (int Op, CacheClient_t *Client)
 This function is a cache client; (but feeds its clients from dicache)
 
void a_Dicache_cleanup (void)
 Free the imgbuf (RGB data) of unused entries.
 
void a_Dicache_freeall (void)
 Deallocate memory used by dicache module (Call this one at exit time, with no cache clients queued)
 

Variables

static const char * format_name [DIC_MAX]
 
static int disabled_formats [DIC_MAX] = { 0 }
 
static DlistCachedIMGs = NULL
 List of DICacheEntry.
 
static uint_t dicache_size_total
 

Macro Definition Documentation

◆ I_RGB

#define I_RGB   0

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DIC_Gif 
DIC_Png 
DIC_Webp 
DIC_Jpeg 
DIC_Svg 
DIC_MAX 

Definition at line 27 of file dicache.c.

Function Documentation

◆ a_Dicache_callback()

◆ a_Dicache_cleanup()

void a_Dicache_cleanup ( void  )

◆ a_Dicache_close()

◆ a_Dicache_freeall()

void a_Dicache_freeall ( void  )

Deallocate memory used by dicache module (Call this one at exit time, with no cache clients queued)

Definition at line 586 of file dicache.c.

References a_Bitvec_free(), a_Imgbuf_unref(), a_Url_free(), DICacheEntry::BitVec, CachedIMGs, DICacheEntry::cmap, dFree(), dicache_size_total, dList_free(), dList_length(), dList_nth_data(), dList_remove_fast(), DICacheEntry::TotalSize, DICacheEntry::url, and DICacheEntry::v_imgbuf.

Referenced by main().

◆ a_Dicache_get_entry()

DICacheEntry * a_Dicache_get_entry ( const DilloUrl Url,
int  version 
)

Search a particular version of a URL in the Dicache.

Returns
a pointer to the entry if found; NULL otherwise.

Notes: DIC_Last means last version of the image. version zero is not allowed.

Definition at line 150 of file dicache.c.

References CachedIMGs, DIC_Last, Dicache_entry_cmp(), DIF_Valid, dList_find_sorted(), dReturn_val_if_fail, DICacheEntry::Flags, DICacheEntry::url, and DICacheEntry::version.

Referenced by a_Cache_stop_client(), a_Dicache_callback(), a_Dicache_close(), a_Dicache_invalidate_entry(), a_Dicache_new_scan(), a_Dicache_ref(), a_Dicache_set_cmap(), a_Dicache_set_parms(), a_Dicache_unref(), a_Dicache_write(), and Dicache_image().

◆ a_Dicache_gif_image()

void * a_Dicache_gif_image ( const char *  Type,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)

GIF wrapper for Dicache_image()

Definition at line 465 of file dicache.c.

References DIC_Gif, and Dicache_image().

Referenced by a_Mime_init().

◆ a_Dicache_init()

void a_Dicache_init ( void  )

Initialize dicache data.

Definition at line 76 of file dicache.c.

References _MSG, CachedIMGs, DIC_MAX, dicache_size_total, disabled_formats, dList_new(), dStriAsciiStr(), format_name, DilloPrefs::ignore_image_formats, and prefs.

Referenced by main().

◆ a_Dicache_invalidate_entry()

void a_Dicache_invalidate_entry ( const DilloUrl Url)

Invalidate this entry.

This is used for the reloading mechanism. Can't erase current versions, but a_Dicache_get_entry(url, DIC_Last) must return NULL.

Definition at line 232 of file dicache.c.

References a_Dicache_get_entry(), DIC_Last, and DICacheEntry::Flags.

Referenced by Cache_entry_remove().

◆ a_Dicache_jpeg_image()

void * a_Dicache_jpeg_image ( const char *  Type,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)

JPEG wrapper for Dicache_image()

Definition at line 474 of file dicache.c.

References DIC_Jpeg, and Dicache_image().

Referenced by a_Mime_init().

◆ a_Dicache_new_scan()

void a_Dicache_new_scan ( const DilloUrl url,
int  version 
)

◆ a_Dicache_png_image()

void * a_Dicache_png_image ( const char *  Type,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)

PNG wrapper for Dicache_image()

Definition at line 447 of file dicache.c.

References DIC_Png, and Dicache_image().

Referenced by a_Mime_init().

◆ a_Dicache_ref()

DICacheEntry * a_Dicache_ref ( const DilloUrl Url,
int  version 
)

Refs the counter of a dicache entry.

Definition at line 217 of file dicache.c.

References a_Dicache_get_entry(), and DICacheEntry::RefCount.

Referenced by Dicache_image().

◆ a_Dicache_set_cmap()

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 at line 282 of file dicache.c.

References _MSG, a_Dicache_get_entry(), DICacheEntry::cmap, dFree(), DIC_SetCmap, dNew0, dReturn_if_fail, and DICacheEntry::State.

◆ a_Dicache_set_parms()

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.

  • 'width' and 'height' come from the image data.
  • HTML width and height attrs are handled with setNonCssHint.
  • CSS sizing is handled by the CSS engine.

Definition at line 248 of file dicache.c.

References _MSG, a_Bitvec_new(), a_Dicache_get_entry(), a_Imgbuf_new(), DICacheEntry::BitVec, DIC_SetParms, dicache_size_total, dReturn_if_fail, DICacheEntry::height, I_RGB, _DilloImage::layout, DICacheEntry::RefCount, DICacheEntry::State, DICacheEntry::TotalSize, DICacheEntry::type, URL_STR, DICacheEntry::v_imgbuf, DICacheEntry::version, and DICacheEntry::width.

Referenced by Png_datainfo_callback().

◆ a_Dicache_svg_image()

void * a_Dicache_svg_image ( const char *  Type,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)

SVG wrapper for Dicache_image()

Definition at line 483 of file dicache.c.

References DIC_Svg, and Dicache_image().

Referenced by a_Mime_init().

◆ a_Dicache_unref()

void a_Dicache_unref ( const DilloUrl Url,
int  version 
)

Unrefs the counter of a dicache entry (it counts cache clients).

If there're no clients and no imgbuf, remove the entry. Otherwise, let a_Dicache_cleanup() do the job later (keeping it cached meanwhile for e.g. reload, repush, back/fwd).

Definition at line 200 of file dicache.c.

References _MSG, a_Dicache_get_entry(), a_Imgbuf_last_reference(), Dicache_remove(), DICacheEntry::RefCount, DICacheEntry::State, and DICacheEntry::v_imgbuf.

Referenced by a_Cache_stop_client(), and a_Dicache_close().

◆ a_Dicache_webp_image()

void * a_Dicache_webp_image ( const char *  Type,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)

WEBP wrapper for Dicache_image()

Definition at line 456 of file dicache.c.

References DIC_Webp, and Dicache_image().

Referenced by a_Mime_init().

◆ a_Dicache_write()

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 at line 329 of file dicache.c.

References _MSG, a_Bitvec_set_bit(), a_Dicache_get_entry(), a_Imgbuf_update(), DICacheEntry::BitVec, DICacheEntry::cmap, DIC_Write, dReturn_if_fail, DICacheEntry::height, DICacheEntry::State, DICacheEntry::type, DICacheEntry::v_imgbuf, and DICacheEntry::width.

Referenced by Png_datarow_callback().

◆ Dicache_add_entry()

static DICacheEntry * Dicache_add_entry ( const DilloUrl Url)
static

Add a new entry in the dicache (a single URL may have several entries)

Definition at line 123 of file dicache.c.

References a_Url_dup(), CachedIMGs, DIC_Last, Dicache_entry_cmp(), Dicache_entry_new(), DIF_Last, dList_find_sorted(), dList_insert_sorted(), DICacheEntry::Flags, DICacheEntry::url, and DICacheEntry::version.

Referenced by Dicache_image().

◆ Dicache_entry_cmp()

static int Dicache_entry_cmp ( const void *  v1,
const void *  v2 
)
static

Compare function for image entries.

Definition at line 59 of file dicache.c.

References a_Url_cmp(), DIC_Last, DIF_Last, DICacheEntry::Flags, DICacheEntry::url, and DICacheEntry::version.

Referenced by a_Dicache_get_entry(), Dicache_add_entry(), and Dicache_remove().

◆ Dicache_entry_new()

◆ Dicache_image()

static void * Dicache_image ( int  ImgType,
const char *  MimeType,
void *  Ptr,
CA_Callback_t Call,
void **  Data 
)
static

◆ Dicache_remove()

Variable Documentation

◆ CachedIMGs

Dlist* CachedIMGs = NULL
static

List of DICacheEntry.

May hold several versions of the same image, although most of the time it holds just one.

Definition at line 50 of file dicache.c.

Referenced by a_Dicache_cleanup(), a_Dicache_freeall(), a_Dicache_get_entry(), a_Dicache_init(), Dicache_add_entry(), and Dicache_remove().

◆ dicache_size_total

uint_t dicache_size_total
static

Definition at line 52 of file dicache.c.

Referenced by a_Dicache_freeall(), a_Dicache_init(), a_Dicache_set_parms(), and Dicache_remove().

◆ disabled_formats

int disabled_formats[DIC_MAX] = { 0 }
static

Definition at line 44 of file dicache.c.

Referenced by a_Dicache_init(), and Dicache_image().

◆ format_name

const char* format_name[DIC_MAX]
static
Initial value:
= {
[DIC_Gif] = "gif",
[DIC_Png] = "png",
[DIC_Webp] = "webp",
[DIC_Jpeg] = "jpeg",
[DIC_Svg] = "svg"
}
@ DIC_Svg
Definition dicache.c:32
@ DIC_Jpeg
Definition dicache.c:31
@ DIC_Png
Definition dicache.c:29
@ DIC_Webp
Definition dicache.c:30
@ DIC_Gif
Definition dicache.c:28

Definition at line 36 of file dicache.c.

Referenced by a_Dicache_init(), and Dicache_image().