~ubuntu-branches/ubuntu/wily/ntop/wily-proposed

« back to all changes in this revision

Viewing changes to gdchart0.94c/gd-1.8.3/gdxpm.c

  • Committer: Bazaar Package Importer
  • Author(s): Dennis Schoen
  • Date: 2002-04-12 11:38:47 UTC
  • Revision ID: james.westby@ubuntu.com-20020412113847-4k4yydw0pzybc6g8
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
add ability to load xpm files to gd, requires the xpm
 
3
library.
 
4
Caolan.McNamara@ul.ie 
 
5
http://www.csn.ul.ie/~caolan
 
6
*/
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include "gd.h"
 
10
 
 
11
#ifndef HAVE_XPM
 
12
gdImagePtr gdImageCreateFromXpm(char *filename)
 
13
        {
 
14
        fprintf(stderr,"libgd was not built with xpm support\n");
 
15
        return(NULL);
 
16
        }
 
17
 
 
18
#else
 
19
 
 
20
#include "xpm.h"
 
21
 
 
22
gdImagePtr gdImageCreateFromXpm(char *filename)
 
23
        {
 
24
        XpmInfo info;
 
25
        XpmImage image;
 
26
        int i,j,k,number;
 
27
        char buf[5];
 
28
        gdImagePtr im = 0;
 
29
        char *apixel;
 
30
        int *pointer;
 
31
        int red=0,green=0,blue=0,color=0;
 
32
        int *colors;
 
33
        int ret;
 
34
 
 
35
        ret = XpmReadFileToXpmImage(filename,&image,&info);
 
36
        if (ret != XpmSuccess)
 
37
                return 0;
 
38
 
 
39
        if (!(im = gdImageCreate(image.width, image.height))) 
 
40
            return 0;
 
41
 
 
42
        number = image.ncolors;
 
43
        colors = (int*)malloc(sizeof(int) * number);
 
44
        if (colors == NULL)
 
45
                return(0);
 
46
        for (i = 0; i < number; i++) 
 
47
                {
 
48
                switch(strlen(image.colorTable[i].c_color))
 
49
                        {
 
50
                        case 4:
 
51
                                buf[1] = '\0';
 
52
                                buf[0] = image.colorTable[i].c_color[1];
 
53
                                red = strtol(buf,NULL,16);
 
54
 
 
55
                                buf[0] = image.colorTable[i].c_color[3];
 
56
                                green = strtol(buf,NULL,16);
 
57
 
 
58
                                buf[0] = image.colorTable[i].c_color[5];
 
59
                                blue = strtol(buf,NULL,16);
 
60
                                break;
 
61
                        case 7:
 
62
                                buf[2] = '\0';
 
63
                                buf[0] = image.colorTable[i].c_color[1];
 
64
                                buf[1] = image.colorTable[i].c_color[2];
 
65
                                red = strtol(buf,NULL,16);
 
66
 
 
67
                                buf[0] = image.colorTable[i].c_color[3];
 
68
                                buf[1] = image.colorTable[i].c_color[4];
 
69
                                green = strtol(buf,NULL,16);
 
70
 
 
71
                                buf[0] = image.colorTable[i].c_color[5];
 
72
                                buf[1] = image.colorTable[i].c_color[6];
 
73
                                blue = strtol(buf,NULL,16);
 
74
                                break;
 
75
                        case 10:
 
76
                                buf[3] = '\0';
 
77
                                buf[0] = image.colorTable[i].c_color[1];
 
78
                                buf[1] = image.colorTable[i].c_color[2];
 
79
                                buf[2] = image.colorTable[i].c_color[3];
 
80
                                red = strtol(buf,NULL,16);
 
81
                                red /= 64;
 
82
 
 
83
                                buf[0] = image.colorTable[i].c_color[4];
 
84
                                buf[1] = image.colorTable[i].c_color[5];
 
85
                                buf[2] = image.colorTable[i].c_color[6];
 
86
                                green = strtol(buf,NULL,16);
 
87
                                green /= 64;
 
88
 
 
89
                                buf[0] = image.colorTable[i].c_color[7];
 
90
                                buf[1] = image.colorTable[i].c_color[8];
 
91
                                buf[2] = image.colorTable[i].c_color[9];
 
92
                                blue = strtol(buf,NULL,16);
 
93
                                blue /= 64;
 
94
                                break;
 
95
                        case 13:
 
96
                                buf[4] = '\0';
 
97
                                buf[0] = image.colorTable[i].c_color[1];
 
98
                                buf[1] = image.colorTable[i].c_color[2];
 
99
                                buf[2] = image.colorTable[i].c_color[3];
 
100
                                buf[3] = image.colorTable[i].c_color[4];
 
101
                                red = strtol(buf,NULL,16);
 
102
                                red /= 256;
 
103
 
 
104
                                buf[0] = image.colorTable[i].c_color[5];
 
105
                                buf[1] = image.colorTable[i].c_color[6];
 
106
                                buf[2] = image.colorTable[i].c_color[7];
 
107
                                buf[3] = image.colorTable[i].c_color[8];
 
108
                                green = strtol(buf,NULL,16);
 
109
                                green /= 256;
 
110
 
 
111
                                buf[0] = image.colorTable[i].c_color[9];
 
112
                                buf[1] = image.colorTable[i].c_color[10];
 
113
                                buf[2] = image.colorTable[i].c_color[11];
 
114
                                buf[3] = image.colorTable[i].c_color[12];
 
115
                                blue = strtol(buf,NULL,16);
 
116
                                blue /= 256;
 
117
                                break;
 
118
                        }
 
119
 
 
120
 
 
121
                colors[i] = gdImageColorResolve(im,red,green,blue);
 
122
                if (colors[i] == -1)
 
123
                        fprintf(stderr,"ARRRGH\n");
 
124
                }
 
125
 
 
126
        apixel = (char *)malloc(image.cpp+1);
 
127
        if (apixel == NULL)
 
128
                return(0);
 
129
        apixel[image.cpp] = '\0';
 
130
 
 
131
        pointer = image.data;
 
132
        for(i=0;i<image.height;i++)
 
133
                {
 
134
                for(j=0;j<image.width;j++)
 
135
                        {
 
136
                        k = *pointer++;
 
137
                        gdImageSetPixel(im,j,i,colors[k]);
 
138
                        }
 
139
                }
 
140
        free(apixel);
 
141
        free(colors);
 
142
        return(im);
 
143
        }
 
144
#endif