200 likes | 318 Views
Using the ImageViewer classes. CAboutDlg CChildFrame CDlgTemplateBuilder CInputDialog CImageViewerApp CImageViewerDoc. CImageViewerView CLUT CMainFrame pnmHelper TIFFWriter Timer. ImageViewer classes. ImageViewer classes. Most important classes: CImageViewerDoc CImageViewerView
E N D
CAboutDlg CChildFrame CDlgTemplateBuilder CInputDialog CImageViewerApp CImageViewerDoc CImageViewerView CLUT CMainFrame pnmHelper TIFFWriter Timer ImageViewer classes
ImageViewer classes • Most important classes: • CImageViewerDoc • CImageViewerView • CInputDialog • pnmHelper • TIFFWriter • Timer
ImageViewer classes • CImageViewerDoc class • mImageWidth, mImageHeight • mImageMin, mImageMax • OnOpenDocument(), OnSaveDocument(), OnCloseDocument()
ImageViewer classes • 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
ImageViewer classes • 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()
ImageViewer classes • CImageViewerView class • OnDraw() CBitmap bm; bm.CreateBitmap( pDoc->mImageWidth, pDoc->mImageHeight, 1, 32, mImage ); pDC->BitBlt( 0, 0, pDoc->mImageWidth, pDoc->mImageHeight, &dcMem, 0, 0, SRCCOPY ); or pDC->StretchBlt( mTx, mTy, (int)(mScale*pDoc->mImageWidth+0.5), (int)(mScale*pDoc->mImageHeight+0.5), &dcMem, 0, 0, pDoc->mImageWidth, pDoc->mImageHeight, SRCCOPY );
ImageViewer classes • pnmHelper class static int* read_pnm_file ( const char* const fname, int* w, int* h, 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.
ImageViewer classes • pnmHelper class static void write_pgm_or_ppm_ascii_data ( const int* const buff, const int width, const int height, const char* const fname, const int samples_per_pixel ) Write values as a pgm (grey) or ppm (color) ascii file.
ImageViewer classes • TIFFWriter class static void write_tiff_data8_rgb ( uint8* buff, int width, int height, FILE* fp, const bool use_clut, const int samples_per_pixel ) Write a 24-bit color tiff image.
ImageViewer classes • 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.
Timer class for Java public class Timer { /** \brief start at current time when constructed */ private long mTime = System.currentTimeMillis(); /** \brief reset to current time */ public void reset ( ) { mTime = System.currentTimeMillis(); } /** \brief return elapsed time in seconds */ public double getElapsedTime ( ) { return (System.currentTimeMillis() - mTime) / 1e3; } }
ImageViewer classes • 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( "Enter value: " ); C++: CInputDialog dlg("Enter a value: "); CString result = dlg.m_str; //what user typed
Misc. C review topics • printf • Must first #include <stdio.h> 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 );
Misc. C review topics • 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.”, str, d ); AfxMessageBox( buff );
Misc. C review topics • malloc/free int* iptr = (int*) malloc( 1000 * sizeof(int) ); //what if iptr == NULL? for (int i=0; i<1000; i++) iptr[i] = i; free( iptr ); //must do this or memory leaks occur! iptr = NULL; //just to be extra careful
Misc. C review topics • 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.
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 { . . . }
Misc. Java review topics String value = JOptionPane.showInputDialog( "Enter value: " ); How can we check and convert what the user typed (a number)? boolean inputOK=true; int x; try { x = Integer.parseInt( value ); } catch (Exception e) { inputOK=false; } if (!inputOK) { . . . } else { . . . }
Misc. Java review topics String value = JOptionPane.showInputDialog( "Enter value: " ); Octal support. int xy = 09; Compiler error: integer number too large. int jj = 0123; System.out.println( jj ); 83