@@ -1155,7 +1155,7 @@ cvShowImage( const char* name, const CvArr* arr )
11551155 void * dst_ptr = 0 ;
11561156 const int channels0 = 3 ;
11571157 int origin = 0 ;
1158- CvMat stub, dst, *image;
1158+ CvMat stub, *image;
11591159 bool changed_size = false ; // philipg
11601160
11611161 if ( !name )
@@ -1209,9 +1209,26 @@ cvShowImage( const char* name, const CvArr* arr )
12091209 DIB_RGB_COLORS, &dst_ptr, 0 , 0 ));
12101210 }
12111211
1212- cvInitMatHeader ( &dst, size.cy , size.cx , CV_8UC3,
1213- dst_ptr, (size.cx * channels + 3 ) & -4 );
1214- cvConvertImage ( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
1212+ {
1213+ cv::Mat src = cv::cvarrToMat (image);
1214+ cv::Mat dst (size.cy , size.cx , CV_8UC3, dst_ptr, (size.cx * channels + 3 ) & -4 );
1215+ if (src.channels () == 1 )
1216+ {
1217+ cv::cvtColor (src, dst, cv::COLOR_GRAY2BGR);
1218+ cv::flip (dst, dst, 0 );
1219+ }
1220+ else if (src.channels () == 4 )
1221+ {
1222+ cv::cvtColor (src, dst, cv::COLOR_BGRA2BGR);
1223+ cv::flip (dst, dst, 0 );
1224+ }
1225+ else
1226+ {
1227+ CV_Assert (src.channels () == 3 );
1228+ cv::flip (src, dst, 0 );
1229+ }
1230+ CV_Assert (dst.data == (uchar*)dst_ptr);
1231+ }
12151232
12161233 // ony resize window if needed
12171234 if (changed_size)
@@ -1223,86 +1240,6 @@ cvShowImage( const char* name, const CvArr* arr )
12231240 __END__;
12241241}
12251242
1226- #if 0
1227- CV_IMPL void
1228- cvShowImageHWND(HWND w_hWnd, const CvArr* arr)
1229- {
1230- CV_FUNCNAME( "cvShowImageHWND" );
1231-
1232- __BEGIN__;
1233-
1234- SIZE size = { 0, 0 };
1235- int channels = 0;
1236- void* dst_ptr = 0;
1237- const int channels0 = 3;
1238- int origin = 0;
1239- CvMat stub, dst, *image;
1240- bool changed_size = false;
1241- BITMAPINFO tempbinfo;
1242- HDC hdc = NULL;
1243-
1244- if( !arr )
1245- EXIT;
1246- if( !w_hWnd )
1247- EXIT;
1248-
1249- hdc = GetDC(w_hWnd);
1250-
1251- if( CV_IS_IMAGE_HDR( arr ) )
1252- origin = ((IplImage*)arr)->origin;
1253-
1254- CV_CALL( image = cvGetMat( arr, &stub ) );
1255-
1256- if ( hdc )
1257- {
1258- //GetBitmapData
1259- BITMAP bmp;
1260- GdiFlush();
1261- HGDIOBJ h = GetCurrentObject( hdc, OBJ_BITMAP );
1262-
1263- if (h == NULL)
1264- EXIT;
1265- if (GetObject(h, sizeof(bmp), &bmp) == 0) //GetObject(): returns size of object, 0 if error
1266- EXIT;
1267-
1268- channels = bmp.bmBitsPixel/8;
1269- dst_ptr = bmp.bmBits;
1270- }
1271-
1272- if( size.cx != image->width || size.cy != image->height || channels != channels0 )
1273- {
1274- changed_size = true;
1275-
1276- uchar buffer[sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD)];
1277- BITMAPINFO* binfo = (BITMAPINFO*)buffer;
1278-
1279- BOOL bDeleteObj = DeleteObject(GetCurrentObject(hdc, OBJ_BITMAP));
1280- CV_Assert( FALSE != bDeleteObj );
1281-
1282- size.cx = image->width;
1283- size.cy = image->height;
1284- channels = channels0;
1285-
1286- FillBitmapInfo( binfo, size.cx, size.cy, channels*8, 1 );
1287-
1288- SelectObject( hdc, CreateDIBSection( hdc, binfo, DIB_RGB_COLORS, &dst_ptr, 0, 0));
1289- }
1290-
1291- cvInitMatHeader( &dst, size.cy, size.cx, CV_8UC3, dst_ptr, (size.cx * channels + 3) & -4 );
1292- cvConvertImage( image, &dst, origin == 0 ? CV_CVTIMG_FLIP : 0 );
1293-
1294- // Image stretching to fit the window
1295- RECT rect;
1296- GetClientRect(w_hWnd, &rect);
1297- StretchDIBits( hdc, 0, 0, rect.right, rect.bottom, 0, 0, image->width, image->height, dst_ptr, &tempbinfo, DIB_RGB_COLORS, SRCCOPY );
1298-
1299- // ony resize window if needed
1300- InvalidateRect(w_hWnd, 0, 0);
1301-
1302- __END__;
1303- }
1304- #endif
1305-
13061243CV_IMPL void cvResizeWindow (const char * name, int width, int height )
13071244{
13081245 CV_FUNCNAME ( " cvResizeWindow" );
0 commit comments