Skip to content

Commit

Permalink
Require grayscale preview requests to supply source and destination p…
Browse files Browse the repository at this point in the history
…ictures
  • Loading branch information
tannerhelland committed Aug 18, 2012
1 parent c105512 commit 5218ab1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
64 changes: 32 additions & 32 deletions Forms/VBP_FormGrayscale.frm
Original file line number Diff line number Diff line change
Expand Up @@ -350,29 +350,29 @@ Private Sub drawGrayscalePreview()

Select Case cboMethod.ListIndex
Case 0
MenuGrayscaleAverage True
MenuGrayscaleAverage True, PicPreview, PicEffect
Case 1
MenuGrayscale True
MenuGrayscale True, PicPreview, PicEffect
Case 2
MenuDesaturate True
MenuDesaturate True, PicPreview, PicEffect
Case 3
If optDecompose(0).Value = True Then
MenuDecompose 0, True
MenuDecompose 0, True, PicPreview, PicEffect
Else
MenuDecompose 1, True
MenuDecompose 1, True, PicPreview, PicEffect
End If
Case 4
If optChannel(0).Value = True Then
MenuGrayscaleSingleChannel 0, True
MenuGrayscaleSingleChannel 0, True, PicPreview, PicEffect
ElseIf optChannel(1).Value = True Then
MenuGrayscaleSingleChannel 1, True
MenuGrayscaleSingleChannel 1, True, PicPreview, PicEffect
Else
MenuGrayscaleSingleChannel 2, True
MenuGrayscaleSingleChannel 2, True, PicPreview, PicEffect
End If
Case 5
fGrayscaleCustom hsShades.Value, True
fGrayscaleCustom hsShades.Value, True, PicPreview, PicEffect
Case 6
fGrayscaleCustomDither hsShades.Value, True
fGrayscaleCustomDither hsShades.Value, True, PicPreview, PicEffect
End Select

End If
Expand Down Expand Up @@ -480,7 +480,7 @@ Private Sub Form_Load()

'Set up the grayscale options combo box
cboMethod.AddItem "Average value [(R+G+B) / 3]", 0
cboMethod.AddItem "Adjusted for the human eye [ITU Standard]", 1
cboMethod.AddItem "Human eye equivalent [ITU Standard]", 1
cboMethod.AddItem "Desaturate", 2
cboMethod.AddItem "Decompose", 3
cboMethod.AddItem "Single color channel", 4
Expand All @@ -503,11 +503,11 @@ Private Sub Form_Load()
End Sub

'Reduce to X # gray shades
Public Sub fGrayscaleCustom(ByVal numOfShades As Long, Optional ByVal toPreview As Boolean = False)
Public Sub fGrayscaleCustom(ByVal numOfShades As Long, Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Converting to " & numOfShades & " shades of gray..."
GetImageData
Expand Down Expand Up @@ -576,7 +576,7 @@ Public Sub fGrayscaleCustom(ByVal numOfShades As Long, Optional ByVal toPreview

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -585,11 +585,11 @@ Public Sub fGrayscaleCustom(ByVal numOfShades As Long, Optional ByVal toPreview
End Sub

'Reduce to X # gray shades (dithered)
Public Sub fGrayscaleCustomDither(ByVal numOfShades As Long, Optional ByVal toPreview As Boolean = False)
Public Sub fGrayscaleCustomDither(ByVal numOfShades As Long, Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Converting to " & numOfShades & " shades of gray, with dithering..."
GetImageData
Expand Down Expand Up @@ -678,7 +678,7 @@ Public Sub fGrayscaleCustomDither(ByVal numOfShades As Long, Optional ByVal toPr

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -687,11 +687,11 @@ Public Sub fGrayscaleCustomDither(ByVal numOfShades As Long, Optional ByVal toPr
End Sub

'Reduce to gray via (r+g+b)/3
Public Sub MenuGrayscaleAverage(Optional ByVal toPreview As Boolean = False)
Public Sub MenuGrayscaleAverage(Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Converting image to grayscale..."
GetImageData
Expand Down Expand Up @@ -749,7 +749,7 @@ Public Sub MenuGrayscaleAverage(Optional ByVal toPreview As Boolean = False)

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -758,11 +758,11 @@ Public Sub MenuGrayscaleAverage(Optional ByVal toPreview As Boolean = False)
End Sub

'Reduce to gray in a more human-eye friendly manner
Public Sub MenuGrayscale(Optional ByVal toPreview As Boolean = False)
Public Sub MenuGrayscale(Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Generating ITU-R compatible grayscale image..."
GetImageData
Expand Down Expand Up @@ -815,7 +815,7 @@ Public Sub MenuGrayscale(Optional ByVal toPreview As Boolean = False)

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -824,11 +824,11 @@ Public Sub MenuGrayscale(Optional ByVal toPreview As Boolean = False)
End Sub

'Reduce to gray via HSL -> convert S to 0
Public Sub MenuDesaturate(Optional ByVal toPreview As Boolean = False)
Public Sub MenuDesaturate(Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Desaturating image..."
GetImageData
Expand Down Expand Up @@ -889,7 +889,7 @@ Public Sub MenuDesaturate(Optional ByVal toPreview As Boolean = False)

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -898,11 +898,11 @@ Public Sub MenuDesaturate(Optional ByVal toPreview As Boolean = False)
End Sub

'Reduce to gray by selecting the minimum (maxOrMin = 0) or maximum (maxOrMin = 1) color in each pixel
Public Sub MenuDecompose(ByVal maxOrMin As Long, Optional ByVal toPreview As Boolean = False)
Public Sub MenuDecompose(ByVal maxOrMin As Long, Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Decomposing image..."
GetImageData
Expand Down Expand Up @@ -955,7 +955,7 @@ Public Sub MenuDecompose(ByVal maxOrMin As Long, Optional ByVal toPreview As Boo

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand All @@ -964,11 +964,11 @@ Public Sub MenuDecompose(ByVal maxOrMin As Long, Optional ByVal toPreview As Boo
End Sub

'Reduce to gray by selecting a single color channel (represeted by cChannel: 0 = Red, 1 = Green, 2 = Blue)
Public Sub MenuGrayscaleSingleChannel(ByVal cChannel As Long, Optional ByVal toPreview As Boolean = False)
Public Sub MenuGrayscaleSingleChannel(ByVal cChannel As Long, Optional ByVal toPreview As Boolean = False, Optional ByRef srcPic As PictureBox, Optional ByRef dstPic As PictureBox)

'Get the appropriate set of image data contingent on whether this is a preview or not
If toPreview = True Then
GetPreviewData PicPreview
GetPreviewData srcPic
Else
Message "Converting to grayscale by isolating single color channel..."
GetImageData
Expand Down Expand Up @@ -1028,7 +1028,7 @@ Public Sub MenuGrayscaleSingleChannel(ByVal cChannel As Long, Optional ByVal toP

'Render the finished output to the appropriate image container
If toPreview = True Then
SetPreviewData PicEffect
SetPreviewData dstPic
Else
SetImageData
Message "Finished."
Expand Down
14 changes: 8 additions & 6 deletions Modules/VBP_MenuIcons.bas
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,24 @@ Public Sub CreateCustomFormIcon(ByRef imgForm As FormImage)
aspectRatio = CSng(imgForm.BackBuffer.ScaleWidth) / CSng(imgForm.BackBuffer.ScaleHeight)

'The target icon's width and height, x and y positioning
Dim tIcoWidth As Single, tIcoHeight As Single, tX As Single, tY As Single
Dim tIcoWidth As Single, tIcoHeight As Single, TX As Single, TY As Single

'If the form is wider than it is tall...
If aspectRatio > 1 Then

'Determine proper sizes and (x, y) positioning so the icon will be centered
tIcoWidth = icoSize
tIcoHeight = icoSize * (1 / aspectRatio)
tX = 0
tY = (icoSize - tIcoHeight) / 2
TX = 0
TY = (icoSize - tIcoHeight) / 2

Else

'Same thing, but with the math adjusted for images taller than they are wide
tIcoHeight = icoSize
tIcoWidth = icoSize * aspectRatio
tY = 0
tX = (icoSize - tIcoWidth) / 2
TY = 0
TX = (icoSize - tIcoWidth) / 2

End If

Expand All @@ -282,7 +282,7 @@ Public Sub CreateCustomFormIcon(ByRef imgForm As FormImage)
SetStretchBltMode imgForm.picIcon.hDC, STRETCHBLT_HALFTONE

'Render the bitmap that will ultimately be converted into an icon
StretchBlt imgForm.picIcon.hDC, CLng(tX), CLng(tY), CLng(tIcoWidth), CLng(tIcoHeight), imgForm.BackBuffer.hDC, 0, 0, imgForm.BackBuffer.ScaleWidth, imgForm.BackBuffer.ScaleHeight, vbSrcCopy
StretchBlt imgForm.picIcon.hDC, CLng(TX), CLng(TY), CLng(tIcoWidth), CLng(tIcoHeight), imgForm.BackBuffer.hDC, 0, 0, imgForm.BackBuffer.ScaleWidth, imgForm.BackBuffer.ScaleHeight, vbSrcCopy
imgForm.picIcon.Picture = imgForm.picIcon.Image

'Now that we have a first draft to work from, start preparing the data types required by the icon API calls
Expand Down Expand Up @@ -354,6 +354,8 @@ Public Sub CreateCustomFormIcon(ByRef imgForm As FormImage)
'Store this icon in our running list, so we can destroy it when the program is closed
addIconToList generatedIcon

If imgForm.WindowState = vbMaximized Then DoEvents

'The chunk of code below will generate an actual icon object for use within VB. I don't use this mechanism because
' VB will internally convert the icon to 256-colors before assigning it to the form. <sigh> Rather than do that,
' I use an alternate API call above to assign the new icon in its transparent, full color glory.
Expand Down
Binary file modified PhotoDemon.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion PhotoDemon.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Description="PhotoDemon"
CompatibleMode="0"
MajorVer=4
MinorVer=3
RevisionVer=30
RevisionVer=32
AutoIncrementVer=1
ServerSupportFiles=0
VersionComments="�2000-2012 Tanner Helland - www.tannerhelland.com"
Expand Down

0 comments on commit 5218ab1

Please sign in to comment.