' Code written by Marius Hudea. Permission to use this code in your projects granted
' as long as my contribution is mentioned somewhere. You should optimize the conversion routines
' if you plan to use them in something that needs speed.
'
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const CREATE_NEW As Long = 1
Private Const CREATE_ALWAYS As Long = 2
Private Const OPEN_EXISTING As Long = 3
Private Const OPEN_ALWAYS As Long = 4
Private Const OPEN_IF_EXISTS As Long = (&H1)
Private Const INVALID_HANDLE_VALUE As Long = -1
Private Const FILE_BEGIN As Long = 0
Private Const FILE_END As Long = 2
Private Const FILE_SHARE_READ As Long = &H1
Private Const FILE_SHARE_WRITE As Long = &H2
Private Const GENERIC_WRITE As Long = &H40000000
Private Const GENERIC_READ As Long = &H80000000
Private Type typeRGBQuad
R As Byte
G As Byte
B As Byte
x As Byte ' reserved
End Type
Private Type typeYUV
Y As Byte ' Luminance
U As Byte ' Chroma b (Cb)
V As Byte ' Chroma r (Cr)
End Type
Private imgRGB() As typeRGBQuad
Private imgRGB2() As typeRGBQuad
Private imgYUV() As typeYUV
'Conversion routines for RGB->YUV and YUV->RGB
'
' coefficients Rec.601 Rec.709 FCC
' Kr : Red channel 0.299 0.2125 0.3
' Kg : Green channel 0.587 0.7154 0.59
' Kb : Blue channel 0.114 0.0721 0.11
'
' 601 is the standard that is used.
'
' The formulas look scary, but really they're not. Stand back and relax.