Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gif timeserie #102

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ else(PNG_FOUND)
report_mandatory_not_found(PNG)
endif(PNG_FOUND)

find_package(GIF)
if(GIF_FOUND)
include_directories(${GIF_INCLUDE_DIR})
target_link_libraries(mapcache ${GIF_LIBRARY})
else(GIF_FOUND)
report_mandatory_not_found(GIF)
endif(GIF_FOUND)

find_package(JPEG)
if(JPEG_FOUND)
include_directories(${JPEG_INCLUDE_DIR})
Expand Down Expand Up @@ -263,6 +271,7 @@ endmacro()
message(STATUS "* Configured options for the mapcache library")
message(STATUS " * Mandatory components")
message(STATUS " * png: ${PNG_LIBRARY}")
message(STATUS " * gif: ${GIF_LIBRARY}")
message(STATUS " * jpeg: ${JPEG_LIBRARY}")
message(STATUS " * Curl: ${CURL_LIBRARY}")
message(STATUS " * Apr: ${APR_LIBRARY}")
Expand Down
30 changes: 27 additions & 3 deletions include/mapcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ typedef struct mapcache_image_format mapcache_image_format;
typedef struct mapcache_image_format_mixed mapcache_image_format_mixed;
typedef struct mapcache_image_format_png mapcache_image_format_png;
typedef struct mapcache_image_format_png_q mapcache_image_format_png_q;
typedef struct mapcache_image_format_gif mapcache_image_format_gif;
typedef struct mapcache_image_format_jpeg mapcache_image_format_jpeg;
typedef struct mapcache_cfg mapcache_cfg;
typedef struct mapcache_tileset mapcache_tileset;
Expand Down Expand Up @@ -843,7 +844,7 @@ void mapcache_service_dispatch_request(mapcache_context *ctx,
/** @{ */

typedef enum {
GC_UNKNOWN, GC_PNG, GC_JPEG
GC_UNKNOWN, GC_PNG, GC_JPEG, GC_GIF
} mapcache_image_format_type;

typedef enum {
Expand Down Expand Up @@ -1200,7 +1201,7 @@ struct mapcache_grid_link {
mapcache_extent *restricted_extent;
mapcache_extent_i *grid_limits;
int minz,maxz;

/**
* tiles above this zoom level will not be stored to the cache, but will be
* dynamically generated (either by reconstructing from lower level tiles, or
Expand Down Expand Up @@ -1506,6 +1507,7 @@ struct mapcache_image_format {
char *extension; /**< the extension to use when saving a file with this format */
char *mime_type;
mapcache_buffer * (*write)(mapcache_context *ctx, mapcache_image *image, mapcache_image_format * format);
mapcache_buffer * (*write_frames)(mapcache_context *ctx, mapcache_image *images, int numimages, mapcache_image_format * format, int delay);
/**< pointer to a function that returns a mapcache_buffer containing the given image encoded
* in the specified format
*/
Expand Down Expand Up @@ -1591,6 +1593,27 @@ mapcache_image_format* mapcache_imageio_create_png_q_format(apr_pool_t *pool, ch

/** @} */

typedef struct {
unsigned char b,g,r,a;
} rgbaPixel;

typedef struct {
unsigned char r,g,b;
} rgbPixel;


struct mapcache_image_format_gif {
mapcache_image_format format;
mapcache_buffer * (*write_frames)(mapcache_context *ctx, mapcache_image *images, int numimages, mapcache_image_format * format, int delay);
int *animate;
};
mapcache_image_format* mapcache_imageio_create_gif_format(apr_pool_t *pool, char *name);
mapcache_buffer* _mapcache_imageio_gif_encode(mapcache_context *ctx, mapcache_image *img, mapcache_image_format *format);


mapcache_image_format* mapcache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality,
mapcache_photometric photometric);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do these private functions need to be exposed in the main header? I'd rather you created a specific file if you need to use quantization from multiple places

/**\defgroup imageio_jpg JPEG Image IO
* \ingroup imageio */
/** @{ */
Expand Down Expand Up @@ -1741,11 +1764,12 @@ apr_array_header_t* mapcache_timedimension_get_entries_for_value(mapcache_contex
struct mapcache_timedimension {
mapcache_timedimension_assembly_type assembly_type;
void (*configuration_parse_xml)(mapcache_context *context, mapcache_timedimension *dim, ezxml_t node);
apr_array_header_t* (*get_entries_for_interval)(mapcache_context *ctx, mapcache_timedimension *dim, mapcache_tileset *tileset,
apr_array_header_t* (*get_entries_for_interval)(mapcache_context *ctx, mapcache_timedimension *dim, mapcache_tileset *tileset,
mapcache_grid *grid, mapcache_extent *extent, time_t start, time_t end);
apr_array_header_t* (*get_all_entries)(mapcache_context *ctx, mapcache_timedimension *dim, mapcache_tileset *tileset);
char *default_value;
char *key; /* TIME, hardcoded */
int delay;
};

#ifdef USE_SQLITE
Expand Down
165 changes: 165 additions & 0 deletions include/pam.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/******************************************************************************
* $Id$
*
* Project: MapServer
* Purpose: MapCache tile caching support file: PNG format
* Author: Thomas Bonfort and the MapServer team.
*
******************************************************************************
* Copyright (c) 1996-2011 Regents of the University of Minnesota.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#include "mapcache.h"

int _mapcache_imageio_quantize_image(mapcache_image *rb,
unsigned int *reqcolors, rgbaPixel *palette,
unsigned int *maxval,
rgbaPixel *forced_palette, int num_forced_palette_entries);
int _mapcache_imageio_classify(mapcache_image *rb, unsigned char *pixels,
rgbaPixel *palette, int numPaletteEntries);

/** \cond DONOTDOCUMENT */

/*
* derivations from pngquant and ppmquant
*
** pngquant.c - quantize the colors in an alphamap down to a specified number
**
** Copyright (C) 1989, 1991 by Jef Poskanzer.
** Copyright (C) 1997, 2000, 2002 by Greg Roelofs; based on an idea by
** Stefan Schneider.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation. This software is provided "as is" without express or
** implied warranty.
*/
/*
typedef struct {
unsigned char b,g,r,a;
} rgbaPixel;

typedef struct {
unsigned char r,g,b;
} rgbPixel;
*/


#define PAM_GETR(p) ((p).r)
#define PAM_GETG(p) ((p).g)
#define PAM_GETB(p) ((p).b)
#define PAM_GETA(p) ((p).a)
#define PAM_ASSIGN(p,red,grn,blu,alf) \
do { (p).r = (red); (p).g = (grn); (p).b = (blu); (p).a = (alf); } while (0)
#define PAM_EQUAL(p,q) \
((p).r == (q).r && (p).g == (q).g && (p).b == (q).b && (p).a == (q).a)
#define PAM_DEPTH(newp,p,oldmaxval,newmaxval) \
PAM_ASSIGN( (newp), \
( (int) PAM_GETR(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
( (int) PAM_GETG(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
( (int) PAM_GETB(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval), \
( (int) PAM_GETA(p) * (newmaxval) + (oldmaxval) / 2 ) / (oldmaxval) )


/* from pamcmap.h */

typedef struct acolorhist_item *acolorhist_vector;
struct acolorhist_item {
rgbaPixel acolor;
int value;
};

typedef struct acolorhist_list_item *acolorhist_list;
struct acolorhist_list_item {
struct acolorhist_item ch;
acolorhist_list next;
};

typedef acolorhist_list *acolorhash_table;

#define MAXCOLORS 32767

#define LARGE_NORM
#define REP_AVERAGE_PIXELS

typedef struct box *box_vector;
struct box {
int ind;
int colors;
int sum;
};

acolorhist_vector mediancut(acolorhist_vector achv, int colors, int sum, unsigned char maxval, int newcolors);
int redcompare (const void *ch1, const void *ch2);
int greencompare (const void *ch1, const void *ch2);
int bluecompare (const void *ch1, const void *ch2);
int alphacompare (const void *ch1, const void *ch2);
int sumcompare (const void *b1, const void *b2);

acolorhist_vector pam_acolorhashtoacolorhist
(acolorhash_table acht, int maxacolors);
acolorhist_vector pam_computeacolorhist
(rgbaPixel **apixels, int cols, int rows, int maxacolors, int* acolorsP);
acolorhash_table pam_computeacolorhash
(rgbaPixel** apixels, int cols, int rows, int maxacolors, int* acolorsP);
acolorhash_table pam_allocacolorhash (void);
int pam_addtoacolorhash
(acolorhash_table acht, rgbaPixel *acolorP, int value);
int pam_lookupacolor (acolorhash_table acht, rgbaPixel* acolorP);
void pam_freeacolorhist (acolorhist_vector achv);
void pam_freeacolorhash (acolorhash_table acht);



/*===========================================================================*/


/* libpam3.c - pam (portable alpha map) utility library part 3
**
** Colormap routines.
**
** Copyright (C) 1989, 1991 by Jef Poskanzer.
** Copyright (C) 1997 by Greg Roelofs.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation. This software is provided "as is" without express or
** implied warranty.
*/

/*
#include "pam.h"
#include "pamcmap.h"
*/

#define HASH_SIZE 20023

#define pam_hashapixel(p) ( ( ( (long) PAM_GETR(p) * 33023 + \
(long) PAM_GETG(p) * 30013 + \
(long) PAM_GETB(p) * 27011 + \
(long) PAM_GETA(p) * 24007 ) \
& 0x7fffffff ) % HASH_SIZE )

/** \endcond DONOTDOCUMENT */
3 changes: 3 additions & 0 deletions lib/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ mapcache_cfg* mapcache_configuration_create(apr_pool_t *pool)
mapcache_configuration_add_image_format(cfg,
mapcache_imageio_create_png_q_format(pool,"PNG8",MAPCACHE_COMPRESSION_FAST,256),
"PNG8");
mapcache_configuration_add_image_format(cfg,
mapcache_imageio_create_gif_format(pool,"GIF"),
"GIF");
mapcache_configuration_add_image_format(cfg,
mapcache_imageio_create_jpeg_format(pool,"JPEG",90,MAPCACHE_PHOTOMETRIC_YCBCR),
"JPEG");
Expand Down
32 changes: 26 additions & 6 deletions lib/configuration_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void parseMetadata(mapcache_context *ctx, ezxml_t node, apr_table_t *metadata)

void parseTimeDimension(mapcache_context *ctx, ezxml_t node, mapcache_tileset *tileset) {
const char *attr = NULL;
int delay;
if(tileset->timedimension) {
ctx->set_error(ctx,400,"tileset \"%s\" can only have a single <timedimension>", tileset->name);
return;
Expand All @@ -66,7 +67,7 @@ void parseTimeDimension(mapcache_context *ctx, ezxml_t node, mapcache_tileset *t
ctx->set_error(ctx,400,"unknown \"type\" attribute \"%s\" for %s's <timedimension>. Expecting one of (sqlite)",attr,tileset->name);
return;
}

} else {
ctx->set_error(ctx,400,"missing \"type\" attribute for %s's <timedimension>",tileset->name);
return;
Expand All @@ -77,14 +78,33 @@ void parseTimeDimension(mapcache_context *ctx, ezxml_t node, mapcache_tileset *t
} else {
tileset->timedimension->key = apr_pstrdup(ctx->pool,"TIME");
}

attr = ezxml_attr(node,"default");
if(attr && *attr) {
tileset->timedimension->default_value = apr_pstrdup(ctx->pool,attr);
} else {
ctx->set_error(ctx,400,"no \"default\" attribute for <timedimension> %s",tileset->timedimension->key);
return;
}

attr = ezxml_attr(node, "animate");
if (attr && *attr){
if(!strcasecmp(attr, "true")) {
tileset->timedimension->assembly_type = MAPCACHE_TIMEDIMENSION_ASSEMBLY_ANIMATE;
attr = ezxml_attr(node, "delay");
if (attr && *attr) {
delay = atoi(attr);
if (delay > 0)
tileset->timedimension->delay = delay;
else
ctx->set_error(ctx,400, "the \"delay \" attribute for <timedimension> %s must be an integer bigger than 0", tileset->timedimension->key);
}
}
} else {
ctx->set_error(ctx,400,"no \"animate\" attribute for <timedimension> %s", tileset->timedimension->key);
}


tileset->timedimension->configuration_parse_xml(ctx,tileset->timedimension,node);
}

Expand Down Expand Up @@ -701,7 +721,7 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
ctx->set_error(ctx, 400, "invalid grid maxzoom/minzoom %d/%d", gridlink->minz,gridlink->maxz);
return;
}

sTolerance = (char*)ezxml_attr(cur_node,"max-cached-zoom");
/* RFC97 implementation: check for a maximum zoomlevel to cache */
if(sTolerance) {
Expand All @@ -712,14 +732,14 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
sTolerance);
return;
}

if(tolerance > gridlink->maxz) {
ctx->set_error(ctx, 400, "failed to parse grid max-cached-zoom %s (max cached zoom is greater than grid's max zoom)",
sTolerance);
return;
}
gridlink->max_cached_zoom = tolerance;

/* default to reassembling */
gridlink->outofzoom_strategy = MAPCACHE_OUTOFZOOM_REASSEMBLE;
sTolerance = (char*)ezxml_attr(cur_node,"out-of-zoom-strategy");
Expand Down Expand Up @@ -750,7 +770,7 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
parseDimensions(ctx, cur_node, tileset);
GC_CHECK_ERROR(ctx);
}

if ((cur_node = ezxml_child(node,"timedimension")) != NULL) {
parseTimeDimension(ctx, cur_node, tileset);
GC_CHECK_ERROR(ctx);
Expand Down
Loading