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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
copys RGB images to a destination
Copyright (C) 2000 Martin Vogt
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation.
For more information look at the file COPYRIGHT in this package
*/
#include "ditherRGB.h"
#include <iostream>
using namespace std;
DitherRGB::DitherRGB() {
}
DitherRGB::~DitherRGB() {
}
int DitherRGB::getDepth(int pixel) {
int byteDepth=0;
switch(pixel) {
case 8:
byteDepth=1;
break;
case 15:
case 16:
byteDepth=2;
break;
case 24:
case 32:
byteDepth=4;
break;
default:
cout << "unknown byteDepth:"<<pixel
<< " in DitherRGB_flipped::flipRGBImage"<<endl;
}
return byteDepth;
}
void DitherRGB::ditherRGBImage(unsigned char* dest,unsigned char* src,
int depth,int width,int height,int offset) {
int byteDepth=getDepth(depth);
if (byteDepth == 0) {
return;
}
if (offset==0) {
int bytes=height*width*byteDepth;
memcpy(dest,src,bytes);
return;
}
int i;
int lineSize=width*byteDepth;
offset=offset*byteDepth+lineSize;
for (i=0;i<height;i++) {
memcpy(dest,src,lineSize);
src+=lineSize;
dest+=offset;
}
}
void DitherRGB::ditherRGBImage_x2(unsigned char* dest,unsigned char* src,
int depth,int width,int height,int offset) {
int byteDepth=getDepth(depth);
if (byteDepth == 0) {
return;
}
switch(byteDepth) {
case 1:
ditherRGB1Byte_x2(dest,src,1,width, height,offset);
break;
case 2:
ditherRGB2Byte_x2(dest,src,2,width, height,offset);
break;
case 4:
ditherRGB4Byte_x2(dest,src,4,width, height,offset);
break;
default:
cout <<"ditherRGBImage_x2 byteDepth:"<<byteDepth
<<" not supported"<<endl;
}
}
void DitherRGB::ditherRGB1Byte_x2(unsigned char* dest,unsigned char* src,
int depth,int width,int height,int offset) {
//
// dest destr
// destd destrd
int lineInc=2*width+offset;
unsigned char* destr=dest+1;
unsigned char* destd=dest+lineInc;
unsigned char* destrd=destd+1;
int row;
int col;
//
// We copy byte by byte this is slow, but works for
// all byteDepth
// this memcpy can be optimized with MMX very i) good ii) easily
for(row=0;row<height;row++) {
for(col=0;col<width;col++) {
*dest++=*src;
*destr++=*src;
*destd++=*src;
*destrd++=*src;
dest++;
destr++;
destd++;
destrd++;
src++;
}
dest+=lineInc;
destr+=lineInc;
destd+=lineInc;
destrd+=lineInc;
}
}
void DitherRGB::ditherRGB2Byte_x2(unsigned char* destination,
unsigned char* source,
int depth,int width,int height,int offset) {
//
// dest destr
// destd destrd
unsigned short int* src=(unsigned short int*) source;
unsigned short int* dest=(unsigned short int*) destination;
int lineInc=2*width+offset;
unsigned short int* destr=dest+1;
unsigned short int* destd=dest+lineInc;
unsigned short int* destrd=destd+1;
int row;
int col;
//
// We copy byte by byte this is slow, but works for
// all byteDepth
// this memcpy can be optimized with MMX very i) good ii) easily
for(row=0;row<height;row++) {
for(col=0;col<width;col++) {
*dest++=*src;
*destr++=*src;
*destd++=*src;
*destrd++=*src;
dest++;
destr++;
destd++;
destrd++;
src++;
}
dest+=lineInc;
destr+=lineInc;
destd+=lineInc;
destrd+=lineInc;
}
}
void DitherRGB::ditherRGB4Byte_x2(unsigned char* destination,
unsigned char* source,
int depth,int width,int height,int offset) {
//
// dest destr
// destd destrd
unsigned int* src=(unsigned int*) source;
unsigned int* dest=(unsigned int*) destination;
int lineInc=2*width+offset;
unsigned int* destr=dest+1;
unsigned int* destd=dest+lineInc;
unsigned int* destrd=destd+1;
int row;
int col;
//
// We copy byte by byte this is slow, but works for
// all byteDepth
// this memcpy can be optimized with MMX very i) good ii) easily
for(row=0;row<height;row++) {
for(col=0;col<width;col++) {
*dest++=*src;
*destr++=*src;
*destd++=*src;
*destrd++=*src;
dest++;
destr++;
destd++;
destrd++;
src++;
}
dest+=lineInc;
destr+=lineInc;
destd+=lineInc;
destrd+=lineInc;
}
}
|