Skip to content

Commit

Permalink
Bug fix again for color space conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
rageworx committed Aug 12, 2018
1 parent 12e3fb5 commit 41a1cfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions res/resource.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define APP_VERSION 0,1,4,16
#define APP_VERSION_STR "0.1.4.16"
#define APP_VERSION 0,1,4,17
#define APP_VERSION_STR "0.1.4.17"
10 changes: 7 additions & 3 deletions src/debugtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ bool convertF32toU8( ImgF32* src, ImgU8 &dst )

if ( fMin < 0.f )
{
printf( "Error @ convertF32toU8(), Min float under zero : %.2f\n", fMin );
printf( "Warning @ convertF32toU8(), Min float under zero : %.2f\n",
fMin );
fflush( stdout );

fMin = 0.f;
}

printf( "fMin:fMax=%.2f:%.2f", fMin, fMax );

#pragma omp parallel for
for( unsigned cnt=0; cnt<srcsz; cnt++ )
{
Expand Down Expand Up @@ -164,14 +165,17 @@ void saveImgYCbCr( void* img, const char* fnameprefix )
char strFnMap[1024] = {0};

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

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

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

Expand Down
18 changes: 11 additions & 7 deletions src/libsrcnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ void converImgU8toYCbCr( ImgU8 &src, ImgYCbCr &out )
#pragma omp parallel for
for( unsigned cnt=0; cnt<imgsz; cnt++ )
{
float fR = src.buff[ ( cnt * src.depth ) + 0 ];
float fG = src.buff[ ( cnt * src.depth ) + 1 ];
float fB = src.buff[ ( cnt * src.depth ) + 2 ];
float fR = (float)src.buff[ ( cnt * src.depth ) + 0 ];
float fG = (float)src.buff[ ( cnt * src.depth ) + 1 ];
float fB = (float)src.buff[ ( cnt * src.depth ) + 2 ];

// Y
out.Y.buff[cnt] = ( 0.299f * fR ) +
Expand All @@ -212,6 +212,7 @@ void converImgU8toYCbCr( ImgU8 &src, ImgYCbCr &out )
( 0.5f * fR ) -
( 0.4187f * fG ) -
( 0.0813f * fB );

}
}

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

// Red -> Green -> Blue ...
out.buff[( cnt * 3 ) + 0] = (unsigned char)fR;
out.buff[( cnt * 3 ) + 1] = (unsigned char)fG;
out.buff[( cnt * 3 ) + 2] = (unsigned char)fB;
out.buff[( cnt * 3 ) + 0] = (unsigned char)MAX( 0.f, fR );
out.buff[( cnt * 3 ) + 1] = (unsigned char)MAX( 0.f, fG );
out.buff[( cnt * 3 ) + 2] = (unsigned char)MAX( 0.f, fB );
}
}

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

#ifdef DEBUG
printf("rY:");
saveImgF32( &imgResized[0], "resized_Y.png" );
printf("rCb:");
saveImgF32( &imgResized[1], "resized_Cb.png" );
printf("rCr:");
saveImgF32( &imgResized[2], "resized_Cr.png" );
#endif

Expand Down Expand Up @@ -608,4 +612,4 @@ int DLL_PUBLIC ProcessSRCNN( const unsigned char* refbuff,
}

return -100;
}
}

0 comments on commit 41a1cfb

Please sign in to comment.