Skip to content

Commit 41a1cfb

Browse files
committed
Bug fix again for color space conversion
1 parent 12e3fb5 commit 41a1cfb

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

res/resource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#define APP_VERSION 0,1,4,16
2-
#define APP_VERSION_STR "0.1.4.16"
1+
#define APP_VERSION 0,1,4,17
2+
#define APP_VERSION_STR "0.1.4.17"

src/debugtool.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ bool convertF32toU8( ImgF32* src, ImgU8 &dst )
9696

9797
if ( fMin < 0.f )
9898
{
99-
printf( "Error @ convertF32toU8(), Min float under zero : %.2f\n", fMin );
99+
printf( "Warning @ convertF32toU8(), Min float under zero : %.2f\n",
100+
fMin );
100101
fflush( stdout );
101-
102-
fMin = 0.f;
103102
}
104103

104+
printf( "fMin:fMax=%.2f:%.2f", fMin, fMax );
105+
105106
#pragma omp parallel for
106107
for( unsigned cnt=0; cnt<srcsz; cnt++ )
107108
{
@@ -164,14 +165,17 @@ void saveImgYCbCr( void* img, const char* fnameprefix )
164165
char strFnMap[1024] = {0};
165166

166167
// Write Y
168+
printf("saveImgYCbCr(%s), Y:", fnameprefix ); fflush( stdout );
167169
sprintf( strFnMap, "%s_Y.png", fnameprefix );
168170
saveImgF32( &refimg->Y, strFnMap );
169171

170172
// Write Cb
173+
printf("Cb:" ); fflush( stdout );
171174
sprintf( strFnMap, "%s_Cb.png", fnameprefix );
172175
saveImgF32( &refimg->Cb, strFnMap );
173176

174177
// Write Cr
178+
printf("Cr:" ); fflush( stdout );
175179
sprintf( strFnMap, "%s_Cr.png", fnameprefix );
176180
saveImgF32( &refimg->Cr, strFnMap );
177181

src/libsrcnn.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ void converImgU8toYCbCr( ImgU8 &src, ImgYCbCr &out )
192192
#pragma omp parallel for
193193
for( unsigned cnt=0; cnt<imgsz; cnt++ )
194194
{
195-
float fR = src.buff[ ( cnt * src.depth ) + 0 ];
196-
float fG = src.buff[ ( cnt * src.depth ) + 1 ];
197-
float fB = src.buff[ ( cnt * src.depth ) + 2 ];
195+
float fR = (float)src.buff[ ( cnt * src.depth ) + 0 ];
196+
float fG = (float)src.buff[ ( cnt * src.depth ) + 1 ];
197+
float fB = (float)src.buff[ ( cnt * src.depth ) + 2 ];
198198

199199
// Y
200200
out.Y.buff[cnt] = ( 0.299f * fR ) +
@@ -212,6 +212,7 @@ void converImgU8toYCbCr( ImgU8 &src, ImgYCbCr &out )
212212
( 0.5f * fR ) -
213213
( 0.4187f * fG ) -
214214
( 0.0813f * fB );
215+
215216
}
216217
}
217218

@@ -239,9 +240,9 @@ void convertImgF32x3toImgU8( ImgF32* src, ImgU8 &out )
239240
float fB = MIN(255.f, fY + 113.f * fCb / 64.f );
240241

241242
// Red -> Green -> Blue ...
242-
out.buff[( cnt * 3 ) + 0] = (unsigned char)fR;
243-
out.buff[( cnt * 3 ) + 1] = (unsigned char)fG;
244-
out.buff[( cnt * 3 ) + 2] = (unsigned char)fB;
243+
out.buff[( cnt * 3 ) + 0] = (unsigned char)MAX( 0.f, fR );
244+
out.buff[( cnt * 3 ) + 1] = (unsigned char)MAX( 0.f, fG );
245+
out.buff[( cnt * 3 ) + 2] = (unsigned char)MAX( 0.f, fB );
245246
}
246247
}
247248

@@ -528,8 +529,11 @@ int DLL_PUBLIC ProcessSRCNN( const unsigned char* refbuff,
528529
discardImgYCbCr( imgYCbCr );
529530

530531
#ifdef DEBUG
532+
printf("rY:");
531533
saveImgF32( &imgResized[0], "resized_Y.png" );
534+
printf("rCb:");
532535
saveImgF32( &imgResized[1], "resized_Cb.png" );
536+
printf("rCr:");
533537
saveImgF32( &imgResized[2], "resized_Cr.png" );
534538
#endif
535539

@@ -608,4 +612,4 @@ int DLL_PUBLIC ProcessSRCNN( const unsigned char* refbuff,
608612
}
609613

610614
return -100;
611-
}
615+
}

0 commit comments

Comments
 (0)