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

Comparing CV/CV.xs (file contents):
Revision 1.10 by root, Tue Feb 8 10:34:19 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 int bigst = 1; 256 const int HISTSIZE = 64;
257
257 int j = 0; 258 int j;
258 SV *sv = *av_fetch (av, i, 1); 259 SV *sv = *av_fetch (av, i, 1);
259 STRLEN len; 260 STRLEN len;
260 char *buf = SvPVbyte (sv, len); 261 char *buf = SvPVbyte (sv, len);
262
261 int tmphist[256]; 263 int tmphist[HISTSIZE];
262 char *hist; 264 float *hist;
263 265
264 SV *histsv = newSV (257);//("", 0); 266 SV *histsv = newSV (HISTSIZE * sizeof (float) + 1);
265 sv_upgrade (histsv, SVt_PV);
266 SvCUR_set (histsv, 256); 267 SvPOK_on (histsv);
268 SvCUR_set (histsv, HISTSIZE * sizeof (float));
267 hist = SvPV_nolen (histsv); 269 hist = (float *)SvPVX (histsv);
268 270
269 Zero (tmphist, 256, int); 271 Zero (tmphist, sizeof (tmphist), char);
270 272
271 while (len--) 273 for (j = len; j--; )
274 {
275 unsigned int idx
276 = ((*buf & 0xc0) >> 2)
277 | ((*buf & 0x18) >> 1)
278 | (*buf & 0x03);
279
272 ++tmphist[*buf++]; 280 ++tmphist[idx];
273 281 ++buf;
274 for (j = 0; j < 256; ++j) 282 }
275 if (tmphist[j] > bigst)
276 bigst = tmphist[j];
277 283
278 for (j = 0; j < 256; ++j) 284 for (j = 0; j < HISTSIZE; ++j)
279 hist[j] = tmphist[j] * 255 / bigst; 285 hist[j] = (float)tmphist[j] / (len + 1e-30);
280 286
281 av_push (result, histsv); 287 av_push (result, histsv);
282 } 288 }
283 289
284 RETVAL = newRV_noinc ((SV *)result); 290 RETVAL = newRV_noinc ((SV *)result);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines