ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.14 by root, Tue Feb 8 12:51:12 2005 UTC vs.
Revision 1.15 by root, Tue Feb 8 16:27:10 2005 UTC

251 av = (AV *) SvRV (ar); 251 av = (AV *) SvRV (ar);
252 result = newAV (); 252 result = newAV ();
253 253
254 for (i = 0; i <= av_len (av); ++i) 254 for (i = 0; i <= av_len (av); ++i)
255 { 255 {
256 const int HISTSIZE = 64;
257
256 int bigst, j; 258 int j;
257 SV *sv = *av_fetch (av, i, 1); 259 SV *sv = *av_fetch (av, i, 1);
258 STRLEN len; 260 STRLEN len;
259 char *buf = SvPVbyte (sv, len); 261 char *buf = SvPVbyte (sv, len);
260 262
261 int tmphist[256]; 263 int tmphist[HISTSIZE];
262 char *hist; 264 float *hist;
263 265
264 SV *histsv = newSV (257); 266 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
265 SvPOK_on (histsv); 267 SvPOK_on (histsv);
266 SvCUR_set (histsv, 256); 268 SvCUR_set (histsv, HISTSIZE * sizeof (float));
267 hist = SvPVX (histsv); 269 hist = (float *)SvPVX (histsv);
268 270
269 Zero (tmphist, 256, int); 271 Zero (tmphist, sizeof (tmphist), char);
270 272
271 j = len; 273 for (j = len; j--; )
274 {
275 unsigned int idx
276 = ((*buf & 0xc0) >> 2)
277 | ((*buf & 0x18) >> 1)
278 | (*buf & 0x03);
272 279
273 while (len--) 280 ++tmphist[idx];
274 ++tmphist[(unsigned char)*buf++ & 0xda]; 281 ++buf;
282 }
275 283
276 len = j;
277
278 bigst = 1;
279 for (j = 0; j < 256; ++j) 284 for (j = 0; j < HISTSIZE; ++j)
280 if (tmphist[j] > bigst) 285 hist[j] = (float)tmphist[j] / (len + 1e-30);
281 bigst = tmphist[j];
282
283 for (j = 0; j < 256; ++j)
284 hist[j] = tmphist[j] * 255 / (len == 0 ? 1 : len);//bigst;
285 286
286 av_push (result, histsv); 287 av_push (result, histsv);
287 } 288 }
288 289
289 RETVAL = newRV_noinc ((SV *)result); 290 RETVAL = newRV_noinc ((SV *)result);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines