home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form fScreen
- BorderStyle = 1 'Fixed Single
- Caption = "Texturize project"
- ClientHeight = 6315
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 7860
- ClipControls = 0 'False
- BeginProperty Font
- Name = "Verdana"
- Size = 6.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- LockControls = -1 'True
- MaxButton = 0 'False
- ScaleHeight = 421
- ScaleMode = 3 'Pixel
- ScaleWidth = 524
- StartUpPosition = 2 'CenterScreen
- Begin VB.CommandButton cmdTexturize
- Caption = "&Texturize"
- Height = 375
- Left = 5385
- TabIndex = 5
- Top = 5355
- Width = 1950
- End
- Begin VB.HScrollBar sbWeight
- Height = 195
- LargeChange = 5
- Left = 5445
- Max = 100
- TabIndex = 2
- Top = 4065
- Value = 50
- Width = 1830
- End
- Begin VB.OptionButton optDepth
- Caption = "Em&boss"
- Height = 210
- Index = 0
- Left = 6435
- TabIndex = 3
- Top = 4650
- Value = -1 'True
- Width = 930
- End
- Begin VB.OptionButton optDepth
- Caption = "En&grave"
- Height = 210
- Index = 1
- Left = 6435
- TabIndex = 4
- Top = 4890
- Width = 930
- End
- Begin VB.PictureBox iBack
- BackColor = &H8000000C&
- ClipControls = 0 'False
- Height = 2685
- Left = 5018
- ScaleHeight = 175
- ScaleMode = 3 'Pixel
- ScaleWidth = 175
- TabIndex = 1
- TabStop = 0 'False
- Top = 1050
- Width = 2685
- Begin VB.Image iTexture
- Height = 2625
- Left = 0
- Top = 0
- Width = 2625
- End
- End
- Begin VB.FileListBox flTextures
- Height = 810
- Left = 5010
- Pattern = "*.bmp"
- TabIndex = 0
- Top = 135
- Width = 2700
- End
- Begin VB.PictureBox iScr
- Appearance = 0 'Flat
- BackColor = &H8000000C&
- ClipControls = 0 'False
- DrawMode = 6 'Mask Pen Not
- ForeColor = &H80000008&
- Height = 2310
- Left = 150
- ScaleHeight = 152
- ScaleMode = 3 'Pixel
- ScaleWidth = 134
- TabIndex = 7
- TabStop = 0 'False
- Top = 150
- Width = 2040
- End
- Begin VB.CommandButton cmdReset
- Caption = "&Reset"
- Height = 375
- Left = 5385
- TabIndex = 6
- Top = 5805
- Width = 1950
- End
- Begin VB.Label lblWeight
- Caption = "Texture weight"
- Height = 210
- Left = 5805
- TabIndex = 10
- Top = 3825
- Width = 1110
- End
- Begin VB.Label lblWeightV
- Alignment = 2 'Center
- Caption = "50%"
- Height = 195
- Left = 6120
- TabIndex = 9
- Top = 4320
- Width = 495
- End
- Begin VB.Label Label1
- Caption = "Depth mode"
- Height = 240
- Left = 5385
- TabIndex = 8
- Top = 4650
- Width = 1140
- End
- Begin VB.Image iIm
- Height = 1275
- Left = 150
- Top = 2550
- Visible = 0 'False
- Width = 1365
- End
- Attribute VB_Name = "fScreen"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '// Texture project
- '// Carles P.V. - 2002
- Option Explicit
- Private iBM As BITMAPINFO 'Image bits
- Private tBM As BITMAPINFO 'Texture bits
- Private Sub Form_Load()
- If (App.LogMode <> 1) Then
- MsgBox "Compile me: I'll process faster.", vbExclamation
- Unload Me
- End If
- '// Get first image from textures list
- With flTextures
- .Path = App.Path
- If (.ListCount) Then
- .ListIndex = 0
- End If
- End With
- '// Load image
- iIm = LoadPicture(App.Path & "\Sample.jpg")
- iScr.Move 10, 10, iIm.Width + 2, iIm.Height + 2
- '// Create Bitmap
- CreateBitmap iBM, iIm.Width, iIm.Height
- '// Get Bits
- iBM.Bits = TakeBitsFromPicture(iIm, iIm.Width, iIm.Height)
- End Sub
- Private Sub iScr_Paint()
- PaintBits iBM, iScr.hdc
- End Sub
- Private Sub cmdReset_Click()
- iBM.Bits = TakeBitsFromPicture(iIm, iIm.Width, iIm.Height)
- iScr_Paint
- End Sub
- Private Sub flTextures_Click()
- With iTexture
- .Picture = LoadPicture(flTextures.Path & "\" & flTextures.FileName)
- .Move 0.5 * (175 - .Width), 0.5 * (175 - .Height)
- End With
- End Sub
- Private Sub sbWeight_Change()
- lblWeightV = sbWeight & "%"
- End Sub
- Private Sub sbWeight_Scroll()
- sbWeight_Change
- End Sub
- ' Texturize filter is based on emboss/engrave filter:
- ' The emboss/engrave gets a new "3D bump field bitmap" from increment/decrement of
- ' RGB values of two adjacent pixels.
- ' The emboss filter is got subtracting R/G/B value of adjacent pixel to main pixel.
- ' The engrave one, subtracting R/G/B value of main pixel to adjacent pixel.
- ' The current emboss/engrave filters are based on NW direction: varying the relative
- ' position of adjacent pixel, we can get 8 possible bump directions for each filter.
- ' A weight parameter lets modify filter intensity (inc./decr. factor)
- ' And a last operation normalizes R/G/B values to median grey value + 128. Texturize filter
- ' works from these last values, applying a "shift" coeficient to each pixel:
- ' 0/128=0.0 to 255/128=2.0 (128/128=1.0 med. luminosity)
- ' Sorry for my English.
- Private Sub cmdTexturize_Click()
- 'Create texture bitmap
- CreateBitmap tBM, iTexture.Width, iTexture.Height
- 'Get texture bits
- tBM.Bits = TakeBitsFromPicture(iTexture, iTexture.Width, iTexture.Height)
- 'Generate depth (gradient) field (emboss/engrave)
- If (optDepth(0)) Then
- Emboss tBM.Bits, sbWeight
- Else
- Engrave tBM.Bits, sbWeight
- End If
- 'Apply on source image
- Texturize iBM.Bits, tBM.Bits
- 'Refresh
- iScr_Paint
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Erase iBM.Bits
- Erase tBM.Bits
- Set fScreen = Nothing
- End
- End Sub
-