src/pixmap.cc
branchpyrit
changeset 89 fcf1487b398b
parent 88 f7edb3b90816
child 90 f6a72eb99631
equal deleted inserted replaced
88:f7edb3b90816 89:fcf1487b398b
    34 
    34 
    35 unsigned char *Pixmap::getCharData() const
    35 unsigned char *Pixmap::getCharData() const
    36 {
    36 {
    37 	unsigned char *cdata = new unsigned char[w*h*3];
    37 	unsigned char *cdata = new unsigned char[w*h*3];
    38 	Float *fd = fdata;
    38 	Float *fd = fdata;
       
    39 
       
    40 #ifdef NO_SSE
    39 	for (unsigned char *cd = cdata; cd != cdata + w*h*3; cd++, fd++)
    41 	for (unsigned char *cd = cdata; cd != cdata + w*h*3; cd++, fd++)
    40 	{
       
    41 		if (*fd > 1.0)
    42 		if (*fd > 1.0)
    42 			*cd = 255;
    43 			*cd = 255;
    43 		else
    44 		else
    44 			*cd = (unsigned char)(*fd * 255.0);
    45 			*cd = (unsigned char)(*fd * 255.0);
       
    46 #else
       
    47 	__m128 cmax = _mm_set_ps1(255.0);
       
    48 	__m64 m;
       
    49 	for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
       
    50 	{
       
    51 		m = _mm_cvtps_pi8(_mm_mul_ps(cmax,
       
    52 			_mm_min_ps(mOne, _mm_set_ps(fd[3],fd[2],fd[1],fd[0]))));
       
    53 		memcpy(cd, &m, 4);
    45 	}
    54 	}
       
    55 #endif
       
    56 
    46 	return cdata;
    57 	return cdata;
    47 }
    58 }
    48 
    59 
    49 int Pixmap::writePNG(const char *fname) const
    60 int Pixmap::writePNG(const char *fname) const
    50 {
    61 {