HexEdit/AerialView.cpp
void CAerialView::draw_bitmap(CDC* pDC)
{
	CHexEditDoc *pDoc = GetDocument();
	ASSERT(pDoc != NULL && pDoc->dib_ != NULL);
	if (pDoc == NULL || pDoc->dib_ == NULL)
		return;

	BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(pDoc->dib_);
	ASSERT(bih->biCompression == BI_RGB && bih->biHeight > 0);

	// Work out how to "reshape" the bitmap based cols_ (already calced from width of the window and dpix)
	// Note: changing the bitmap header (ie width/height) should only be done just before BLTing
	// the bitmap as more than one view can use the same bitmap and they may require different "shapes".
	bih->biWidth = cols_;
	ASSERT(cols_ % 8 == 0 && cols_ > 0 && cols_ <= CHexEditDoc::MAX_WIDTH);
	ASSERT((pDoc->length_-1)/bih->biWidth < LONG_MAX);
	bih->biHeight = LONG((pDoc->NumElts()-1)/bih->biWidth) + 1;

	int pos = int(scrollpos_/(GetDocument()->GetBpe() * cols_));    // no of rows above top of window
	CRect cliprct; pDC->GetClipBox(&cliprct);                       // only BLT the area that needs it

	// Work out src rect
	int sl = (cliprct.left - bdr_left_)/actual_dpix_;
	if (sl < 0) sl = 0;
	int st = pos + (cliprct.top - bdr_top_)/actual_dpix_;
	if (st < 0) st = 0;
	int sr = (cliprct.right - bdr_left_ - 1)/actual_dpix_ + 1;
	if (sr > bih->biWidth) sr = bih->biWidth;
	int sb = pos + (cliprct.bottom - bdr_top_ - 1)/actual_dpix_ + 1;
	if (sb > bih->biHeight) sb = bih->biHeight;

	// Work out dest rect
	int dl = bdr_left_ + sl*actual_dpix_;
	int dt = bdr_top_ + (st - pos)*actual_dpix_;
	int dr = bdr_left_ + sr*actual_dpix_;
	int db = bdr_top_ + (sb - pos)*actual_dpix_;

	::StretchDIBits(pDC->GetSafeHdc(),
					dl, dt, dr - dl, db - dt,
					sl, sb + 1, sr - sl, st - sb,
					FreeImage_GetBits(pDoc->dib_), FreeImage_GetInfo(pDoc->dib_),
					DIB_RGB_COLORS, SRCCOPY);
}
// Redraws the part of the bitmap that need to be shown in the window.
// The source (FreeImage) bitmap is reshaped to fit across the display:
// 1. The width (bih->biWidth) is modified so that the correct number of
//    elements for the client window width is used.
// Note that this relies on the bitmap width always being a multiple
// of 4 (actually we use 8 for possible future compatibility) so that there
// are no pad bytes on the end of the scan lines.
// 2. The height (bih->biHeight) is calculated so that the bitmap size
//    includes all elements in the bitmap.
// Note that this means that the actual bitmap size varies depending on
// the width, but that has been allowed for by allocating a bit of extra
// space at the end (see CHexEditDoc::AddAerialView).

Redraws the part of the bitmap that need to be shown in the window.
The source (FreeImage) bitmap is reshaped to fit across the display:
1. The width (bih->biWidth) is modified so that the correct number of
elements for the client window width is used.
Note that this relies on the bitmap width always being a multiple
of 4 (actually we use 8 for possible future compatibility) so that there
are no pad bytes on the end of the scan lines.
2. The height (bih->biHeight) is calculated so that the bitmap size
includes all elements in the bitmap.
Note that this means that the actual bitmap size varies depending on
the width, but that has been allowed for by allocating a bit of extra
space at the end .
Redraws the part of the bitmap that need to be shown in the window . The source ( FreeImage ) bitmap is reshaped to fit across the display : 1 . The width ( bih - > biWidth ) is modified so that the correct number of elements for the client window width is used . Note that this relies on the bitmap width always being a multiple of 4 ( actually we use 8 for possible future compatibility ) so that there are no pad bytes on the end of the scan lines . 2 . The height ( bih - > biHeight ) is calculated so that the bitmap size includes all elements in the bitmap . Note that this means that the actual bitmap size varies depending on the width but that has been allowed for by allocating a bit of extra space at the end .
void CAerialView::draw_bitmap(CDC* pDC)
{
	CHexEditDoc *pDoc = GetDocument();
	ASSERT(pDoc != NULL && pDoc->dib_ != NULL);
	if (pDoc == NULL || pDoc->dib_ == NULL)
		return;
	BITMAPINFOHEADER *bih = FreeImage_GetInfoHeader(pDoc->dib_);
	ASSERT(bih->biCompression == BI_RGB && bih->biHeight > 0);
	bih->biWidth = cols_;
	ASSERT(cols_ % 8 == 0 && cols_ > 0 && cols_ <= CHexEditDoc::MAX_WIDTH);
	ASSERT((pDoc->length_-1)/bih->biWidth < LONG_MAX);
	bih->biHeight = LONG((pDoc->NumElts()-1)/bih->biWidth) + 1;
	int pos = int(scrollpos_/(GetDocument()->GetBpe() * cols_));    
	CRect cliprct; pDC->GetClipBox(&cliprct);                       
	int sl = (cliprct.left - bdr_left_)/actual_dpix_;
	if (sl < 0) sl = 0;
	int st = pos + (cliprct.top - bdr_top_)/actual_dpix_;
	if (st < 0) st = 0;
	int sr = (cliprct.right - bdr_left_ - 1)/actual_dpix_ + 1;
	if (sr > bih->biWidth) sr = bih->biWidth;
	int sb = pos + (cliprct.bottom - bdr_top_ - 1)/actual_dpix_ + 1;
	if (sb > bih->biHeight) sb = bih->biHeight;
	int dl = bdr_left_ + sl*actual_dpix_;
	int dt = bdr_top_ + (st - pos)*actual_dpix_;
	int dr = bdr_left_ + sr*actual_dpix_;
	int db = bdr_top_ + (sb - pos)*actual_dpix_;
	::StretchDIBits(pDC->GetSafeHdc(),
					dl, dt, dr - dl, db - dt,
					sl, sb + 1, sr - sl, st - sb,
					FreeImage_GetBits(pDoc->dib_), FreeImage_GetInfo(pDoc->dib_),
					DIB_RGB_COLORS, SRCCOPY);
}
void CAerialView :: draw_bitmap ( CDC * pDC ) { CHexEditDoc * pDoc = GetDocument ( ) ; ASSERT ( pDoc != NULL && pDoc -> dib_ != NULL ) ; if ( pDoc == NULL || pDoc -> dib_ == NULL ) return ; BITMAPINFOHEADER * bih = FreeImage_GetInfoHeader ( pDoc -> dib_ ) ; ASSERT ( bih -> biCompression == BI_RGB && bih -> biHeight > 0 ) ; bih -> biWidth = cols_ ; ASSERT ( cols_ % 8 == 0 && cols_ > 0 && cols_ <= CHexEditDoc :: MAX_WIDTH ) ; ASSERT ( ( pDoc -> length_ - 1 ) / bih -> biWidth < LONG_MAX ) ; bih -> biHeight = LONG ( ( pDoc -> NumElts ( ) - 1 ) / bih -> biWidth ) + 1 ; int pos = int ( scrollpos_ / ( GetDocument ( ) -> GetBpe ( ) * cols_ ) ) ; CRect cliprct ; pDC -> GetClipBox ( & cliprct ) ; int sl = ( cliprct . left - bdr_left_ ) / actual_dpix_ ; if ( sl < 0 ) sl = 0 ; int st = pos + ( cliprct . top - bdr_top_ ) / actual_dpix_ ; if ( st < 0 ) st = 0 ; int sr = ( cliprct . right - bdr_left_ - 1 ) / actual_dpix_ + 1 ; if ( sr > bih -> biWidth ) sr = bih -> biWidth ; int sb = pos + ( cliprct . bottom - bdr_top_ - 1 ) / actual_dpix_ + 1 ; if ( sb > bih -> biHeight ) sb = bih -> biHeight ; int dl = bdr_left_ + sl * actual_dpix_ ; int dt = bdr_top_ + ( st - pos ) * actual_dpix_ ; int dr = bdr_left_ + sr * actual_dpix_ ; int db = bdr_top_ + ( sb - pos ) * actual_dpix_ ; :: StretchDIBits ( pDC -> GetSafeHdc ( ) , dl , dt , dr - dl , db - dt , sl , sb + 1 , sr - sl , st - sb , FreeImage_GetBits ( pDoc -> dib_ ) , FreeImage_GetInfo ( pDoc -> dib_ ) , DIB_RGB_COLORS , SRCCOPY ) ; }
Redraws the part of the bitmap that need to be shown in the window.
Redraws the part of the bitmap that need to be shown in the window .
// Work out how to "reshape" the bitmap based cols_ (already calced from width of the window and dpix)
 // Note: changing the bitmap header (ie width/height) should only be done just before BLTing
 // the bitmap as more than one view can use the same bitmap and they may require different "shapes".
 // no of rows above top of window
 // only BLT the area that needs it
 // Work out src rect
 // Work out dest rect
