mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
store_ro_composite.c File Reference
#include <glib.h>
#include <stdio.h>
#include "config.h"
#include "g_logger.h"
#include "store.h"
#include "store_ro_composite.h"
#include <cairo/cairo.h>
#include <stdlib.h>
#include <string.h>

Functions

static cairo_status_t write_png_stream_to_byte_array (void *in_closure, const unsigned char *data, unsigned int length)
 Cairo PNG stream write callback appending encoded PNG chunks to a byte buffer.
static cairo_status_t read_png_stream_from_byte_array (void *in_closure, unsigned char *data, unsigned int length)
 Cairo PNG stream read callback feeding encoded PNG bytes from a memory buffer.
static int ro_composite_tile_read (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg)
 Read tiles from both primary and secondary backends, composite them via Cairo, and encode as PNG.
static struct stat_info ro_composite_tile_stat (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z)
 Delegate tile metadata and expiry lookup to the primary storage backend.
static char * ro_composite_tile_storage_id (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string)
 Return a static identifier string for composite tiles.
static int ro_composite_metatile_write (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz)
 Reject metatile write attempts on the read-only composite backend.
static int ro_composite_metatile_delete (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Reject metatile delete attempts on the read-only composite backend.
static int ro_composite_metatile_expire (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Reject metatile expiry attempts on the read-only composite backend.
static int ro_composite_close_storage (struct storage_backend *store)
 Close and free both child storage backends, the tile cache buffer, and ro_composite_ctx.
struct storage_backend * init_storage_ro_composite (const char *connection_string)
 Allocate and initialize a read-only Cairo compositing storage_backend.

Function Documentation

◆ init_storage_ro_composite()

struct storage_backend * init_storage_ro_composite ( const char * connection_string)

Allocate and initialize a read-only Cairo compositing storage_backend.

Parses connection_string of the form: "composite:{<xmlconfig_primary>,<backend_opts_primary>}{<xmlconfig_secondary>,<backend_opts_secondary>}", initializes both child storage backends via init_storage_backend(), sets the default render_size to 256, and wires all backend operation function pointers. Returns NULL if compiled without HAVE_CAIRO or if parsing/initialization fails.

Parameters
connection_stringConfiguration URI beginning with "composite:{".
Returns
Newly allocated struct storage_backend pointer, or NULL on failure or if unsupported.

◆ read_png_stream_from_byte_array()

cairo_status_t read_png_stream_from_byte_array ( void * in_closure,
unsigned char * data,
unsigned int length )
static

Cairo PNG stream read callback feeding encoded PNG bytes from a memory buffer.

Passed to cairo_image_surface_create_from_png_stream() to decode raw tile PNG data retrieved from an underlying storage backend.

Parameters
in_closurePointer to a png_stream_to_byte_array_closure_t tracking buffer bounds and cursor.
dataDestination buffer requested by Cairo's PNG decoder.
lengthNumber of bytes requested by Cairo.
Returns
CAIRO_STATUS_SUCCESS if read, or CAIRO_STATUS_READ_ERROR if closure->max_size is exceeded.

◆ ro_composite_close_storage()

int ro_composite_close_storage ( struct storage_backend * store)
static

Close and free both child storage backends, the tile cache buffer, and ro_composite_ctx.

Parameters
storeComposite storage_backend instance to close.
Returns
Always returns 0.

◆ ro_composite_metatile_delete()

int ro_composite_metatile_delete ( struct storage_backend * store,
const char * xmlconfig,
int x,
int y,
int z )
static

Reject metatile delete attempts on the read-only composite backend.

Parameters
storeComposite storage_backend (unused).
xmlconfigLogical map style name (unused).
xTile X coordinate (unused).
yTile Y coordinate (unused).
zTile zoom level (unused).
Returns
Always returns -1.

◆ ro_composite_metatile_expire()

int ro_composite_metatile_expire ( struct storage_backend * store,
const char * xmlconfig,
int x,
int y,
int z )
static

Reject metatile expiry attempts on the read-only composite backend.

Parameters
storeComposite storage_backend (unused).
xmlconfigLogical map style name (unused).
xTile X coordinate (unused).
yTile Y coordinate (unused).
zTile zoom level (unused).
Returns
Always returns -1.

◆ ro_composite_metatile_write()

int ro_composite_metatile_write ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
const char * buf,
int sz )
static

Reject metatile write attempts on the read-only composite backend.

Parameters
storeComposite storage_backend (unused).
xmlconfigLogical map style name (unused).
optionsStyle parameterization options string (unused).
xTile X coordinate (unused).
yTile Y coordinate (unused).
zTile zoom level (unused).
bufSerialized metatile buffer (unused).
szByte length of buf (unused).
Returns
Always returns -1.

◆ ro_composite_tile_read()

int ro_composite_tile_read ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
char * buf,
size_t sz,
int * compressed,
char * log_msg )
static

Read tiles from both primary and secondary backends, composite them via Cairo, and encode as PNG.

Fetches and decodes the PNG tile from store_primary (imageA), fetches and decodes the PNG tile from store_secondary (imageB), creates a render_size x render_size ARGB32 destination surface (imageC), paints imageA followed by imageB onto imageC, and encodes the resulting composite surface as PNG bytes into buf.

Parameters
storeInitialized composite storage_backend (storage_ctx holds struct ro_composite_ctx *).
xmlconfigLogical map style name (overridden internally by xmlconfig_primary / xmlconfig_secondary).
optionsStyle parameterization options string forwarded to both child backends.
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.
bufCaller-supplied scratch/output buffer receiving the composited PNG bytes.
szMaximum capacity of buf in bytes.
compressedOutput compression flag populated by the child tile_read() calls.
log_msgCaller-supplied buffer receiving an error message on failure.
Returns
Byte length of the composited PNG written into buf (> 0) on success, or -1 on read/decode/surface error.

◆ ro_composite_tile_stat()

struct stat_info ro_composite_tile_stat ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z )
static

Delegate tile metadata and expiry lookup to the primary storage backend.

Parameters
storeInitialized composite storage_backend.
xmlconfigLogical map style name (overridden by ctx->xmlconfig_primary).
optionsStyle parameterization options string.
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.
Returns
struct stat_info returned by ctx->store_primary->tile_stat().

◆ ro_composite_tile_storage_id()

char * ro_composite_tile_storage_id ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
char * string )
static

Return a static identifier string for composite tiles.

Parameters
storeComposite storage_backend (unused).
xmlconfigLogical map style name (unused).
optionsStyle parameterization options string (unused).
xTile X coordinate (unused).
yTile Y coordinate (unused).
zTile zoom level (unused).
stringCaller-supplied buffer (unused; static string pointer is returned).
Returns
Pointer to static string "Composite tile".

◆ write_png_stream_to_byte_array()

cairo_status_t write_png_stream_to_byte_array ( void * in_closure,
const unsigned char * data,
unsigned int length )
static

Cairo PNG stream write callback appending encoded PNG chunks to a byte buffer.

Passed to cairo_surface_write_to_png_stream() to serialize a composited ARGB32 surface directly into closure->data.

Parameters
in_closurePointer to a png_stream_to_byte_array_closure_t tracking buffer bounds and cursor.
dataSource PNG byte chunk emitted by Cairo.
lengthByte length of data.
Returns
CAIRO_STATUS_SUCCESS if copied, or CAIRO_STATUS_WRITE_ERROR if closure->max_size would overflow.