00001
00005 #include <RobotTypes.H>
00006 #include <ImageSource.H>
00007
00008 namespace WURDE {
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 long GCM_rleEncodeGreyLow(unsigned char *data, const long rows, const long cols) {
00021 long i, j;
00022 unsigned char curRun, curVal;
00023 unsigned char *source = data;
00024 unsigned char *target = data;
00025 long count = 0;
00026
00027 count = 0;
00028 for(i=0;i<rows*cols;) {
00029
00030
00031 curVal = source[i++] >> 3;
00032
00033
00034 curRun = 0;
00035 for(j=0;j<7 && i<rows*cols;j++) {
00036 if((source[i] >> 3) == curVal) {
00037 curRun++;
00038 i++;
00039 }
00040 else
00041 break;
00042 }
00043
00044 target[count++] = (curRun << 5) | curVal;
00045 }
00046
00047 return(count);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 int GCM_rleDecodeGreyLow(unsigned char *source, const long rleSize, unsigned char *target) {
00057 long i, j;
00058 unsigned long k;
00059 unsigned int curRun;
00060 unsigned char curVal;
00061
00062 for(i=0,j=0;i<rleSize;i++) {
00063
00064
00065 curRun = (source[i] >> 5) + 1;
00066 curVal = (source[i]) << 3;
00067
00068
00069 for(k=0;k<curRun;k++,j++)
00070 target[j] = curVal;
00071 }
00072
00073 return(0);
00074 }
00075
00076
00077
00078
00079
00080
00081
00082 long GCM_rleEncodeGreyMed(unsigned char *data, const long rows, const long cols) {
00083 long i, j;
00084 unsigned char curRun, curVal;
00085 unsigned char *source = data;
00086 unsigned char *target = data;
00087 long count = 0;
00088
00089 count = 0;
00090 for(i=0;i<rows*cols;) {
00091
00092
00093 curVal = source[i++] >> 2;
00094
00095
00096 curRun = 0;
00097 for(j=0;j<3 && i<rows*cols;j++) {
00098 if((source[i] >> 2) == curVal) {
00099 curRun++;
00100 i++;
00101 }
00102 else
00103 break;
00104 }
00105
00106 target[count++] = (curRun << 6) | curVal;
00107 }
00108
00109 return(count);
00110 }
00111
00112
00113
00114
00115
00116 int GCM_rleDecodeGreyMed(unsigned char *source, const long rleSize, unsigned char *target) {
00117 long i, j;
00118 unsigned long k;
00119 unsigned int curRun;
00120 unsigned char curVal;
00121
00122 for(i=0,j=0;i<rleSize;i++) {
00123
00124
00125 curRun = (source[i] >> 6) + 1;
00126 curVal = (source[i]) << 2;
00127
00128
00129 for(k=0;k<curRun;k++,j++)
00130 target[j] = curVal;
00131 }
00132
00133 return(0);
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 long GCM_rleEncodePixLow(unsigned char *data, const long rows, const long cols) {
00146 long a,i;
00147 unsigned short curRun, curVal;
00148 unsigned char *source = data;
00149 unsigned char *target = data;
00150 long count = 0;
00151
00152 count = 0;
00153 for(i=0;i<rows*cols*3;) {
00154
00155
00156 curVal = ((source[i] & 0x00F0) << 4) | ((source[i+1] & 0x00F0)) | ((source[i+2] & 0x00F0) >> 4);
00157 a = i;
00158 i += 3;
00159
00160
00161 for(curRun=0;curRun<15 && i<rows*cols*3;curRun++,i+=3) {
00162 if(curVal != (((source[i] & 0x00F0) << 4) | ((source[i+1] & 0x00F0)) | ((source[i+2] & 0x00F0) >> 4)))
00163 break;
00164 }
00165
00166 target[count++] = (curRun << 4) | ((source[a] & 0xF0) >> 4);
00167 target[count++] = (source[a+1] & 0xF0) | ((source[a+2] & 0xF0) >> 4);
00168 }
00169
00170 return(count);
00171 }
00172
00173
00174
00175
00176
00177 int GCM_rleDecodePixLow(unsigned char *data, const long rleSize, unsigned char *target) {
00178 long i, j;
00179 short curRun;
00180 unsigned char curVal[3];
00181 unsigned char *source = (unsigned char *)data;
00182
00183 for(i=0,j=0;i<rleSize;i+=2) {
00184
00185
00186 curRun = ((source[i] & 0xF0) >> 4);
00187 curVal[0] = (source[i] & 0x0F) << 4;
00188 curVal[1] = (source[i+1] & 0xF0);
00189 curVal[2] = (source[i+1] & 0x0F) << 4;
00190
00191
00192 for(;curRun>=0;curRun--,j+=3) {
00193 target[j+0] = curVal[0];
00194 target[j+1] = curVal[1];
00195 target[j+2] = curVal[2];
00196 }
00197 }
00198
00199 return(0);
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 long GCM_rleEncodePixMed(unsigned char *data, const long rows, const long cols) {
00213 long i;
00214 unsigned char *source = data;
00215 unsigned char *target = (unsigned char *)data;
00216 long count = 0;
00217
00218 for(i=0,count=0;i<rows*cols*3;i+=3) {
00219
00220
00221 target[count++] = (source[i] & 0xF8) | (source[i+1] >> 5);
00222
00223
00224 target[count++] = ((source[i+1] & 0xFC) << 3) | (source[i+2] >> 3);
00225 }
00226
00227 return(count);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 int GCM_rleDecodePixMed(unsigned char *data, const long rleSize, unsigned char *target) {
00237 long i, j;
00238 unsigned char *source = (unsigned char *)data;
00239
00240
00241 for(i=0,j=0;i<rleSize;i+=2,j+=3) {
00242
00243 target[j+0] = (source[i] & 0xF8);
00244 target[j+1] = ((source[i] & 0x07) << 5) | ((source[i+1] & 0xE0) >> 3);
00245 target[j+2] = (source[i+1] & 0x1F) << 3;
00246 }
00247
00248 return(0);
00249 }
00250
00251 }