1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
typedef struct _RunlengthPacket
{
unsigned short
red,
green,
blue,
length;
unsigned short
index;
} RunlengthPacket;
typedef struct _Image
{
int
status,
temporary;
char
filename[1664 ];
long int
filesize;
int
pipe;
char
magick[1664 ],
*comments,
*label,
*text;
unsigned int
matte;
unsigned int
columns,
rows,
depth;
unsigned int
scene,
number_scenes;
char
*montage,
*directory;
unsigned int
colors;
double
gamma;
float
x_resolution,
y_resolution;
unsigned int
mean_error_per_pixel;
double
normalized_mean_error,
normalized_maximum_error;
unsigned long
total_colors;
char
*signature;
unsigned int
packets,
runlength,
packet_size;
unsigned char
*packed_pixels;
long int
magick_time;
char
magick_filename[1664 ];
unsigned int
magick_columns,
magick_rows;
char
*geometry,
*page;
unsigned int
dispose,
delay,
iterations;
unsigned int
orphan;
struct _Image
*previous,
*list,
*next;
} Image;
Image *MinifyImage(Image *image)
{
Image
*minified_image;
register RunlengthPacket
*q,
*s,
*s0,
*s1,
*s2,
*s3;
register unsigned int
x;
unsigned int
blue,
green,
red;
unsigned long
total_matte,
total_blue,
total_green,
total_red;
unsigned short
index;
for (x=0; x < (image->columns-1); x+=2)
{
total_red=0;
total_green=0;
total_blue=0;
total_matte=0;
s=s0;
total_red+=( 3 )*(s->red); total_green+=( 3 )*(s->green); total_blue+=( 3 )*(s->blue); total_matte+=( 3 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 3 )*(s->red); total_green+=( 3 )*(s->green); total_blue+=( 3 )*(s->blue); total_matte+=( 3 )*(s->index); s++; ;
s=s1;
total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 15 )*(s->red); total_green+=( 15 )*(s->green); total_blue+=( 15 )*(s->blue); total_matte+=( 15 )*(s->index); s++; ; total_red+=( 15 )*(s->red); total_green+=( 15 )*(s->green); total_blue+=( 15 )*(s->blue); total_matte+=( 15 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ;
s=s2;
total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 15 )*(s->red); total_green+=( 15 )*(s->green); total_blue+=( 15 )*(s->blue); total_matte+=( 15 )*(s->index); s++; ; total_red+=( 15 )*(s->red); total_green+=( 15 )*(s->green); total_blue+=( 15 )*(s->blue); total_matte+=( 15 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ;
s=s3;
total_red+=( 3 )*(s->red); total_green+=( 3 )*(s->green); total_blue+=( 3 )*(s->blue); total_matte+=( 3 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 7 )*(s->red); total_green+=( 7 )*(s->green); total_blue+=( 7 )*(s->blue); total_matte+=( 7 )*(s->index); s++; ; total_red+=( 3 )*(s->red); total_green+=( 3 )*(s->green); total_blue+=( 3 )*(s->blue); total_matte+=( 3 )*(s->index); s++; ;
red=(unsigned short) ((total_red+63) >> 7);
green=(unsigned short) ((total_green+63) >> 7);
blue=(unsigned short) ((total_blue+63) >> 7);
index=(unsigned short) ((total_matte+63) >> 7);
if ((red == q->red) && (green == q->green) && (blue == q->blue) &&
(index == q->index) && ((int) q->length < 65535L ))
q->length++;
}
return(minified_image);
}
|