Subversion Repositories wimsdev

Rev

Rev 8103 | Rev 8897 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 2002-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
18
/* tex 2 gif translator, image manipulating routines */
8103 bpr 19
#include "texgif.h"
10 reyssat 20
 
21
gdImagePtr image=NULL;
22
int color_white, color_black, color_bounder;
23
 
24
int getcolor(int r, int g, int b)
25
{
26
    int col;
27
    if(r>255) r=255; if(r<0) r=0;
28
    if(g>255) g=255; if(g<0) g=0;
29
    if(b>255) b=255; if(b<0) b=0;
30
    col=gdImageColorExact(image, r, g, b);
31
    if(col==-1) col=gdImageColorAllocate(image,r,g,b);
32
    return col;
33
}
34
 
35
void createimage(int xsize, int ysize)
36
{
8195 bpr 37
    if(xsize<=0 || ysize<=0) texgif_error("Bad image size.");
38
    if(xsize*ysize>IMAGE_SIZE_LIMIT) texgif_error("Image size too big.");
10 reyssat 39
    image=gdImageCreate(xsize,ysize);
8195 bpr 40
    if(image==NULL) texgif_error("Image creation failure");
10 reyssat 41
    color_white=gdImageColorAllocate(image,255,255,255);
42
    color_black=gdImageColorAllocate(image,0,0,0);
43
    color_bounder=gdImageColorAllocate(image,1,2,3);
44
    gdImageColorTransparent(image,color_white);
7076 obado 45
    printf("Created image: %dx%d\n",xsize,ysize);
10 reyssat 46
}
47
 
48
void saveimage()
49
{
50
    int xsize, ysize;
51
    int white2;
52
    FILE *outf;
53
    char *ff;
54
    if(image==NULL) return;
55
    xsize=image->sx; ysize=image->sy;
56
    ff=outfile; while(isspace(*ff)) ff++;
57
    for(; *outfile && *outfile!='\n';outfile++);
58
    if(*outfile) *outfile++=0;
8195 bpr 59
    outf=fopen(ff,"w"); if(outf==NULL) texgif_error("unable to create gif output.");
10 reyssat 60
    printf("Output to %s.\n",ff);
61
    if(compressratio==1) gdImageGif(image,outf);
62
    else {
7076 obado 63
        gdImagePtr image2;
64
        int x2, y2;
65
        x2=(xsize+1)/2; y2=(ysize+1)/2;
66
        image2=gdImageCreate(x2,y2);
67
        white2=gdImageColorAllocate(image2,255,255,255);
68
        gdImageColorTransparent(image2,white2);
69
        gdImageCopyResized(image2,image,0,0,0,0,x2,y2,xsize,ysize);
70
        gdImageGif(image2,outf); gdImageDestroy(image2);
10 reyssat 71
    }
72
    fclose(outf);
73
    gdImageDestroy(image); image=NULL;
74
}
75
 
76
int paintfont(FONT *f, int ch, int x, int y, int color)
77
{
78
    int i,j, xlen, ylen, xsize;
79
    char *buf;
80
    ch-=f->bc; x+=f->fh[ch].xstart; y+=f->fh[ch].ystart;
81
    xlen=f->fh[ch].xmax; ylen=f->fh[ch].ymax;
82
    xsize=(xlen+7)/8; buf=f->data+f->fh[ch].start;
83
    for(j=0;j<ylen;j++) for(i=0;i<xlen;i++) {
7076 obado 84
        if((buf[j*xsize+(i>>3)]&(1<<(i&7)))!=0)
85
            gdImageSetPixel(image,x+i,y+j,color);
10 reyssat 86
    }
87
    return f->fh[ch].w;
88
}
89
 
7076 obado 90
    /* Make color according to string indication */
10 reyssat 91
void makecolor(char *p)
92
{
93
    int t, r,g,b;
94
    char *p2;
8103 bpr 95
 
10 reyssat 96
    p=find_word_start(p); r=g=b=0;
7076 obado 97
    p2=strchr(p,',');
98
    if(p2==NULL) {  /* color name */
99
        *find_word_end(p)=0;
100
        t=search_list(colors,colorno,sizeof(colors[0]),p);
101
        if(t<0) return;
102
        r=colors[t].r; g=colors[t].g; b=colors[t].b;
10 reyssat 103
    }
7076 obado 104
    else {  /* rgb values */
105
        *p2++=0;
106
        r=atoi(p); p=find_word_start(p2);
107
        p2=strchr(p,','); if(p2==NULL) p2=p+strlen(p); else *p2++=0;
108
        g=atoi(p); b=atoi(p2);
10 reyssat 109
    }
110
    t=getcolor(r,g,b);
111
    if(t!=-1) currentcolor=t;
112
}