src/pixmap.cc
branchpyrit
changeset 95 ca7d4c665531
parent 92 9af5c039b678
child 103 3b3257a410fe
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
    45 		else
    45 		else
    46 			*cd = (unsigned char)(*fd * 255.0);
    46 			*cd = (unsigned char)(*fd * 255.0);
    47 #else
    47 #else
    48 	__m128 cmax = _mm_set_ps1(255.0);
    48 	__m128 cmax = _mm_set_ps1(255.0);
    49 	__m64 m;
    49 	__m64 m;
    50 	for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
    50 	if (!refdata)
    51 	{
    51 		for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
    52 		m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
    52 		{
    53 			_mm_min_ps(mOne, _mm_load_ps(fd))));
    53 			m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
    54 		for (int i = 0; i < 4; i++)
    54 				_mm_min_ps(mOne, _mm_load_ps(fd))));
    55 			cd[i] = ((unsigned char *)&m)[i<<1];
    55 			for (int i = 0; i < 4; i++)
    56 	}
    56 				cd[i] = ((unsigned char *)&m)[i<<1];
       
    57 		}
       
    58 	else // must use _mm_loadu_ instead of _mm_load_ as we do not know the alignment
       
    59 		for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
       
    60 		{
       
    61 			m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
       
    62 				_mm_min_ps(mOne, _mm_loadu_ps(fd))));
       
    63 			for (int i = 0; i < 4; i++)
       
    64 				cd[i] = ((unsigned char *)&m)[i<<1];
       
    65 		}
    57 #endif
    66 #endif
    58 
    67 
    59 	return cdata;
    68 	return cdata;
    60 }
    69 }
    61 
    70 
    62 int Pixmap::writePNG(const char *fname) const
    71 int Pixmap::writePNG(const char *fname) const
    63 {
    72 {
    64 #ifndef HAVE_PNG
    73 #ifndef HAVE_PNG
       
    74 	dbgmsg(0, "W %s not written: PNG support is disabled\n", fname);
    65 	return -3;
    75 	return -3;
    66 #else
    76 #else
    67 	int y;
    77 	int y;
    68 	FILE *f;
    78 	FILE *f;
    69 	png_structp png;   /* PNG data */
    79 	png_structp png;   /* PNG data */