vbAccelerator - Contents of code file: frmGammaCorrection.frm

VERSION 5.00
Begin VB.Form frmGammaCorrection 
   Caption         =   "vbAccelerator Gamma Correction Sample"
   ClientHeight    =   4395
   ClientLeft      =   2265
   ClientTop       =   2100
   ClientWidth     =   7725
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmGammaCorrection.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4395
   ScaleWidth      =   7725
   Begin VB.HScrollBar hscGamma 
      Height          =   255
      LargeChange     =   40
      Left            =   4860
      Max             =   200
      SmallChange     =   10
      TabIndex        =   5
      Top             =   3960
      Value           =   100
      Width           =   1575
   End
   Begin VB.PictureBox picResult 
      Height          =   3435
      Left            =   3900
      ScaleHeight     =   225
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   241
      TabIndex        =   3
      Top             =   420
      Width           =   3675
   End
   Begin VB.PictureBox picSource 
      Height          =   3435
      Left            =   120
      ScaleHeight     =   225
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   241
      TabIndex        =   1
      Top             =   420
      Width           =   3675
   End
   Begin VB.CommandButton cmdSource 
      Caption         =   "Load I&mage..."
      Height          =   435
      Left            =   120
      TabIndex        =   0
      Top             =   3900
      Width           =   1455
   End
   Begin VB.Label lblGammaAmount 
      Height          =   255
      Left            =   6540
      TabIndex        =   7
      Top             =   3960
      Width           =   675
   End
   Begin VB.Label lblGamma 
      Caption         =   "&Gamma"
      Height          =   255
      Left            =   4020
      TabIndex        =   6
      Top             =   3960
      Width           =   855
   End
   Begin VB.Label lblResult 
      BackColor       =   &H80000010&
      Caption         =   " Result"
      ForeColor       =   &H80000014&
      Height          =   255
      Left            =   3900
      TabIndex        =   4
      Top             =   60
      Width           =   3675
   End
   Begin VB.Label lblSource 
      BackColor       =   &H80000010&
      Caption         =   " Source Image"
      ForeColor       =   &H80000014&
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   60
      Width           =   3675
   End
End
Attribute VB_Name = "frmGammaCorrection"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private m_cSourceImage As New cDIBSection
Private m_cGammaImage As New cDIBSection
Private m_cGamma As New cGammaCorrect

Private Sub processGamma(ByVal Gamma As Double)
   lblGammaAmount.Caption = Gamma
   m_cGamma.Gamma = Gamma
   m_cGamma.Correct m_cSourceImage, m_cGammaImage
   picResult.Refresh
End Sub

Private Sub openImage(ByVal sFile As String)
   Dim sPic As StdPicture
   Set sPic = LoadPicture(sFile)
   m_cSourceImage.CreateFromPicture sPic
   picSource.Refresh
   m_cGammaImage.Create m_cSourceImage.Width, m_cSourceImage.Height
   hscGamma_Change
End Sub

Private Sub cmdSource_Click()
On Error GoTo ErrorHandler
   
   Dim c As New cCommonDialog
   Dim sFile As String
   If c.VBGetOpenFileName(sFile, Filter:="Picture Files
    (*.GIF;*.JPG;*.BMP)|*.GIF;*.JPG;*.BMP|All Files (*.*)|*.*",
    DefaultExt:="BMP", Owner:=Me.hwnd) Then
      openImage sFile
   End If
   Exit Sub

ErrorHandler:
   MsgBox "Problem getting source image: [" & Err.Description & "]",
    vbExclamation
   Exit Sub
End Sub


Private Sub Form_Load()
   
   Me.Show
   Me.Refresh
   
On Error GoTo ErrorHandler
   Dim sFile As String
   sFile = App.Path
   If (Right$(sFile, 1) <> "\") Then sFile = sFile & "\"
   sFile = sFile & "beer.jpg"
   openImage sFile
   Exit Sub
   
ErrorHandler:
   MsgBox "Problem getting source image: [" & Err.Description & "]",
    vbExclamation
   Exit Sub
End Sub

Private Sub hscGamma_Change()
Dim lV As Long
   lV = hscGamma.Value
   If (lV = 100) Then
      processGamma 1#
   ElseIf (lV < 100) Then
      ' 100 == 1, 0 == 1/5
      processGamma 1# / (5# - (lV / 25#))
   Else
      ' 100 == 1, 200 == 5
      processGamma (lV - 100#) / 25# + 1#
   End If
   
End Sub

Private Sub hscGamma_Scroll()
   hscGamma_Change
End Sub

Private Sub picResult_Paint()
   m_cGammaImage.PaintPicture picResult.hdc
End Sub

Private Sub picSource_Paint()
   m_cSourceImage.PaintPicture picSource.hdc
End Sub