Using the ImageViewer classes - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Using the ImageViewer classes

Description:

mIsColor false=gray, true=rgb color. mW, mH width and ... int jj = 0123; System.out.println( jj ); 83. Sample images. Available on main course web page. ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 23
Provided by: georgejgr
Category:

less

Transcript and Presenter's Notes

Title: Using the ImageViewer classes


1
Using the ImageViewer classes
2
ImageViewer classes
  • AboutDlg
  • ChildFrame
  • DlgTemplateBuilder
  • InputDialog
  • ImageViewer
  • ImageData
  • View
  • CLUT
  • MainFrame
  • pnmHelper
  • TIFFWriter
  • Timer

3
ImageViewer classes
  • Most important classes
  • ImageData (document)
  • View (view)
  • InputDialog
  • pnmHelper
  • TIFFWriter
  • Timer

4
ImageViewer classes
  • ImageData class protected attributes
  • mIsColor falsegray, truergb color
  • mW, mH width and height
  • mMin, mMax min and max values
  • int mOriginalImage
  • actual image pixel data
  • stored mOriginalImage0 is gray
  • or mOriginalImage0r, mOriginalImage1g,
    mOriginalImage2b
  • 3 separate ints

5
ImageViewer classes
  • ImageData class public methods
  • bool getIsColor ( void )
  • int getW ( void ) int getH ( void )
  • int getMin ( void ) int getMax ( void )
  • int getData ( int i )
  • int getGray ( int row, int col )
  • int getRed ( int row, int col )
  • int getGreen ( int row, int col )
  • int getBlue ( int row, int col )
  • Note that there arent any set methods!

6
ImageViewer classes
  • View class members
  • unsigned char mDisplayData
  • displayable image data
  • stored b, g, r, 0
  • 4 separate bytes
  • Intel is little endian so this is actually
    0,r,g,b
  • Note that ImageDatamOriginalImage is 1 int per
    component while ViewmImage is 1 byte per
    component.
  • ImageData GetDocument()
  • OnMouseMove ( ), OnDraw ( )

7
ImageViewer classes
  • View class OnDraw ( )
  • CBitmap bm
  • bm.CreateBitmap( pDoc-gtgetW(), pDoc-gtgetH(), 1,
    32, mDisplayData )
  • pDC-gtBitBlt( 0, 0, pDoc-gtgetW(), pDoc-gtgetH(),
    dcMem, 0, 0, SRCCOPY )
  • or
  • pDC-gtStretchBlt( mTx, mTy,
  • (int)(mScalepDoc-gtgetW()0.5),
  • (int)(mScalepDoc-gtgetH()0.5), dcMem, 0, 0,
  • pDoc-gtgetW(), pDoc-gtgetH(), SRCCOPY )

8
ImageViewer classes
  • pnmHelper class
  • static int read_pnm_file (
  • char 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 (
  • int buff, int width, int height,
  • char fname, 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, bool use_clut,
  • int samples_per_pixel )
  • Write a 24-bit color tiff image.

11
ImageViewer classes
  • Timer class
  • 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.
  • Visual Studio creates debug and release versions.
    Release is typically much faster than debug.

12
Timer class for Java
  • Ctor start timer.
  • reset( ) starts timer back at zero.
  • getElapsedTime() returns elapsed time resolved to
    milliseconds.
  • Timer continues to run.
  • getElapsedTimeNano() returns elapsed time
    resolved to nanoseconds.
  • Timer continues to run.

13
GUI Input (prompt user for a value)
  • Java
  • String value JOptionPane.showInputDialog(
  • "Enter value " )
  • C
  • InputDialog dlg( "Enter a value )
  • CString result dlg.m_str //get what user
    typed

14
GUI output
  • C
  • AfxMessageBox presents a modal dialog box to the
    user with a programmer-specified string.
  • Java
  • See JOptionPane.showMessageDialog( )

15
Misc. C review topics output
  • printf
  • Must first include ltstdio.hgt
  • 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 Istvan
  • printf( Mr. s, you have .2f in your account.,
  • str, d )

16
Misc. C review topics converting numbers to
strings
  • 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 )

17
Misc. C review topics memory management
  • malloc/free
  • int iptr (int) malloc( 1000 sizeof(int) )
  • //what if iptr NULL?
  • for (int i0 ilt1000 i)
  • iptri i
  • free( iptr ) //must do this or memory leaks
    occur!
  • iptr NULL //just to be extra careful

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

19
Misc. C review topics number input
  • InputDialog 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
  • . . .

20
Misc. Java review topics number input
  • String value JOptionPane.showInputDialog(
  • "Enter value " )
  • How can we check and convert what the user typed
    (a number)?
  • boolean inputOKtrue
  • int x
  • try
  • x Integer.parseInt( value )
  • catch (Exception e)
  • inputOKfalse
  • if (!inputOK)
  • . . .
  • else
  • . . .

21
Misc. Java review topics octal numbers
  • 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

22
Sample images
  • Available on main course web page.
Write a Comment
User Comments (0)
About PowerShow.com