1 / 20

Using the ImageViewer classes

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

yachi
Download Presentation

Using the ImageViewer classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using the ImageViewer classes

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

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

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

  5. 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

  6. 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()

  7. 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 );

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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; } }

  13. 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

  14. 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 );

  15. 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 );

  16. 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

  17. 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.

  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: " ); 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 { . . . }

  20. 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

More Related