Rev 8897 | 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 | |||
8897 | bpr | 24 | /* same in Flydraw/flylines.c */ |
25 | |||
10 | reyssat | 26 | int getcolor(int r, int g, int b) |
27 | { |
||
28 | int col; |
||
11121 | georgesk | 29 | if(r>255) r=255; |
30 | if(r<0) r=0; |
||
31 | if(g>255) g=255; |
||
32 | if(g<0) g=0; |
||
33 | if(b>255) b=255; |
||
34 | if(b<0) b=0; |
||
10 | reyssat | 35 | col=gdImageColorExact(image, r, g, b); |
36 | if(col==-1) col=gdImageColorAllocate(image,r,g,b); |
||
37 | return col; |
||
38 | } |
||
39 | |||
40 | void createimage(int xsize, int ysize) |
||
41 | { |
||
8195 | bpr | 42 | if(xsize<=0 || ysize<=0) texgif_error("Bad image size."); |
43 | if(xsize*ysize>IMAGE_SIZE_LIMIT) texgif_error("Image size too big."); |
||
10 | reyssat | 44 | image=gdImageCreate(xsize,ysize); |
8195 | bpr | 45 | if(image==NULL) texgif_error("Image creation failure"); |
10 | reyssat | 46 | color_white=gdImageColorAllocate(image,255,255,255); |
47 | color_black=gdImageColorAllocate(image,0,0,0); |
||
48 | color_bounder=gdImageColorAllocate(image,1,2,3); |
||
49 | gdImageColorTransparent(image,color_white); |
||
7076 | obado | 50 | printf("Created image: %dx%d\n",xsize,ysize); |
10 | reyssat | 51 | } |
52 | |||
53 | void saveimage() |
||
54 | { |
||
55 | int xsize, ysize; |
||
56 | int white2; |
||
57 | FILE *outf; |
||
58 | char *ff; |
||
59 | if(image==NULL) return; |
||
60 | xsize=image->sx; ysize=image->sy; |
||
61 | ff=outfile; while(isspace(*ff)) ff++; |
||
62 | for(; *outfile && *outfile!='\n';outfile++); |
||
63 | if(*outfile) *outfile++=0; |
||
8195 | bpr | 64 | outf=fopen(ff,"w"); if(outf==NULL) texgif_error("unable to create gif output."); |
10 | reyssat | 65 | printf("Output to %s.\n",ff); |
66 | if(compressratio==1) gdImageGif(image,outf); |
||
67 | else { |
||
7076 | obado | 68 | gdImagePtr image2; |
69 | int x2, y2; |
||
70 | x2=(xsize+1)/2; y2=(ysize+1)/2; |
||
71 | image2=gdImageCreate(x2,y2); |
||
72 | white2=gdImageColorAllocate(image2,255,255,255); |
||
73 | gdImageColorTransparent(image2,white2); |
||
74 | gdImageCopyResized(image2,image,0,0,0,0,x2,y2,xsize,ysize); |
||
75 | gdImageGif(image2,outf); gdImageDestroy(image2); |
||
10 | reyssat | 76 | } |
77 | fclose(outf); |
||
78 | gdImageDestroy(image); image=NULL; |
||
79 | } |
||
80 | |||
81 | int paintfont(FONT *f, int ch, int x, int y, int color) |
||
82 | { |
||
83 | int i,j, xlen, ylen, xsize; |
||
84 | char *buf; |
||
85 | ch-=f->bc; x+=f->fh[ch].xstart; y+=f->fh[ch].ystart; |
||
86 | xlen=f->fh[ch].xmax; ylen=f->fh[ch].ymax; |
||
87 | xsize=(xlen+7)/8; buf=f->data+f->fh[ch].start; |
||
88 | for(j=0;j<ylen;j++) for(i=0;i<xlen;i++) { |
||
7076 | obado | 89 | if((buf[j*xsize+(i>>3)]&(1<<(i&7)))!=0) |
90 | gdImageSetPixel(image,x+i,y+j,color); |
||
10 | reyssat | 91 | } |
92 | return f->fh[ch].w; |
||
93 | } |
||
94 | |||
7076 | obado | 95 | /* Make color according to string indication */ |
10 | reyssat | 96 | void makecolor(char *p) |
97 | { |
||
98 | int t, r,g,b; |
||
99 | char *p2; |
||
8103 | bpr | 100 | |
10 | reyssat | 101 | p=find_word_start(p); r=g=b=0; |
7076 | obado | 102 | p2=strchr(p,','); |
103 | if(p2==NULL) { /* color name */ |
||
104 | *find_word_end(p)=0; |
||
105 | t=search_list(colors,colorno,sizeof(colors[0]),p); |
||
106 | if(t<0) return; |
||
107 | r=colors[t].r; g=colors[t].g; b=colors[t].b; |
||
10 | reyssat | 108 | } |
7076 | obado | 109 | else { /* rgb values */ |
110 | *p2++=0; |
||
111 | r=atoi(p); p=find_word_start(p2); |
||
112 | p2=strchr(p,','); if(p2==NULL) p2=p+strlen(p); else *p2++=0; |
||
113 | g=atoi(p); b=atoi(p2); |
||
10 | reyssat | 114 | } |
115 | t=getcolor(r,g,b); |
||
116 | if(t!=-1) currentcolor=t; |
||
117 | } |