OSDN Git Service

* Fixed BUG.
[modchxj/mod_chxj.git] / src / chxj_img_conv.c
1 /*
2  * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include "mod_chxj.h"
18
19
20 char * 
21 chxj_img_conv(
22   request_rec  *r, 
23   device_table *spec, 
24   const char   *s)
25 {
26   char *dst = apr_pstrdup(r->pool, s);
27   if (spec) {
28     switch (spec->color) {
29     case 2       : dst = apr_pstrcat(r->pool, dst,".10", NULL); break;
30     case 4       : dst = apr_pstrcat(r->pool, dst,".20", NULL); break;
31     case 256     : dst = apr_pstrcat(r->pool, dst,".30", NULL); break;
32     case 4096    : dst = apr_pstrcat(r->pool, dst,".40", NULL); break;
33     case 65536   : dst = apr_pstrcat(r->pool, dst,".50", NULL); break;
34     case 262144  : dst = apr_pstrcat(r->pool, dst,".60", NULL); break;
35     case 15680000: dst = apr_pstrcat(r->pool, dst,".70", NULL); break;
36     default:       dst = apr_pstrcat(r->pool, dst,".30", NULL); break;
37     }
38
39     if (spec->available_jpeg)
40       return apr_pstrcat(r->pool, dst,".jpg", NULL);
41
42     if (spec->available_png)
43       return apr_pstrcat(r->pool, dst,".png", NULL);
44
45     if (spec->available_gif)
46       return apr_pstrcat(r->pool, dst, ".gif", NULL);
47
48     if (spec->available_bmp4 || spec->available_bmp2)
49       return apr_pstrcat(r->pool, dst, ".bmp", NULL);
50   }
51
52   return dst;
53 }
54
55 char *
56 chxj_img_rewrite_parameter(
57     request_rec *r,
58     mod_chxj_config *conf,
59     const char *href)
60 {
61   if (conf->image_rewrite == CHXJ_IMG_REWRITE_ON &&
62       conf->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_TAG){
63     if(strstr(href,"?")){
64       return apr_pstrcat(r->pool,href,"&",CHXJ_IMG_REWRITE_URL_STRING,NULL);
65     }
66     else{
67       return apr_pstrcat(r->pool,href,"?",CHXJ_IMG_REWRITE_URL_STRING,NULL);
68     }
69   }
70   else{
71     return apr_pstrcat(r->pool,href,NULL);
72   }
73 }