Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the ImageViewer classes. ImageViewer classes CAboutDlg CAboutDlg CChildFrame CChildFrame CDlgTemplateBuilder CDlgTemplateBuilder CInputDialog CInputDialog.

Similar presentations


Presentation on theme: "Using the ImageViewer classes. ImageViewer classes CAboutDlg CAboutDlg CChildFrame CChildFrame CDlgTemplateBuilder CDlgTemplateBuilder CInputDialog CInputDialog."— Presentation transcript:

1 Using the ImageViewer classes

2 ImageViewer classes CAboutDlg CAboutDlg CChildFrame CChildFrame CDlgTemplateBuilder CDlgTemplateBuilder CInputDialog CInputDialog CImageViewerApp CImageViewerApp CImageViewerDoc CImageViewerDoc CImageViewerView CImageViewerView CLUT CLUT CMainFrame CMainFrame pnmHelper pnmHelper TIFFWriter TIFFWriter Timer Timer

3 ImageViewer classes Most important classes: Most important classes: –CImageViewerDoc –CImageViewerView –CInputDialog –pnmHelper –TIFFWriter –Timer

4 ImageViewer classes CImageViewerDoc class CImageViewerDoc class –mImageWidth, mImageHeight –mImageMin, mImageMax –OnOpenDocument(), OnSaveDocument(), OnCloseDocument()

5 ImageViewer classes CImageViewerDoc class CImageViewerDoc class –mImageSamplesPerPixel  1=gray, 3=rgb –int* mImage  actual image pixel data  stored mImage[0] is gray  or mImage[0]=r, mImage[1]=g, mImage[2]=b –3 separate ints

6 ImageViewer classes CImageViewerView class CImageViewerView class –unsigned char* mImage  displayable image  stored: b, g, r, 0 –4 separate bytes –Intel is little endian so this is actually 0,r,g,b  Recall CImageViewerDoc::mImage is 1 int per component while CImageViewerView::mImage is 1 byte per component. –OnMouseMove()

7 ImageViewer classes CImageViewerView class CImageViewerView class –OnDraw() CBitmap bm; bm.CreateBitmap( pDoc->mImageWidth, pDoc->mImageHeight, 1, 32, mImage ); pDoc->mImageHeight, 1, 32, mImage ); pDC->BitBlt( 0, 0, pDoc->mImageWidth, pDoc->mImageHeight, &dcMem, 0, 0, SRCCOPY ); pDoc->mImageHeight, &dcMem, 0, 0, SRCCOPY );or pDC->StretchBlt( mTx, mTy, (int)(mScale*pDoc->mImageWidth+0.5), (int)(mScale*pDoc->mImageWidth+0.5), (int)(mScale*pDoc->mImageHeight+0.5), &dcMem, 0, 0, (int)(mScale*pDoc->mImageHeight+0.5), &dcMem, 0, 0, pDoc->mImageWidth, pDoc->mImageWidth, pDoc->mImageHeight, SRCCOPY ); pDoc->mImageHeight, SRCCOPY );

8 ImageViewer classes pnmHelper class pnmHelper class static int* read_pnm_file ( const char* const fname, int* w, int* h, const char* const fname, int* w, int* h, int* samplesPerPixel, int* min, int* max) int* samplesPerPixel, int* min, int* max) This method should be generally used to read any pnm (pgm grey, ppm color) binary or ascii image files.

9 ImageViewer classes pnmHelper class pnmHelper class static void write_pgm_or_ppm_ascii_data ( const int* const buff, const int width, const int* const buff, const int width, const int height, const char* const fname, const int height, const char* const fname, const int samples_per_pixel ) const int samples_per_pixel ) Write values as a pgm (grey) or ppm (color) ascii file.

10 ImageViewer classes TIFFWriter class TIFFWriter class static void write_tiff_data8_rgb ( uint8* buff, int width, int height, FILE* fp, int width, int height, FILE* fp, const bool use_clut, const bool use_clut, const int samples_per_pixel ) const int samples_per_pixel ) Write a 24-bit color tiff image.

11 ImageViewer classes Timer class Timer class –Updated 3/22 –Can be used to easily time algorithms. –Timer() ctor starts the timer. –reset() resets the timer to 0 (and start the timer) –getElapsedTime() returns a double of the elapsed time in seconds. –getCPUTime() returns a double of the CPU time used in seconds. –Timer demo: show Debug and Release for median filter.

12 Timer class for Java public class Timer { /** \brief start at current time when constructed */ /** \brief start at current time when constructed */ private long mTime = System.currentTimeMillis(); private long mTime = System.currentTimeMillis(); /** \brief reset to current time */ /** \brief reset to current time */ public void reset ( ) { public void reset ( ) { mTime = System.currentTimeMillis(); mTime = System.currentTimeMillis(); } /** \brief return elapsed time in seconds */ /** \brief return elapsed time in seconds */ public double getElapsedTime ( ) { public double getElapsedTime ( ) { return (System.currentTimeMillis() - mTime) / 1e3; return (System.currentTimeMillis() - mTime) / 1e3; }}

13 ImageViewer classes CInputDialog class CInputDialog class –get new CInputDialog.h file from course web page –AfxMessageBox presents a modal dialog box to the user with a programmer-specified string. Java: String value = JOptionPane.showInputDialog( String value = JOptionPane.showInputDialog( "Enter value: " ); "Enter value: " );C++: CInputDialog dlg("Enter a value: "); CInputDialog dlg("Enter a value: "); CString result = dlg.m_str; //what user typed

14 Misc. C review topics printf printf –Must first #include –Must first #include int i=5242; printf( “The value %d\nis %x in hex.\n”, i, i ); double d = 65.769970; printf( “The std dev = %f.”, d ); char* name = “Ochlak”; printf( “Mr. %s, you have %.2f in your account.”, str, d );

15 Misc. C review topics sprintf sprintf –Just like printf but works on a string buffer in memory. char buff[ 256 ]; sprintf( buff, “Mr. %s, you have %.2f in your account.”, “Mr. %s, you have %.2f in your account.”, str, d ); AfxMessageBox( buff );

16 Misc. C review topics malloc/free malloc/free int* iptr = (int*) malloc( 1000 * sizeof(int) ); //what if iptr == NULL? for (int i=0; i<1000; i++) iptr[i] = i; iptr[i] = i; free( iptr ); //must do this or memory leaks occur! iptr = NULL; //just to be extra careful

17 Misc. C review topics Assert Assert –Assume or require some condition to be true. –Now in Java 5 as well! int* iptr = (int*) malloc( 1000 * sizeof(int) ); //what if iptr == NULL? assert( iptr != NULL ); Disappears completely in non-debug mode.

18 Misc. C review topics CInputDialog dlg("Enter a value: "); How can we check and convert what the user typed (a number)? int x; int howManyWereOK = sscanf( dlg.m_str, "%d", &x ); if (howManyWereOK!=1) { AfxMessageBox( “Bad input.” ); } else {......}

19 Misc. Java review topics String value = JOptionPane.showInputDialog( "Enter value: " ); "Enter value: " ); How can we check and convert what the user typed (a number)? boolean inputOK=true; int x; try { x = Integer.parseInt( value ); x = Integer.parseInt( value ); } catch (Exception e) { inputOK=false; inputOK=false;} if (!inputOK) {...... } else {......}

20 Misc. Java review topics String value = JOptionPane.showInputDialog( "Enter value: " ); "Enter value: " ); Octal support. int xy = 09; Compiler error: integer number too large. int jj = 0123; System.out.println( jj ); 83


Download ppt "Using the ImageViewer classes. ImageViewer classes CAboutDlg CAboutDlg CChildFrame CChildFrame CDlgTemplateBuilder CDlgTemplateBuilder CInputDialog CInputDialog."

Similar presentations


Ads by Google