Click here to Skip to main content
15,884,629 members

sunny.rana - Professional Profile



Summary

    Blog RSS
-17
Debator
3
Enquirer
309
Participant
0
Author
0
Authority
0
Editor
0
Organiser
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
Question16 bit image using Bitmap or TIFF using VC++ (MFC control) Pin
sunny.rana5-Dec-07 6:45
sunny.rana5-Dec-07 6:45 
i have a CCD camera that acquires 12 bit image and i have used MFC function BitMapInfoheader function to save it as 8 bit as a result my image displayed is compressed and i loose finer details could u please help to correct my code for 16 bit the code is as below.

Thank you in advanceSmile | :)

./* Window.C */
#include "stdafx.h"
#include "afxstr.h"
#include "atlimage.h"
#include "string.h"

extern "C"
{
#include <windows.h>
#include "wingdi.h"
#include "win.h"
#include "master.h"

}


#define ALIGNLONG(i) ((i+3)/4*4)
#define COLORBITS 8

CImage image;
void Draw_Strip( HWND hWnd );
HBRUSH ghbrWhite, ghbrBlack;
void Create_DIB( HWND wnd );
void Draw_DIB( HWND wnd );

/*
* Some handy globals.
*/
CString fullname;
int W, H;
unsigned int Min,Max;
static HBITMAP hBitmap;
static LPBITMAPINFOHEADER lpbi;
static BITMAPINFOHEADER bi;
char *lpstBitmap;
HPALETTE palette;

CString name = "Image";
//CImage image;


/**************************************************
*
* Register this type of window...
*
*
**************************************************/
BOOL RegisterWindow(char *lpClass, HINSTANCE instance)
{
WNDCLASS wc;

ghbrWhite = CreateSolidBrush(0x00FFFFFF);
ghbrBlack = CreateSolidBrush(0x00000000);

wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) ImageWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(LONG);
wc.hInstance = instance;
wc.hIcon = LoadIcon(NULL,IDC_ARROW);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = ghbrWhite;
wc.lpszMenuName = NULL;
wc.lpszClassName = lpClass;

if (!RegisterClass(&wc))
return FALSE;

else
return TRUE;

}

/**************************************************
*
* Create and show the window....
*
*
**************************************************/
HWND CreateWin( int x,
int y,
int width,
int height,
char *lpClass,
char *name,
HINSTANCE instance)
{
HWND handle;
W = width;
H = height;
handle = CreateWindow(
lpClass, // pointer to registered class name
name, // pointer to window name
WS_VISIBLE | WS_OVERLAPPEDWINDOW, //| WS_VSCROLL | WS_HSCROLL, // window style
x, // horizontal position of window
y+20, // vertical position of window
width, // window width
height, // window height
NULL, // handle to parent or owner window
NULL, // handle to menu or child-window identifier
instance, // handle to application instance
NULL // pointer to window-creation data
);

return (handle);

}

/**************************************************
*
* Handles the messages for this window
*
*
**************************************************/
int WINAPI ImageWndProc(
HWND hwnd,
UINT message,
DWORD wParam,
LONG lParam)
{
switch (message)
{
case WM_PAINT:

Draw_DIB( hwnd );


return 0L;
break;
case WM_SIZE:
return DefMDIChildProc(hwnd, message, wParam, lParam);
break;
case WM_CREATE:
Create_DIB( hwnd );

return 0L;
break;

case WM_CLOSE:

return DefMDIChildProc(hwnd, message, wParam, lParam);
break;

case WM_DESTROY:

return DefMDIChildProc(hwnd, message, wParam, lParam);

break;

default:
return DefMDIChildProc(hwnd, message, wParam, lParam);
break;
}

}

/**************************************************
*
* Create a Device Independent Bitmap...
*
*
**************************************************/
void Create_DIB( HWND hWnd )
{

HDC hDC;
unsigned char i;
long k,j, NumBytes;
LPBITMAPINFO info;
unsigned char *dat;
DWORD error;

hDC = GetDC (hWnd) ;
// Intialize BITMAPINFOHEADER data.
//.................................
bi.biSize = sizeof (BITMAPINFOHEADER) ;
bi.biWidth = W;
bi.biHeight = -H; // top-down DIB
bi.biPlanes = 1;
bi.biBitCount = COLORBITS;
bi.biCompression = BI_RGB;
bi.biSizeImage = ( ALIGNLONG( (W * COLORBITS)/8 ) * H);
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 256;
bi.biClrImportant = 256;


// Allocate memory for BITMAPINFO structure.
//..........................................
NumBytes = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); // +
//( ALIGNLONG( ( W * COLORBITS ) / 8 ) * H );

lpbi = (BITMAPINFOHEADER*)GlobalAlloc( GPTR, NumBytes );

if( lpbi == NULL )
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

exit( EXIT_FAILURE ); // Get out now!
}

// Copy BITMAPINFOHEADER information.
//...................................
*lpbi = bi;

// Create The Palette
info = (LPBITMAPINFO) lpbi;


for ( i=0; i<255; i++ )
{
info->bmiColors[i].rgbRed = i;
info->bmiColors[i].rgbBlue = i;
info->bmiColors[i].rgbGreen = i;
info->bmiColors[i].rgbReserved = 0;
}

// Set pointer to bitmap’s bit data.
//..................................
// lpstBitmap = (LPSTR)lpbi + (WORD)sizeof(BITMAPINFOHEADER) +
// (256 * sizeof(RGBQUAD));

hBitmap = ::CreateDIBSection(hDC,(LPBITMAPINFO)lpbi, DIB_RGB_COLORS,(VOID **)&lpstBitmap, NULL,0);
dat = (unsigned char*)lpstBitmap;

for ( k=0; k< H; k++ )
for ( j = 0; j < W; j++ )
*dat++ = (unsigned char)k;

// Create uninitialized DIB bitmap.
//.................................
/* hBitmap = CreateDIBitmap( hDC,
&bi,
0 ,
0,
(LPBITMAPINFO) lpbi, */




error = GetLastError();


ReleaseDC( hWnd, hDC);



}

void Save(int num)
{

CString prefix = "C:\\Documents and Settings\\Garner Lab\\My Documents\\Hyperspectimages\\image";
char buf[4];
itoa(num, buf, 10);
CString number = buf;
CString suffix = ".bmp";
fullname = prefix + number + suffix;
CImage image;
image.Attach(hBitmap);
image.Save(fullname); // save as BMP
image.Detach();
}
/**************************************************
*
* Force repaint and update the display...
*
*
**************************************************/
void Draw_DIB( HWND hWnd )
{
PAINTSTRUCT ps;
HDC hMemDC;
int scan;
DWORD lasterror;


BeginPaint( hWnd, &ps );
hMemDC = CreateCompatibleDC( ps.hdc );

SelectPalette(hMemDC, palette, TRUE);
RealizePalette(hMemDC);
SelectPalette(ps.hdc, palette, TRUE);
RealizePalette(ps.hdc);


scan = SetDIBits(
hMemDC, // handle of device context
hBitmap, // handle of bitmap
0, // starting scan line
H, // number of scan lines
lpstBitmap, // array of bitmap bits
(LPBITMAPINFO) lpbi, // address of structure with bitmap data
DIB_RGB_COLORS ); // type of color indices to use



if ( !scan )
lasterror = GetLastError();
SelectObject( hMemDC, hBitmap );

BitBlt( ps.hdc, 0, 0, W, H,
hMemDC, 0, 0, SRCCOPY );
DeleteDC( hMemDC );

EndPaint( hWnd, &ps );




}


/**************************************************
*
* Set the bits to the bitmap to be displayed...
*
*
**************************************************/
void Update_Bitmap( HWND hwnd, unsigned short *data, int AutoStop )
{
// Alter The Bits via the pointer
int i,j;
unsigned char *dbits = (unsigned char*)lpstBitmap;
unsigned short *head;
static float mp;
unsigned int max, min;

max = 0;
min = 65535;
head = data;


/* Calculate Scaling Factor */
for (i=0; i<h; i++)<br="" mode="hold"> for (j=0;j<w; j++)<br="" mode="hold"> {
if ( min > *head ) min = *head;
if ( max < *head ) max = *head;
head++;
Min = min;
Max = max;
}

mp = (float)256 / ( (float)max-(float)min );

/* Transfer Data to 8 bits */
for (i=0; i<h; i++)<br="" mode="hold"> for ( j=0;j<w;j++)>
*dbits++ = (unsigned char)(((float)*data++ - (float)min)*mp);


// force repaint
InvalidateRect( hwnd, NULL, FALSE );

if( AutoStop ); // Get rid of compiler warning
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.