/*
- * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
* Copyright (C) 2005 QSDN,Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
struct query_string_param_t {
img_conv_mode_t mode;
- char* user_agent;
+ char *user_agent;
ua_use_flag_t ua_flag;
- char* name; /* for EZGET */
+ char *name; /* for EZGET */
long offset; /* for EZGET */
long count; /* for EZGET */
int width;
/*----------------------------------------------------------------------------*/
/* Download page for AU */
/*----------------------------------------------------------------------------*/
-static const char* HDML_FIRST_PAGE =
+static const char *HDML_FIRST_PAGE =
"<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
" <NODISPLAY>\r\n"
" <ACTION TYPE=ACCEPT TASK=GOSUB DEST=\"device:data/dnld?url=%s&name=%s%s&size=%ld&disposition=%s&title=%s\">\r\n"
" </NODISPLAY>\r\n"
"</HDML>\r\n";
-static const char* HDML_SUCCESS_PAGE =
+static const char *HDML_SUCCESS_PAGE =
"<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
" <DISPLAY>\r\n"
" <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
" </DISPLAY>\r\n"
"<HDML>\r\n";
-static const char* HDML_FAIL_PAGE =
+static const char *HDML_FAIL_PAGE =
"<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
" <DISPLAY>\r\n"
" <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
/*----------------------------------------------------------------------------*/
/* Prototype declaration */
/*----------------------------------------------------------------------------*/
-static char* s_create_workfile_name( request_rec*,
- mod_chxj_config* ,
- const char*,
- query_string_param_t*);
-
-static apr_status_t s_create_cache_file(request_rec* r,
- const char* tmpfile,
- device_table* spec,
- apr_finfo_t* st,
- query_string_param_t* qsp,
- mod_chxj_config *conf);
-
-static apr_status_t s_send_cache_file( device_table* spec,
- query_string_param_t* query_string,
- request_rec* r,
- const char* tmpfile);
-
-static apr_status_t s_send_original_file(request_rec* r,
- const char* originalfile);
-
-static apr_status_t s_header_only_cache_file(device_table* spec,
- query_string_param_t* query_string,
- request_rec* r,
- const char* tmpfile);
-
-static query_string_param_t* s_get_query_string_param(request_rec *r);
-
-static unsigned short s_add_crc( const char* writedata,
- apr_size_t witebyte);
-
-static MagickWand* s_fixup_size(MagickWand* ,
- request_rec* r,
- device_table* spec,
+static char *s_create_workfile_name(request_rec *,
+ mod_chxj_config *,
+ const char *,
+ query_string_param_t *);
+
+static apr_status_t s_create_cache_file(request_rec *r,
+ const char *tmpfile,
+ device_table *spec,
+ apr_finfo_t *st,
+ query_string_param_t *qsp,
+ mod_chxj_config *conf);
+
+static apr_status_t s_send_cache_file(device_table *spec,
+ query_string_param_t *query_string,
+ request_rec *r,
+ const char *tmpfile);
+
+static apr_status_t s_send_original_file(request_rec *r,
+ const char *originalfile);
+
+static apr_status_t s_header_only_cache_file(device_table *spec,
+ query_string_param_t *query_string,
+ request_rec *r,
+ const char *tmpfile);
+
+static query_string_param_t *s_get_query_string_param(request_rec *r);
+
+static unsigned short s_add_crc(const char *writedata, apr_size_t witebyte);
+
+static MagickWand *s_fixup_size(MagickWand *,
+ request_rec *r,
+ device_table *spec,
query_string_param_t *qsp);
-static MagickWand* s_fixup_color(MagickWand* magick_wand,
- request_rec* r,
- device_table* spec,
+static MagickWand *s_fixup_color(MagickWand *magick_wand,
+ request_rec *r,
+ device_table *spec,
img_conv_mode_t mode);
-static MagickWand* s_fixup_depth(MagickWand* magick_wand,
+static MagickWand *s_fixup_depth(MagickWand* magick_wand,
request_rec* r, device_table* spec);
-static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
- request_rec* r, device_table* spec);
+static MagickWand *s_img_down_sizing(MagickWand *magick_wand,
+ request_rec *r, device_table *spec);
-static MagickWand* s_add_copyright(MagickWand* magick_wand,
- request_rec* r,
- device_table* spec);
+static MagickWand *s_add_copyright(MagickWand *magick_wand,
+ request_rec *r,
+ device_table *spec);
-static char* s_create_blob_data(request_rec* r,
- device_table* spec,
- query_string_param_t* qsp,
- char* indata,
- apr_size_t* len);
+static char *s_create_blob_data(request_rec *r,
+ device_table *spec,
+ query_string_param_t *qsp,
+ char *indata,
+ apr_size_t *len);
-static int s_img_conv_format_from_file(request_rec* r,
- mod_chxj_config* conf,
- const char* user_agent,
- query_string_param_t* qsp,
- device_table* spec);
+static int s_img_conv_format_from_file(request_rec *r,
+ mod_chxj_config *conf,
+ const char *user_agent,
+ query_string_param_t *qsp,
+ device_table *spec);
+static int s_convert_to_jpeg(MagickWand *magick_wand, request_rec *r, device_table *spec);
+static int s_convert_to_png(MagickWand *maigck_wand, request_rec *r, device_table *spec);
+static int s_convert_to_gif(MagickWand *magick_wand, request_rec *r, device_table *spec);
+static int s_convert_to_bmp(MagickWand *magick_wand, request_rec *r, device_table *spec);
int
-chxj_img_conv_format_handler(request_rec* r)
+chxj_img_conv_format_handler(request_rec *r)
{
- mod_chxj_config* conf;
- query_string_param_t* qsp;
- char* user_agent;
- device_table* spec;
- chxjconvrule_entry* entryp;
+ mod_chxj_config *conf;
+ query_string_param_t *qsp;
+ char *user_agent;
+ device_table *spec;
+ chxjconvrule_entry *entryp;
DBG(r, "start chxj_img_conv_format_handler()");
- if ((*r->handler != 'c' && *r->handler != 'C')
- || (strcasecmp(r->handler, "chxj-picture")
- && strcasecmp(r->handler, "chxj-qrcode"))) {
+ if (r->handler && !STRCASEEQ('c','C',"chxj-picture",r->handler) && !STRCASEEQ('c','C',"chxj-qrcode",r->handler)) {
DBG(r, "end chxj_img_conv_format_handler()");
return DECLINED;
}
return DECLINED;
}
- if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF) {
+ if (STRCASEEQ('c','C',"chxj-qrcode",r->handler) && conf->image == CHXJ_IMG_OFF) {
return DECLINED;
}
-
/*------------------------------------------------------------------------*/
/* get UserAgent from http header */
/*------------------------------------------------------------------------*/
* @param len [i/o] It is length of former image binary data.
*/
char *
-chxj_exchange_image(request_rec *r, const char **src, apr_size_t *len)
+chxj_convert_image(request_rec *r, const char **src, apr_size_t *len)
{
mod_chxj_config *conf;
query_string_param_t *qsp;
char *conv_check;
chxjconvrule_entry *entryp;
- DBG(r, "start chxj_exchange_image()");
+ DBG(r, "start chxj_convert_image()");
conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
if (conv_check) {
qsp = s_get_query_string_param(r);
conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
if (conf == NULL) {
- DBG(r, "end chxj_exchange_image()");
+ DBG(r, "end chxj_convert_image()");
return NULL;
}
if (dst == NULL)
*len = 0;
- DBG(r, "end chxj_exchange_image()");
+ DBG(r, "end chxj_convert_image()");
return dst;
}
+
static int
s_img_conv_format_from_file(
- request_rec* r,
- mod_chxj_config* conf,
- const char* user_agent,
- query_string_param_t* qsp,
- device_table* spec)
+ request_rec *r,
+ mod_chxj_config *conf,
+ const char *user_agent,
+ query_string_param_t *qsp,
+ device_table *spec)
{
apr_status_t rv;
apr_finfo_t st;
apr_finfo_t cache_st;
- char* tmpfile;
+ char *tmpfile;
int try_count;
if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
if (rv != APR_SUCCESS)
return HTTP_NOT_FOUND;
+ apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
try_count = CACHE_RETRY_COUNT;
do {
rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
WRN(r, "cache retry failure....");
WRN(r, "cache file was deleted...");
}
- apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
DBG(r,"end chxj_img_conv_format");
static apr_status_t
-s_create_cache_file(request_rec* r,
- const char* tmpfile,
- device_table* spec,
- apr_finfo_t* st,
+s_create_cache_file(request_rec *r,
+ const char *tmpfile,
+ device_table *spec,
+ apr_finfo_t *st,
query_string_param_t *qsp,
mod_chxj_config *conf)
{
unsigned short crc;
img_conv_mode_t mode = qsp->mode;
- char* writedata = NULL;
- char* readdata = NULL;
+ char *writedata = NULL;
+ char *readdata = NULL;
- apr_file_t* fout;
- apr_file_t* fin;
- apr_finfo_t cache_dir_st;
+ apr_file_t *fout;
+ apr_file_t *fin;
+ apr_finfo_t cache_dir_st;
- MagickWand* magick_wand;
+ MagickWand *magick_wand;
+ int img_count;
- if ((*r->handler == 'c' || *r->handler == 'C')
- && strcasecmp(r->handler, "chxj-qrcode") == 0) {
+ if (STRCASEEQ('c','C',"chxj-qrcode",r->handler)) {
/*------------------------------------------------------------------------*/
- /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
+ /* QRCODE用のファイルの場合 */
/*------------------------------------------------------------------------*/
Doc doc;
- Node* root;
+ Node *root;
qr_code_t qrcode;
int sts;
}
else {
/*------------------------------------------------------------------------*/
- /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
+ /* 通常のイメージファイルの場合 */
/*------------------------------------------------------------------------*/
rv = apr_file_open(&fin,
r->filename,
return HTTP_NOT_FOUND;
}
+ /*------------------*/
+ /* for AnimationGIF */
+ /*------------------*/
+ img_count = MagickGetNumberImages(magick_wand);
+ DBG(r, "REQ[%X] img_count is [%d]", (unsigned int)(apr_size_t)r, img_count);
+ if (img_count > 1) {
+ MagickSetImageIndex(magick_wand, 0);
+ MagickWand *magick_wand2 = MagickGetImage(magick_wand);
+ DestroyMagickWand(magick_wand);
+ magick_wand = magick_wand2;
+ }
+
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ ERR(r, "mod_chxj: strip image failure.");
+ EXIT_MAGICK_ERROR();
+ return HTTP_NOT_FOUND;
+ }
+
if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
- /*
- * The size of the image is changed.
- */
- DBG(r,"call s_fixup_size()");
-
- if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
- return HTTP_NOT_FOUND;
+ int oldw = MagickGetImageWidth(magick_wand);
+ int oldh = MagickGetImageHeight(magick_wand);
+ int done_fixup_size = 0;
+ if ((qsp->mode == IMG_CONV_MODE_WALLPAPER && spec->wp_width < oldw && spec->wp_heigh < oldh)
+ || (qsp->mode != IMG_CONV_MODE_WALLPAPER && spec->width < oldw && spec->heigh < oldh)) {
+ /*
+ * The size of the image is changed.
+ */
+ DBG(r,"call s_fixup_size()");
+ if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
+ return HTTP_NOT_FOUND;
+
+ done_fixup_size = 1;
+ }
/*
* The colors of the image is changed.
*/
return HTTP_NOT_FOUND;
-
- DBG(r,"start convert and compression");
-
- if (spec->available_jpeg) {
- if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
- }
-
- if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
- EXIT_MAGICK_ERROR();
+ if (! done_fixup_size) {
+ /*
+ * The size of the image is changed.
+ */
+ DBG(r,"call s_fixup_size()");
+ if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
return HTTP_NOT_FOUND;
- }
-
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
- }
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return HTTP_NOT_FOUND;
-
- r->content_type = apr_psprintf(r->pool, "image/jpeg");
- DBG(r,"convert to jpg");
}
- else
- if (spec->available_png) {
-
- if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+
+ char *nowFormat = MagickGetImageFormat(magick_wand);
+ int fixFormatFlag = 0;
+ if (nowFormat) {
+ if (STRCASEEQ('g','G',"gif",nowFormat)) {
+ if (spec->available_gif) {
+ if (s_convert_to_gif(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
+ fixFormatFlag = 1;
+ }
}
-
- if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+ else if (STRCASEEQ('j','J',"jpg",nowFormat)||STRCASEEQ('j','J',"jpeg",nowFormat)) {
+ if (spec->available_jpeg) {
+ if (s_convert_to_jpeg(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
+ fixFormatFlag = 1;
+ }
}
-
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+ else if (STRCASEEQ('p','P',"png",nowFormat)) {
+ if (spec->available_png) {
+ if (s_convert_to_png(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
+ fixFormatFlag = 1;
+ }
}
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return HTTP_NOT_FOUND;
-
- r->content_type = apr_psprintf(r->pool, "image/png");
- DBG(r, "convert to png");
}
- else
- if (spec->available_gif) {
-
- if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
- }
-
- if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
- }
+
+ DBG(r,"start convert and compression");
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+ if (! fixFormatFlag) {
+ if (spec->available_jpeg) {
+ if (s_convert_to_jpeg(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
}
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return HTTP_NOT_FOUND;
-
- r->content_type = apr_psprintf(r->pool, "image/gif");
-
- DBG(r,"convert to gif");
- }
- else
- if (spec->available_bmp2 || spec->available_bmp4) {
-
- if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+ else if (spec->available_gif) {
+ if (s_convert_to_gif(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
}
+ else if (spec->available_png) {
+ if (s_convert_to_png(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
- if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
}
-
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return HTTP_NOT_FOUND;
+ else
+ if (spec->available_bmp2 || spec->available_bmp4) {
+ if (s_convert_to_bmp(magick_wand, r, spec)) {
+ return HTTP_NOT_FOUND;
+ }
}
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return HTTP_NOT_FOUND;
-
- r->content_type = apr_psprintf(r->pool, "image/bmp");
-
- DBG(r, "convert to bmp(unsupported)");
}
/*
}
-static char*
-s_create_blob_data(request_rec* r,
- device_table* spec,
- query_string_param_t *qsp,
- char* indata,
- apr_size_t* len)
+static int
+s_convert_to_jpeg(MagickWand *magick_wand, request_rec *r, device_table *spec)
{
- apr_size_t writebyte;
- unsigned short crc;
- img_conv_mode_t mode = qsp->mode;
+ if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
+ return -1;
+
+ r->content_type = apr_psprintf(r->pool, "image/jpeg");
+ ap_set_content_type(r, "image/jpeg");
+ DBG(r,"convert to jpg");
+ return 0;
+}
- char* writedata = NULL;
- char* dst = NULL;
- MagickWand* magick_wand;
+static int
+s_convert_to_png(MagickWand *magick_wand, request_rec *r, device_table *spec)
+{
+ if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
+ return -1;
+
+ r->content_type = apr_psprintf(r->pool, "image/png");
+ ap_set_content_type(r, "image/png");
+ DBG(r, "convert to png");
+ return 0;
+}
- magick_wand = NewMagickWand();
- if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
+static int
+s_convert_to_gif(MagickWand *magick_wand, request_rec *r, device_table *spec)
+{
+ if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
EXIT_MAGICK_ERROR();
- return NULL;
+ return -1;
}
+
+ if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
+ return -1;
+
+ r->content_type = apr_psprintf(r->pool, "image/gif");
+ ap_set_content_type(r, "image/gif");
+
+ DBG(r,"convert to gif");
+ return 0;
+}
- /*
- * The size of the image is changed.
- */
- DBG(r, "call s_fixup_size()");
- if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
- return NULL;
+static int
+s_convert_to_bmp(MagickWand *magick_wand, request_rec *r, device_table *spec)
+{
+ if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return -1;
+ }
+
+ if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
+ return -1;
+
+ r->content_type = apr_psprintf(r->pool, "image/bmp");
+ ap_set_content_type(r, "image/bmp");
+
+ DBG(r, "convert to bmp(unsupported)");
+ return 0;
+}
- /*
- * The colors of the image is changed.
- */
- DBG(r, "call s_fixup_color()");
- if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
- return NULL;
+static char *
+s_create_blob_data(request_rec *r,
+ device_table *spec,
+ query_string_param_t *qsp,
+ char *indata,
+ apr_size_t *len)
+{
+ apr_size_t writebyte;
+ unsigned short crc;
+ img_conv_mode_t mode = qsp->mode;
- /*
- * DEPTH of the image is changed.
- */
+ char *writedata = NULL;
+ char *dst = NULL;
+ MagickWand *magick_wand;
- DBG(r,"call s_fixup_depth()");
+ magick_wand = NewMagickWand();
- if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
+ if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
return NULL;
+ }
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ ERR(r, "mod_chxj: strip image failure.");
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
+ {
+ int oldw = MagickGetImageWidth(magick_wand);
+ int oldh = MagickGetImageHeight(magick_wand);
+ int done_fixup_size = 0;
+ if ((qsp->mode == IMG_CONV_MODE_WALLPAPER && spec->wp_width < oldw && spec->wp_heigh < oldh)
+ || (qsp->mode != IMG_CONV_MODE_WALLPAPER && spec->width < oldw && spec->heigh < oldh)) {
+ /*
+ * The size of the image is changed.
+ */
+ DBG(r,"call s_fixup_size()");
- DBG(r,"start convert and compression");
-
- if (spec->available_jpeg) {
- if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
- }
+ if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL) {
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
- if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ done_fixup_size = 1;
}
+ /*
+ * The colors of the image is changed.
+ */
+ DBG(r,"call s_fixup_color()");
- if (MagickStripImage(magick_wand) == MagickFalse) {
+ if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL) {
EXIT_MAGICK_ERROR();
return NULL;
}
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return NULL;
-
- r->content_type = apr_psprintf(r->pool, "image/jpeg");
+ /*
+ * DEPTH of the image is changed.
+ */
+ DBG(r,"call s_fixup_depth()");
- DBG(r, "convert to jpg");
- }
- else
- if (spec->available_png) {
- if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
+ if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL) {
EXIT_MAGICK_ERROR();
return NULL;
}
- if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
- }
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ if (! done_fixup_size) {
+ /*
+ * The size of the image is changed.
+ */
+ DBG(r,"call s_fixup_size()");
+ if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL) {
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
}
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return NULL;
-
- r->content_type = apr_psprintf(r->pool, "image/png");
-
- DBG(r,"convert to png");
}
- else
- if (spec->available_gif) {
- if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ char *nowFormat = MagickGetImageFormat(magick_wand);
+ int fixFormatFlag = 0;
+ if (nowFormat) {
+ if (STRCASEEQ('g','G',"gif",nowFormat)) {
+ if (spec->available_gif) {
+ if (s_convert_to_gif(magick_wand, r, spec)) {
+ return NULL;
+ }
+ fixFormatFlag = 1;
+ }
}
-
- if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ else if (STRCASEEQ('j','J',"jpg",nowFormat)||STRCASEEQ('j','J',"jpeg",nowFormat)) {
+ if (spec->available_jpeg) {
+ if (s_convert_to_jpeg(magick_wand, r, spec)) {
+ return NULL;
+ }
+ fixFormatFlag = 1;
+ }
}
-
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ else if (STRCASEEQ('p','P',"png",nowFormat)) {
+ if (spec->available_png) {
+ if (s_convert_to_png(magick_wand, r, spec)) {
+ return NULL;
+ }
+ fixFormatFlag = 1;
+ }
}
+ }
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return NULL;
-
- r->content_type = apr_psprintf(r->pool, "image/gif");
+ DBG(r,"start convert and compression");
- DBG(r,"convert to gif");
- }
- else
- if (spec->available_bmp2 || spec->available_bmp4) {
- if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ if (!fixFormatFlag) {
+ if (spec->available_jpeg) {
+ if (s_convert_to_jpeg(magick_wand, r, spec)) {
+ return NULL;
+ }
}
-
- if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ else if (spec->available_png) {
+ if (s_convert_to_png(magick_wand, r, spec)) {
+ return NULL;
+ }
}
-
- if (MagickStripImage(magick_wand) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ else if (spec->available_gif) {
+ if (s_convert_to_gif(magick_wand, r, spec)) {
+ return NULL;
+ }
+ }
+ else if (spec->available_bmp2 || spec->available_bmp4) {
+ if (s_convert_to_bmp(magick_wand, r, spec)) {
+ return NULL;
+ }
}
-
- if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
- return NULL;
-
- r->content_type = apr_psprintf(r->pool, "image/bmp");
-
- DBG(r,"convert to bmp(unsupported)");
}
/*--------------------------------------------------------------------------*/
/* Add Comment (Copyright and so on.) */
return dst;
}
-static MagickWand*
-s_fixup_size(MagickWand* magick_wand,
- request_rec* r,
- device_table* spec,
- query_string_param_t *qsp)
+
+static MagickWand *
+s_fixup_size(MagickWand *magick_wand,
+ request_rec *r,
+ device_table *spec,
+ query_string_param_t *qsp)
{
img_conv_mode_t mode = qsp->mode;
int oldw;
break;
}
+ if (neww == 0) neww = 1;
+ if (newh == 0) newh = 1;
+
if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
DBG(r,"convert width=[%d --> %d]", oldw, neww);
DBG(r,"convert heigh=[%d --> %d]", oldh, newh);
return magick_wand;
}
-static MagickWand*
-s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t UNUSED(mode))
+
+static MagickWand *
+s_fixup_color(MagickWand *magick_wand, request_rec *r, device_table *spec, img_conv_mode_t UNUSED(mode))
{
DBG(r,"start chxj_fixup_clor()");
return magick_wand;
}
+ unsigned long colors = MagickGetImageColors(magick_wand);
+ DBG(r, "now color:[%ld] spec->color:[%ld]", colors, (unsigned long)spec->color);
+ if (colors < (unsigned long)spec->color) {
+ DBG(r, "Pass s_fixup_color proc. color:[%ld] spec->color:[%d]", colors, spec->color);
+ return magick_wand;
+ }
+
if (spec->color >= 256) {
DBG(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
-static MagickWand*
-s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
+static MagickWand *
+s_fixup_depth(MagickWand *magick_wand, request_rec *r, device_table *spec)
{
if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
DBG(r, "Pass s_fixup_depth proc");
}
-static MagickWand*
-s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
+static MagickWand *
+s_add_copyright(MagickWand *magick_wand, request_rec *r, device_table *spec)
{
- mod_chxj_config* conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+ mod_chxj_config *conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
DBG(r, "Pass add_copiright proc");
DBG(r, "Add COPYRIGHT [%s]", conf->image_copyright);
- if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
+ if (spec->html_spec_type == CHXJ_SPEC_Jhtml
+ || spec->html_spec_type == CHXJ_SPEC_Jxhtml) {
apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
if (MagickCommentImage(magick_wand,
apr_psprintf(r->pool,
return NULL;
}
-static MagickWand*
-s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
+static MagickWand *
+s_img_down_sizing(MagickWand *magick_wand, request_rec *r, device_table *spec)
{
MagickBooleanType status;
- unsigned long quality = 70;
- apr_size_t writebyte = 0;
- char* writedata;
- apr_size_t prev_size = 0;
- int revers_flag = 0;
-
- writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
+ unsigned long quality = 70;
+ apr_size_t writebyte = 0;
+ char *writedata;
+ apr_size_t prev_size = 0;
+ int revers_flag = 0;
+ char *fmt;
+ int fmt_type = 0;
+
+ writedata = (char *)MagickGetImageBlob(magick_wand, &writebyte);
prev_size = writebyte;
- do {
- if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
- }
-
- writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
- if (writebyte >= prev_size || revers_flag) {
- DBG(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
- revers_flag = 1;
- quality += 10;
- if (quality > 100) {
- if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+
+ fmt = MagickGetImageFormat(magick_wand);
+ if (fmt) {
+ if (STRCASEEQ('j','J',"jpg",fmt)) fmt_type = 1;
+ if (STRCASEEQ('p','P',"png",fmt)) fmt_type = 2;
+ if (STRCASEEQ('g','G',"gif",fmt)) fmt_type = 3;
+ if (STRCASEEQ('b','B',"bmp",fmt)) fmt_type = 4;
+ }
+ if (fmt_type == 1) {
+ do {
+ if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
+
+ writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
+ if (writebyte >= prev_size || revers_flag) {
+ DBG(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
+ revers_flag = 1;
+ quality += 10;
+ if (quality > 100) {
+ if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
+ break;
}
- break;
+ prev_size = writebyte;
+ continue;
}
- prev_size = writebyte;
- continue;
+
+ DBG(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
+
+ if (spec->cache == 0)
+ break;
+
+ if (writebyte <= (unsigned int)spec->cache)
+ break;
+
+ quality -= 10;
+
+ if (quality == 0 || quality > 100)
+ break;
+
}
-
- DBG(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
-
- if (spec->cache == 0)
- break;
-
- if (writebyte <= (unsigned int)spec->cache)
- break;
-
- quality -= 10;
-
- if (quality == 0 || quality > 100)
- break;
-
+ while (1);
}
- while (1);
if (spec->cache > 0
if (now_color <= 2) break;
+
if (now_color >= 8) {
status = MagickQuantizeImage(magick_wand,
now_color,
EXIT_MAGICK_ERROR();
return NULL;
}
-
- if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
- EXIT_MAGICK_ERROR();
- return NULL;
+ if (fmt_type != 2) {
+ if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return NULL;
+ }
}
-
writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
DBG(r,"now_color=[%ld] size=[%d]", (long)now_color, (int)writebyte);
return magick_wand;
}
+
static apr_status_t
-s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
+s_send_cache_file(device_table *UNUSED(spec), query_string_param_t *query_string, request_rec *r, const char *tmpfile)
{
apr_status_t rv;
apr_finfo_t st;
- apr_file_t* fout;
+ apr_file_t *fout;
apr_size_t sendbyte;
- char* contentLength;
+ char *contentLength;
rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
if (rv != APR_SUCCESS)
DBG(r, "offset:[%ld]", query_string->offset);
DBG(r, "count:[%ld]", query_string->count);
- if (spec->available_jpeg) {
- r->content_type = apr_psprintf(r->pool, "image/jpeg");
- }
- else
- if (spec->available_png) {
- r->content_type = apr_psprintf(r->pool, "image/png");
- }
- else
- if (spec->available_gif) {
- r->content_type = apr_psprintf(r->pool, "image/gif");
- }
- else
- if (spec->available_bmp2 || spec->available_bmp4) {
- r->content_type = apr_psprintf(r->pool, "image/bmp");
- }
-
if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
DBG(r,"Content-Length:[%d]", (int)st.size);
-
+ MagickWand *magick_wand = NewMagickWand();
+ if (MagickReadImage(magick_wand,tmpfile) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return HTTP_NOT_FOUND;
+ }
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ ERR(r, "mod_chxj: strip image failure.");
+ EXIT_MAGICK_ERROR();
+ return HTTP_NOT_FOUND;
+ }
+ char *nowFormat = MagickGetImageFormat(magick_wand);
+ DestroyMagickWand(magick_wand);
+ if (nowFormat) {
+ if (STRCASEEQ('j','J',"jpeg",nowFormat) || STRCASEEQ('j','J',"jpg",nowFormat)) {
+ DBG(r, "detect cache file => jpg.");
+ ap_set_content_type(r, "image/jpeg");
+ }
+ else if (STRCASEEQ('p','P',"png", nowFormat)) {
+ DBG(r, "detect cache file => png.");
+ ap_set_content_type(r, "image/png");
+ }
+ else if (STRCASEEQ('g','G',"gif", nowFormat)) {
+ DBG(r, "detect cache file => gif.");
+ ap_set_content_type(r, "image/gif");
+ }
+ else if (STRCASEEQ('b','B',"bmp", nowFormat)) {
+ DBG(r, "detect cache file => bmp.");
+ ap_set_content_type(r, "image/bmp");
+ }
+ else {
+ ERR(r, "detect unknown file");
+ return HTTP_NOT_FOUND;
+ }
+ }
rv = apr_file_open(&fout, tmpfile,
APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
if (rv != APR_SUCCESS) {
DBG(r, "cache file open failed[%s]", tmpfile);
return HTTP_NOT_FOUND;
}
-
ap_send_fd(fout, r, 0, st.size, &sendbyte);
apr_file_close(fout);
ap_rflush(r);
}
else
if (query_string->mode == IMG_CONV_MODE_EZGET) {
- char* name = apr_pstrdup(r->pool, basename(r->filename));
+ char *name = apr_pstrdup(r->pool, basename(r->filename));
name[strlen(name)-4] = 0;
if (strcasecmp(r->content_type, "image/jpeg") == 0) {
static apr_status_t
-s_send_original_file(request_rec* r, const char* originalfile)
+s_send_original_file(request_rec *r, const char *originalfile)
{
apr_status_t rv;
apr_finfo_t st;
- apr_file_t* fout;
+ apr_file_t *fout;
apr_size_t sendbyte = 0;
rv = apr_stat(&st, originalfile, APR_FINFO_MIN, r->pool);
return OK;
}
+
static apr_status_t
-s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
+s_header_only_cache_file(device_table *UNUSED(spec), query_string_param_t *query_string, request_rec *r, const char *tmpfile)
{
apr_status_t rv;
apr_finfo_t st;
- char* contentLength;
+ char *contentLength;
rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
if (rv != APR_SUCCESS)
DBG(r, "offset:[%ld]", query_string->offset);
DBG(r, "count:[%ld]", query_string->count);
- if (spec->available_jpeg) {
- r->content_type = apr_psprintf(r->pool, "image/jpeg");
- }
- else
- if (spec->available_png) {
- r->content_type = apr_psprintf(r->pool, "image/png");
- }
- else
- if (spec->available_gif) {
- r->content_type = apr_psprintf(r->pool, "image/gif");
- }
- else
- if (spec->available_bmp2 || spec->available_bmp4) {
- r->content_type = apr_psprintf(r->pool, "image/bmp");
- }
-
if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
+
+ MagickWand *magick_wand = NewMagickWand();
+ if (MagickReadImage(magick_wand,tmpfile) == MagickFalse) {
+ EXIT_MAGICK_ERROR();
+ return HTTP_NOT_FOUND;
+ }
+ if (MagickStripImage(magick_wand) == MagickFalse) {
+ ERR(r, "mod_chxj: strip image failure.");
+ EXIT_MAGICK_ERROR();
+ return HTTP_NOT_FOUND;
+ }
+ char *nowFormat = MagickGetImageFormat(magick_wand);
+ DestroyMagickWand(magick_wand);
+ if (nowFormat) {
+ if (STRCASEEQ('j','J',"jpeg",nowFormat) || STRCASEEQ('j','J',"jpg",nowFormat)) {
+ DBG(r, "detect cache file => jpg.");
+ ap_set_content_type(r, "image/jpeg");
+ }
+ else if (STRCASEEQ('p','P',"png", nowFormat)) {
+ DBG(r, "detect cache file => png.");
+ ap_set_content_type(r, "image/png");
+ }
+ else if (STRCASEEQ('g','G',"gif", nowFormat)) {
+ DBG(r, "detect cache file => gif.");
+ ap_set_content_type(r, "image/gif");
+ }
+ else if (STRCASEEQ('b','B',"bmp", nowFormat)) {
+ DBG(r, "detect cache file => bmp.");
+ ap_set_content_type(r, "image/bmp");
+ }
+ else {
+ ERR(r, "detect unknown file");
+ return HTTP_NOT_FOUND;
+ }
+ }
DBG(r,"Content-Length:[%d]", (int)st.size);
}
else
if (query_string->mode == IMG_CONV_MODE_EZGET) {
- char* name = apr_pstrdup(r->pool, basename(r->filename));
+ char *name = apr_pstrdup(r->pool, basename(r->filename));
name[strlen(name)-4] = 0;
if (strcasecmp(r->content_type, "image/jpeg") == 0) {
}
}
-static char*
+
+static char *
s_create_workfile_name(
- request_rec* r,
- mod_chxj_config* conf,
- const char* user_agent,
+ request_rec *r,
+ mod_chxj_config *conf,
+ const char *user_agent,
query_string_param_t *qsp)
{
- int ii;
- int jj;
- int len;
- char* w = apr_palloc(r->pool, 256);
- char* fname;
+ int ii;
+ int jj;
+ int len;
+ char *w = apr_palloc(r->pool, 256);
+ char *fname;
char *new_user_agent;
-
s_init_serial_pattern(r->server->process->pool);
/* for DoCoMo */
fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, new_user_agent);
DBG(r, "mode=thumbnail [%s]", fname);
break;
+
case IMG_CONV_MODE_WALLPAPER:
case IMG_CONV_MODE_EZGET:
fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, new_user_agent);
DBG(r, "mode=WallPaper [%s]", fname);
break;
+
case IMG_CONV_MODE_NORMAL:
default:
static unsigned short
-s_add_crc(const char* writedata, apr_size_t writebyte)
+s_add_crc(const char *writedata, apr_size_t writebyte)
{
unsigned short crc = 0xffff;
apr_size_t ii;
return crc;
}
+
int
chxj_trans_name(request_rec *r)
{
- const char* ccp;
- char* docroot;
- int len;
- apr_finfo_t st;
- apr_status_t rv;
- mod_chxj_config* conf;
- int ii;
- char* ext[] = {
+ const char *ccp;
+ char *docroot;
+ int len;
+ apr_finfo_t st;
+ apr_status_t rv;
+ mod_chxj_config *conf;
+ int ii;
+ char *ext[] = {
"jpg",
"jpeg",
"png",
"bmp",
"gif",
- "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
+ "qrc", /* QRCode出力用ファイルの拡張子 */
"",
};
- char* fname;
- char* idx;
- char* filename_sv;
+ char *fname = NULL;
+ char *idx;
+ char *filename_sv;
int do_ext_check = TRUE;
int next_ok = FALSE;
*
* @param r [i]
*/
-static query_string_param_t*
+static query_string_param_t *
s_get_query_string_param(request_rec *r)
{
- char* pair;
- char* name;
- char* value;
- char* pstate;
- char* vstate;
- char* s;
- query_string_param_t* param;
+ char *pair;
+ char *name;
+ char *value;
+ char *pstate;
+ char *vstate;
+ char *s;
+ query_string_param_t *param;
s = apr_pstrdup(r->pool, r->parsed_uri.query);
param = apr_palloc(r->pool, sizeof(query_string_param_t));