Leider läuft mit der DLL nicht alles rund und eine neue DLL ist auch nicht in Sicht,dafür gibts da aber den Quellcode.
Also habe ich versucht die Stück für Stück in PB umzusetzen und nun bin ich an einem Punkt wo nichts mehr weitergeht.

Code: Alles auswählen
FrostGlass() bzw RandomColor()
Vieleicht schleicht hier jemand rum der sich besser mit VC++ auskennt.
Code: Alles auswählen
EnableExplicit
Define.l GFX ,Event ,Gadget ,Type ,Window
Global Window_0, ScrollArea_0, Container_0, TrackBar_0, TrackBar_1
Global TrackBar_2, TrackBar_3, TrackBar_4, TrackBar_5, TrackBar_6
Global Container_1, Button_0, Button_1, Button_2,Image_37 , Menu_0, CheckBox_0, ProgressBar_0
Global F1, F2, F3, F4, F5, F6, F7, F8, F9, F10
Global F11, F12, F13, F14, F15, F16, F17, F18, F19, F20
Global F21, F22, F23, F24, F25, F26, F27, F28, F29, F30
Global F31, F32, F33, F34, F35, F36, F37, F38, F39, F40
Global F41, F42, F43, F44, F45, F46, F47, F48, F49, F50
Global F51, F52, F53, F54, F55, F56, F57, F58, F59, F60
Global F61, F62, F63, F64, F65, F66, F67, F68, F69, F70
Global F71, F72, F73, F74, F75, F76,SCR_Image,DES_Image
Global ASCII_font=LoadFont(#PB_Any,"Smalfont",7,#PB_Font_Bold | #PB_Font_HighQuality)
Global Dim ASCII_table.c (17)
CopyMemory(?table,@ASCII_table(),18)
;=============================================
; Library: GetImage
; Author: Lloyd Gallant (netmaestro)
; Date: October 26, 2006
; Target OS: Microsoft Windows
; Target Compiler: PureBasic 4.xx
; Dependencies: gdiplus.dll
; License: Open Source
;=============================================
Global PixelFormatIndexed = $00010000 ; Indexes into a palette
Global PixelFormatGDI = $00020000 ; Is a GDI-supported format
Global PixelFormatAlpha = $00040000 ; Has an alpha component
Global PixelFormatPAlpha = $00080000 ; Pre-multiplied alpha
Global PixelFormatExtended = $00100000 ; Extended color 16 bits/channel
Global PixelFormatCanonical = $00200000
Global PixelFormatUndefined = 0
Global PixelFormatDontCare = 0
Global PixelFormat1bppIndexed = (1 | ( 1 << 8) |PixelFormatIndexed |PixelFormatGDI)
Global PixelFormat4bppIndexed = (2 | ( 4 << 8) |PixelFormatIndexed |PixelFormatGDI)
Global PixelFormat8bppIndexed = (3 | ( 8 << 8) |PixelFormatIndexed |PixelFormatGDI)
Global PixelFormat16bppGrayScale = (4 | (16 << 8) |PixelFormatExtended) ; $100
Global PixelFormat16bppRGB555 = (5 | (16 << 8) |PixelFormatGDI)
Global PixelFormat16bppRGB565 = (6 | (16 << 8) |PixelFormatGDI)
Global PixelFormat16bppARGB1555 = (7 | (16 << 8) |PixelFormatAlpha |PixelFormatGDI)
Global PixelFormat24bppRGB = (8 | (24 << 8) |PixelFormatGDI)
Global PixelFormat32bppRGB = (9 | (32 << 8) |PixelFormatGDI)
Global PixelFormat32bppARGB = (10 | (32 << 8) |PixelFormatAlpha |PixelFormatGDI |PixelFormatCanonical)
Global PixelFormat32bppPARGB = (11 | (32 << 8) |PixelFormatAlpha |PixelFormatPAlpha |PixelFormatGDI)
Global PixelFormat48bppRGB = (12 | (48 << 8) |PixelFormatExtended)
Global PixelFormat64bppARGB = (13 | (64 << 8) |PixelFormatAlpha |PixelFormatCanonical |PixelFormatExtended)
Global PixelFormat64bppPARGB = (14 | (64 << 8) |PixelFormatAlpha |PixelFormatPAlpha |PixelFormatExtended)
Global PixelFormatMax = 15
CompilerIf Defined(GdiplusStartupInput, #PB_Structure) = 0
Structure GdiplusStartupInput
GdiPlusVersion.l
*DebugEventCallback.Debug_Event
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
CompilerEndIf
Structure StreamObject
block.l
*bits
stream.ISTREAM
EndStructure
Procedure StringToBStr (string$) ; By Zapman Inspired by Fr34k
Protected Unicode$ = Space(Len(String$)* 2 + 2)
Protected bstr_string.l
PokeS(@Unicode$, String$, -1, #PB_Unicode)
bstr_string = SysAllocString_(@Unicode$)
ProcedureReturn bstr_string
EndProcedure
ProcedureDLL ImageFromMem(Address, Length)
Protected lib.l
lib = OpenLibrary(#PB_Any, "gdiplus.dll")
If Not lib
ProcedureReturn 0
EndIf
Define.l *token ,*image ,*gfx
Define.l Width ,Height ,Format ,bits_per_pixel ,imagenumber ,Retval ,hDC
Define.GdiplusStartupInput input
Define.streamobject stream
input\GdiPlusVersion = 1
CallFunction(lib, "GdiplusStartup", @*token, @input, #Null)
If *token
Stream\block = GlobalAlloc_(#GHND, Length)
Stream\bits = GlobalLock_(Stream\block)
CopyMemory(address, stream\bits, Length)
If CreateStreamOnHGlobal_(stream\bits, 0, @Stream\stream) = #S_OK
CallFunction(lib, "GdipCreateBitmapFromStream", Stream\stream , @*image)
Stream\stream\Release()
GlobalUnlock_(Stream\bits)
GlobalFree_(Stream\block)
Else
CallFunction(lib, "GdiplusShutdown", *token)
ProcedureReturn 0
EndIf
If *image
CallFunction(lib, "GdipGetImageWidth", *image, @Width)
CallFunction(lib, "GdipGetImageHeight", *image, @Height)
CallFunction(lib, "GdipGetImagePixelFormat", *image, @Format)
Select Format
Case PixelFormat1bppIndexed: bits_per_pixel = 1
Case PixelFormat4bppIndexed: bits_per_pixel = 4
Case PixelFormat8bppIndexed: bits_per_pixel = 8
Case PixelFormat16bppARGB1555: bits_per_pixel = 16
Case PixelFormat16bppGrayScale: bits_per_pixel = 16
Case PixelFormat16bppRGB555: bits_per_pixel = 16
Case PixelFormat16bppRGB565: bits_per_pixel = 16
Case PixelFormat24bppRGB: bits_per_pixel = 24
Case PixelFormat32bppARGB: bits_per_pixel = 32
Case PixelFormat32bppPARGB: bits_per_pixel = 32
Case PixelFormat32bppRGB: bits_per_pixel = 32
Case PixelFormat48bppRGB: bits_per_pixel = 48
Case PixelFormat64bppARGB: bits_per_pixel = 64
Case PixelFormat64bppPARGB: bits_per_pixel = 64
Default : bits_per_pixel = 32
EndSelect
If bits_per_pixel < 24 : bits_per_pixel = 24 : EndIf
imagenumber = CreateImage(#PB_Any, Width, Height, bits_per_pixel)
Retval = ImageID(imagenumber)
hDC = StartDrawing(ImageOutput(ImageNumber))
CallFunction(lib, "GdipCreateFromHDC", hdc, @*gfx)
CallFunction(lib, "GdipDrawImageRectI", *gfx, *image, 0, 0, Width, Height)
StopDrawing()
CallFunction(lib, "GdipDeleteGraphics", *gfx)
CallFunction(lib, "GdipDisposeImage", *image)
CallFunction(lib, "GdiplusShutdown", *token)
CloseLibrary(0)
ProcedureReturn Retval
Else
ProcedureReturn 0
EndIf
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL ImageFromFile(Filename$)
Protected lib.l
lib = OpenLibrary(#PB_Any, "gdiplus.dll")
If Not lib
ProcedureReturn 0
EndIf
Define.l *token ,*image ,*gfx
Define.l Width ,Height ,Format ,bits_per_pixel ,imagenumber ,Retval ,hDC
Define.GdiplusStartupInput input
Define.streamobject stream
input\GdiPlusVersion = 1
CallFunction(lib, "GdiplusStartup", @*token, @input, #Null)
If *token
CallFunction(lib, "GdipCreateBitmapFromFile", StringToBStr(Filename$), @*image)
CallFunction(lib, "GdipGetImageWidth", *image, @Width.l)
CallFunction(lib, "GdipGetImageHeight", *image, @Height.l)
CallFunction(lib, "GdipGetImagePixelFormat", *image, @Format.l)
Select Format
Case PixelFormat1bppIndexed: bits_per_pixel = 1
Case PixelFormat4bppIndexed: bits_per_pixel = 4
Case PixelFormat8bppIndexed: bits_per_pixel = 8
Case PixelFormat16bppARGB1555: bits_per_pixel = 16
Case PixelFormat16bppGrayScale: bits_per_pixel = 16
Case PixelFormat16bppRGB555: bits_per_pixel = 16
Case PixelFormat16bppRGB565: bits_per_pixel = 16
Case PixelFormat24bppRGB: bits_per_pixel = 24
Case PixelFormat32bppARGB: bits_per_pixel = 32
Case PixelFormat32bppPARGB: bits_per_pixel = 32
Case PixelFormat32bppRGB: bits_per_pixel = 32
Case PixelFormat48bppRGB: bits_per_pixel = 48
Case PixelFormat64bppARGB: bits_per_pixel = 64
Case PixelFormat64bppPARGB: bits_per_pixel = 64
Default : bits_per_pixel = 32
EndSelect
If bits_per_pixel < 24 : bits_per_pixel = 24 : EndIf
imagenumber = CreateImage(#PB_Any, Width, Height, bits_per_pixel)
Retval = ImageID(imagenumber)
hDC = StartDrawing(ImageOutput(ImageNumber))
CallFunction(lib, "GdipCreateFromHDC", hdc, @*gfx)
CallFunction(lib, "GdipDrawImageRectI", *gfx, *image, 0, 0, Width, Height)
StopDrawing()
CallFunction(lib, "GdipDeleteGraphics", *gfx)
CallFunction(lib, "GdipDisposeImage", *image)
CallFunction(lib, "GdiplusShutdown", *token)
CloseLibrary(lib)
ProcedureReturn imagenumber
Else
ProcedureReturn 0
EndIf
EndProcedure
;Constants for blend modes
#BLM_AVERAGE = 1 ; Average mode
#BLM_MULTIPLY = 2 ; Multiply mode
#BLM_SCREEN = 3 ; Screen mode
#BLM_DARKEN = 4 ; Darken mode
#BLM_LIGHTEN = 5 ; Lighten mode
#BLM_DIFFERENCE = 6 ; Difference mode
#BLM_NEGATION = 7 ; Negation mode
#BLM_EXCLUSION = 8 ; Exclusion mode
#BLM_OVERLAY = 9 ; Overlay mode
#BLM_HARDLIGHT = 10 ; Hard Light mode
#BLM_SOFTLIGHT = 11 ; Soft Light mode
#BLM_COLORDODGE = 12 ; Color Dodge mode
#BLM_COLORBURN = 13 ; Color Burn mode
#BLM_SOFTDODGE = 14 ; Soft dodge mode
#BLM_SOFTBURN = 15 ; Soft burn mode
#BLM_REFLECT = 16 ; Reflect mode
#BLM_GLOW = 17 ; Glow mode
#BLM_FREEZE = 18 ; Freeze mode
#BLM_HEAT = 19 ; Heat mode
#BLM_ADDITIVE = 20 ; Additive mode
#BLM_SUBTRACTIVE = 21 ; Subtractive mode
#BLM_INTERPOLATION = 22 ; Interpolation mode
#BLM_STAMP = 23 ; Stamp mode
#BLM_XOR = 24 ; XOR mode
;Constants for Histogram functions like GPX_StretchHistogram
#HST_RED = 1 ; Red
#HST_GREEN = 2 ; Green
#HST_BLUE = 4 ; Blue
#HST_COLOR = 7 ; All the colors
#HST_GRAY = 8 ; Gray
;Contants for Gradient functions like GPX_Metallic
#GRAD_METALLIC = 1 ; Metallic
#GRAD_GOLD = 2 ; Gold gradient
#GRAD_ICE = 3 ; Ice gradient
#COLOR_SIZE =256
#MAXINTENSITY = 255
#ANGLE_PERCENTAGE = 0.01745329
#COLOR_PERCENTAGE = 2.55
#RAND_MAX = 32767
Structure Histogram
Table.l[256]
Minimum.l
Maximum.l
EndStructure
Structure ColorAmp
Low.l
High.l
LowRed.l
LowGreen.l
LowBlue.l
HighRed.l
HighGreen.l
HighBlue.l
EndStructure
Macro DoEvents ()
Define.MSG Msg
While (PeekMessage_ (@Msg, #Null, 0, 0, #PM_REMOVE))
If (Msg\message = #WM_QUIT)
Break
EndIf
TranslateMessage_ (@Msg)
DispatchMessage_ (@Msg)
Wend
EndMacro
Macro ImageToArray()
PicSrcDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
PicDestDC= CreateDC_("DISPLAY", #Null, #Null, #Null)
GetObject_(ImageID(SImage), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
TemporaryBitmapInfo\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
TemporaryBitmapInfo\bmiHeader\biWidth = TemporaryBitmap\bmWidth
TemporaryBitmapInfo\bmiHeader\biHeight = -TemporaryBitmap\bmHeight
TemporaryBitmapInfo\bmiHeader\biPlanes = 1
TemporaryBitmapInfo\bmiHeader\biBitCount = 24
TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
Width = TemporaryBitmap\bmWidth
Height = TemporaryBitmap\bmHeight
LineWidth = Width * 3
If (LineWidth % 4)
LineWidth + (4 - LineWidth % 4)
EndIf
BitCount = LineWidth * (Height+1); +1 da bei Canvas Array zu klein ??
Dim bits.c (BitCount)
GetDIBits_(PicSrcDC, ImageID(SImage), 0, TemporaryBitmap\bmHeight, bits(), TemporaryBitmapInfo.BITMAPINFO, #DIB_RGB_COLORS)
EndMacro
Macro ArrayToImage(Memory)
SetDIBits_(PicDestDC, ImageID(DImage), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo.BITMAPINFO, #DIB_RGB_COLORS)
DeleteDC_(PicDestDC)
DeleteDC_(PicSrcDC)
EndMacro
Procedure.l min(n1.l,min.l)
!MOV Eax,dword[p.v_n1]
!MOV Ecx,dword[p.v_min]
!CMP Ecx,Eax
!cmovg Eax,Ecx
ProcedureReturn
EndProcedure
Procedure.l Max(n1.l,max.l)
!MOV Eax,dword[p.v_n1]
!MOV Ecx,dword[p.v_max]
!CMP Eax,Ecx
!cmovg Eax,Ecx
ProcedureReturn
EndProcedure
Procedure.l Lim_Max (now.l, up.l, max.l)
max-1
While (now > max - up)
up-1
Wend
ProcedureReturn up
EndProcedure
Procedure.d ATan2(x.d, y.d)
!FLD qword[p.v_y]
!FLD qword[p.v_x]
!FPATAN
ProcedureReturn
EndProcedure
Procedure.l LimitValues (x.l)
!mov eax,dword[p.v_x]
!xor edx,edx ; set EDX to zero
!cmp eax,0 ; compare with top limit
!cmovl eax,edx ;
!mov edx,255 ; 255
!cmp eax,edx ; compare with bottom limit
!cmovg eax,edx ; if lower, set value to bottom limit
ProcedureReturn
EndProcedure
Macro Exp(x)
(Pow(2,x#/Log(2)))
EndMacro
; Macro RGB(Red, Green, Blue)
; (((Blue << 8 + Green) << 8 ) + Red )
; EndMacro
Macro FastRed(color)
color & 255
EndMacro
Macro FastGreen(color)
(color & 65535) >> 8
EndMacro
Macro FastBlue(color)
(color & 16777215) >> 16
EndMacro
Procedure ShiftTable (Array Table.c(1),Shift.l)
Protected i.l
Dim tempTable.c (#COLOR_SIZE)
Define.l NewPosition
CopyMemory (@Table(), @tempTable(), #COLOR_SIZE)
For i = 0 To 255
NewPosition = Int(Abs(i + Shift)) & $000000FF
Table(NewPosition) = tempTable(i)
Next
EndProcedure
Procedure.c GetIntensity(r.c,g.c,b.c)
ProcedureReturn Int(R * 0.3 + G * 0.59 + B * 0.11)
EndProcedure
Procedure.l MostFrequentColor (Array bits.c(1),Width.l ,Height.l , x.l , y.l , Radius.l, Intensity.l)
Define.l i ,iCount , w, h, color,LineWidth ,MaxInstance ,BrushSize ,Smoothness
Define.l R, G, B
Define.d Scale = Intensity / 255.0
LineWidth = Width * 3
If (LineWidth % 4)
LineWidth + (4 - LineWidth % 4)
EndIf
BrushSize = Min(Max( BrushSize,5 ), 1)
Smoothness = Min(Max( Smoothness,255 ), 10)
Dim IntensityCount.c (Intensity + 1)
Dim AverageColorR.l (Intensity + 1)
Dim AverageColorG.l (Intensity + 1)
Dim AverageColorB.l (Intensity + 1)
FillMemory(@IntensityCount(),Intensity + 1 , #Null , #PB_Byte)
For w = X - Radius To X + Radius
For h = Y - Radius To Y + Radius
If ((w >= 0) And (w < Width) And (h >= 0) And (h < Height))
i = h * LineWidth + 3 * w
iCount = GetIntensity (Bits(i+2), Bits(i+1), Bits(i))* Scale
IntensityCount(iCount)+1
If (IntensityCount(iCount) = 1)
AverageColorR(iCount) = Bits(i+2)
AverageColorG(iCount) = Bits(i+1)
AverageColorB(iCount) = Bits( i )
Else
AverageColorR(iCount) + Bits(i+2)
AverageColorG(iCount) + Bits(i+1)
AverageColorB(iCount) + Bits( i )
EndIf
EndIf
Next
Next
iCount=0
For i = 0 To Intensity
If (IntensityCount(i) > MaxInstance)
iCount= i
MaxInstance = IntensityCount(i)
EndIf
Next
R = AverageColorR(iCount) / MaxInstance
G = AverageColorG(iCount) / MaxInstance
B = AverageColorB(iCount) / MaxInstance
ProcedureReturn RGB (R, G, B)
EndProcedure
Procedure.l AssignTables (Array RedTable.c(1), Array GreenTable.c(1), Array BlueTable.c(1), Array Bits.c(1), Width, Height)
Define.l LineWidth = Width * 3
Define.l h, w, i
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
Bits(i+2) = RedTable(Bits(i+2))
Bits(i+1) = GreenTable(Bits(i+1))
Bits( i ) = BlueTable(Bits( i ))
Next
Next
EndProcedure
Procedure.l GradientValue ( FirstValue.d, SecondValue.d, Gradient.d)
If (Gradient = 0.0)
ProcedureReturn FirstValue
EndIf
If (Gradient = 255.0)
ProcedureReturn SecondValue
EndIf
ProcedureReturn ((FirstValue * (255 - Gradient) + SecondValue * Gradient) / 256)
EndProcedure
Procedure.l MakeGradient ( *cAmp.ColorAmp,Array rTable.c(1),Array gTable.c(1),Array bTable.c(1))
Define.l i
Define.d delta, temp
If (*cAmp\High = *cAmp\Low)
ProcedureReturn
EndIf
delta = 255.0 / (*cAmp\High - *cAmp\Low)
For i = *cAmp\Low To *cAmp\High
temp = (i - *cAmp\Low) * delta
rTable(i) = GradientValue (*cAmp\LowRed, *cAmp\HighRed, temp)
gTable(i) = GradientValue (*cAmp\LowGreen, *cAmp\HighGreen, temp)
bTable(i) = GradientValue (*cAmp\LowBlue, *cAmp\HighBlue, temp)
Next
EndProcedure
Procedure.l RandomColor (Array Bits.c(1), Width.l, Height.l, X.l, Y.l,radius.l)
Define.l i, w, h, color, counter ,LineWidth,RandNumber, count, Index, ErrorCount
Define.c R, G, B,Icont
LineWidth = 3 * Width
If (LineWidth % 4)
LineWidth + (4 - LineWidth % 4)
EndIf
Dim IntensityCount.c(#MAXINTENSITY + 1)
Dim AverageColorR.l(#MAXINTENSITY + 1)
Dim AverageColorG.l(#MAXINTENSITY + 1)
Dim AverageColorB.l(#MAXINTENSITY + 1)
For w = X - Radius To X + Radius
For h = Y - Radius To Y + Radius
If ((w >= 0) And (w < Width) And (h >= 0) And (h < Height))
i = h * LineWidth + 3 * w
Icont = (GetIntensity (Bits(i+2), Bits(i+1), Bits(i)))
If (IntensityCount(Icont) = 1)
AverageColorR(Icont) = Bits(i+2)
AverageColorG(Icont) = Bits(i+1)
AverageColorB(Icont) = Bits( i )
EndIf
Else
AverageColorR(Icont) + Bits(i+2)
AverageColorG(Icont) + Bits(i+1)
AverageColorB(Icont) + Bits( i )
EndIf
IntensityCount(Icont)+1
counter+1
Next
Next
While IntensityCount(Icont) = 0 And ErrorCount <= counter
RandNumber = int((Random(#RAND_MAX)+1) * (counter / (#RAND_MAX +1)))
count = 0
Index = 0
While count < RandNumber
count + IntensityCount(Index)
Index+1
Wend
Icont = Index -1
ErrorCount+1
Wend
If ErrorCount >= counter
R = AverageColorR(Icont) / counter
G = AverageColorG(Icont) / counter
B = AverageColorB(Icont) / counter
Else
R = AverageColorR(Icont) / IntensityCount(Icont)
G = AverageColorG(Icont) / IntensityCount(Icont)
B = AverageColorB(Icont) / IntensityCount(Icont)
EndIf
color = RGB (R, G, B)
ProcedureReturn (color)
EndProcedure
Procedure.l ApplyMetallicLayer (Array Bits.c(1),Width.l ,Height.l ,Levels.l)
Define.l j, k
Dim mTable.c (#COLOR_SIZE)
If Levels < 2
ProcedureReturn
EndIf
For j = 0 To 254
For k = 0 To 255
mTable(j+1) = k
Next
While k > 1
mTable(j+1) = k
k-Levels
Wend
If Levels % 2 = 0
mTable(255) = 0
Else
mTable(255) = 255
EndIf
AssignTables (mTable(), mTable(), mTable(), Bits(), Width, Height)
Next
EndProcedure
Procedure.l ApplyMetallicShiftLayer (Array Bits.c(1),Width.l,Height.l,Levels.l,Shift.l)
Define.ColorAmp cAmp
Dim mTable.c (#COLOR_SIZE)
If (Levels < 1)
ProcedureReturn
EndIf
Define.l i, factor = 255 / Levels
For i = 0 To Levels-1
If i % 2
cAmp\Low = i * factor
cAmp\LowRed = 255
cAmp\LowGreen = 255
cAmp\LowBlue = 255
cAmp\High = (i + 1) * factor
cAmp\HighRed = 0
cAmp\HighGreen = 0
cAmp\HighBlue = 0
mTable(255) = 0
Else
cAmp\Low = i * factor + 1
cAmp\LowRed = 0
cAmp\LowGreen = 0
cAmp\LowBlue = 0
cAmp\High = (i + 1) * factor
cAmp\HighRed = 255
cAmp\HighGreen = 255
cAmp\HighBlue = 255
mTable(255) = 255
EndIf
MakeGradient (@cAmp, mTable(), mTable(), mTable())
Next
ShiftTable (mTable(), Shift)
AssignTables (mTable(), mTable(), mTable(), Bits(), Width, Height)
EndProcedure
Procedure.l ApplyGoldLayer (Array Bits.c(1),Width.l ,Height.l)
Define.ColorAmp cAmp
Dim rTable.c (#COLOR_SIZE)
Dim gTable.c (#COLOR_SIZE)
Dim bTable.c (#COLOR_SIZE)
FillMemory(@rTable(), #COLOR_SIZE , #Null , #PB_Long)
FillMemory(@gTable(), #COLOR_SIZE , #Null , #PB_Long)
FillMemory(@bTable(), #COLOR_SIZE , #Null , #PB_Long)
cAmp\Low = 0
cAmp\LowRed = 0
cAmp\LowGreen = 0
cAmp\LowBlue = 0
cAmp\High = 55
cAmp\HighRed = 190
cAmp\HighGreen = 55
cAmp\HighBlue = 0
MakeGradient (@cAmp, rTable(), gTable(), bTable())
cAmp\Low = 55
cAmp\LowRed = 190
cAmp\LowGreen = 55
cAmp\LowBlue = 0
cAmp\High = 155
cAmp\HighRed = 255
cAmp\HighGreen = 190
cAmp\HighBlue = 50
MakeGradient (@cAmp, rTable(), gTable(), bTable())
cAmp\Low = 155
cAmp\LowRed = 255
cAmp\LowGreen = 190
cAmp\LowBlue = 50
cAmp\High = 255
cAmp\HighRed = 255
cAmp\HighGreen = 255
cAmp\HighBlue = 255
MakeGradient (@cAmp, rTable(), gTable(), bTable())
AssignTables (rTable(), gTable(), bTable(), Bits(), Width, Height)
EndProcedure
Procedure.l ApplyIceLayer (Array Bits.c(1),Width.l ,Height.l )
Define.ColorAmp cAmp
Dim rTable.c (#COLOR_SIZE)
Dim gTable.c (#COLOR_SIZE)
Dim bTable.c (#COLOR_SIZE)
FillMemory(@rTable(), #COLOR_SIZE , #Null , #PB_Long)
FillMemory(@gTable(), #COLOR_SIZE , #Null , #PB_Long)
FillMemory(@bTable(), #COLOR_SIZE , #Null , #PB_Long)
cAmp\Low = 0
cAmp\LowRed = 0
cAmp\LowGreen = 0
cAmp\LowBlue = 0
cAmp\High = 55
cAmp\HighRed = 0
cAmp\HighGreen = 65
cAmp\HighBlue = 205
MakeGradient (@cAmp, rTable(), gTable(), bTable())
cAmp\Low = 55
cAmp\LowRed = 0
cAmp\LowGreen = 65
cAmp\LowBlue = 205
cAmp\High = 155
cAmp\HighRed = 65
cAmp\HighGreen = 205
cAmp\HighBlue = 255
MakeGradient (@cAmp, rTable(), gTable(), bTable())
cAmp\Low = 155
cAmp\LowRed = 65
cAmp\LowGreen = 205
cAmp\LowBlue = 255
cAmp\High = 255
cAmp\HighRed = 255
cAmp\HighGreen = 255
cAmp\HighBlue = 255
MakeGradient (@cAmp, rTable(), gTable(), bTable())
AssignTables (rTable(), gTable(), bTable(), Bits(), Width, Height)
EndProcedure
Procedure.d ProportionalValue ( DestValue.d, SrcValue.d, Shade.l)
If Shade = 0.0
ProcedureReturn DestValue
EndIf
If Shade = 255.0
ProcedureReturn SrcValue
EndIf
ProcedureReturn (DestValue * (255.0 - Shade) + SrcValue * Shade) / 256.0
EndProcedure
Procedure.d MaximumRadius ( Height.l , Width.l , Angle.d)
Define.d MaxRad, MinRad
Define.d Radius, DegAngle = Abs (Angle * 57.295)
MinRad = min(Height, Width)/ 2.0
MaxRad = max(Height, Width)/ 2.0
If (DegAngle > 90.0)
Radius = ProportionalValue (MinRad, MaxRad, (DegAngle * (255.0 / 90.0)))
Else
Radius = ProportionalValue (MaxRad, MinRad, ((DegAngle - 90.0) * (255.0 / 90.0)))
EndIf
ProcedureReturn Radius
EndProcedure
Procedure.l ShadeColors (DestColor.l, SrcColor.l, Shade.l)
If Shade = 0
ProcedureReturn DestColor
EndIf
If Shade = 255
ProcedureReturn SrcColor
EndIf
ProcedureReturn ((DestColor * (255 - Shade) + SrcColor * Shade) >> 8)
EndProcedure
Procedure.l AspectSize(source_w.l ,source_h.l ,*dest_w.l ,*dest_h.l )
Protected aspect.f,w.l,h.l,width.l,height.l
If source_w=0 Or source_h=0 Or *dest_w=0 Or *dest_h=0
ProcedureReturn
EndIf
width = PeekL(*dest_w)
height = PeekL(*dest_h)
aspect = source_w / source_h
w = width
h = width / aspect
If h > height
w = height * aspect
h = height
EndIf
;wichtig fuer metall
If (W % 4)
W+ (4 - W % 4)
EndIf
PokeL( *dest_w, w)
PokeL( *dest_h, h)
EndProcedure
Procedure.l FindHistoMinAndMaxValues ( *Histo.Histogram)
Define.l hMin = 0, hMax = 255
While *Histo\Table[hMin] = 0 And hMin < 255
hMin+1
Wend
While *Histo\Table[hMax] = 0 And hMax > 0
hMax-1
Wend
*Histo\Minimum = hMin
*Histo\Maximum = hMax
EndProcedure
Procedure.l GetHistogram (Array Bits.c(1),Width.l ,Height.l ,*tmp.Histogram,Flag.l )
Define.l i, j, index, LineWidth
LineWidth = 3 * Width
If (LineWidth % 4)
LineWidth + (4 - LineWidth % 4)
EndIf
For i = 0 To Width-1
For j = 0 To Height-1
index = j * LineWidth + 3 * i
If (Flag = #HST_RED)
*tmp\Table[Bits(index+2)]+1
ElseIf (Flag = #HST_GREEN)
*tmp\Table[Bits(index+1)]+1
ElseIf (Flag = #HST_BLUE)
*tmp\Table[Bits( index )]+1
EndIf
Next
Next
EndProcedure
Procedure.l Flip (DImage.l ,SImage.l ,Width.l ,Height.l ,Horizontal.l ,Vertical.l)
Define.l PicDestDC, PicSrcDC
PicDestDC= StartDrawing(ImageOutput(DImage))
PicSrcDC = CreateCompatibleDC_(#Null)
SelectObject_(PicSrcDC, ImageID(SImage))
If Horizontal And Vertical
StretchBlt_ (PicDestDC, 0, 0, Width, Height, PicSrcDC, Width - 1,Height - 1, -Width, -Height, #SRCCOPY)
ElseIf Horizontal
StretchBlt_ (PicDestDC, 0, 0, Width, Height, PicSrcDC, Width - 1, 0, -Width, Height, #SRCCOPY)
ElseIf Vertical
StretchBlt_ (PicDestDC, 0, 0, Width, Height, PicSrcDC, 0, Height - 1, Width, -Height, #SRCCOPY)
EndIf
StopDrawing()
DeleteDC_(PicSrcDC)
EndProcedure
Procedure.l StretchHistogram (DImage.l ,SImage.l , Flag.l , StretchFactor.d)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
ImageToArray()
If (StretchFactor > 2.0)
StretchFactor = 2.0
EndIf
If (StretchFactor < 0.0)
StretchFactor = 0.0
EndIf
Define.l i , h, w,GrayPixel
If (Flag & #HST_GRAY)
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
GrayPixel = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
Bits(i+2) = GrayPixel
Bits(i+1) = GrayPixel
Bits(i) = GrayPixel
Next
Next
Flag = #HST_COLOR
EndIf
Define.Histogram Red, Green, Blue
Define.l ORR, ORG, ORB
Define.l SRR, SRG, SRB
Define.d ScaleFactorR, ScaleFactorG, ScaleFactorB
If (Flag & #HST_RED)
GetHistogram (Bits(), Width, Height, @Red, #HST_RED)
FindHistoMinAndMaxValues (@Red)
ORR = Red\Maximum - Red\Minimum
SRR = ORR + Round (StretchFactor * (255 - ORR),#PB_Round_Up)
If (Not ORR)
ScaleFactorR = 1.0
Else
ScaleFactorR = SRR / ORR
EndIf
EndIf
If (Flag & #HST_GREEN)
GetHistogram (Bits(), Width, Height, @Green, #HST_GREEN)
FindHistoMinAndMaxValues (@Green)
ORG = Green\Maximum - Green\Minimum
SRG = ORG + Round (StretchFactor * (255 - ORG),#PB_Round_Up)
If (Not ORG)
ScaleFactorG = 1.0
Else
ScaleFactorG = SRG / ORG
EndIf
EndIf
If (Flag & #HST_BLUE)
GetHistogram (Bits(), Width, Height, @Blue,#HST_BLUE)
FindHistoMinAndMaxValues (@Blue)
ORB = Blue\Maximum - Blue\Minimum
SRB = ORB + Round (StretchFactor * (255 - ORB),#PB_Round_Up)
If (Not ORB)
ScaleFactorB = 1.0
Else
ScaleFactorB = SRB / ORB
EndIf
EndIf
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
If (Flag & 1)
Bits(i+2) = LimitValues (Round (ScaleFactorR * (Bits(i+2) - Red\Minimum),#PB_Round_Up))
EndIf
If (Flag & 2)
Bits(i+1) = LimitValues (Round (ScaleFactorG * (Bits(i+1) - Green\Minimum),#PB_Round_Up))
EndIf
If (Flag & 4)
Bits( i ) = LimitValues (Round (ScaleFactorB * (Bits( i ) - Blue\Minimum),#PB_Round_Up))
EndIf
Next
Next
ArrayToImage(bits())
EndProcedure
Procedure Shift (DImage.l ,SImage.l ,Shift.l )
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l
ImageToArray()
Shift=min(max(Shift,255),0)
Define.l i , j
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
Bits( i ) = ShadeColors (Bits( i ), Bits(i+1), Shift)
Bits(i+1) = ShadeColors (Bits(i+1), Bits( i ), Shift)
Next
Next
ArrayToImage(bits())
EndProcedure
Procedure.l Hue (DImage.l ,SImage.l , Hue.l)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l
ImageToArray()
Define.l i , j , table
Define.l temp
Hue = min(max(Hue,350),0)
table = Hue / 50
If table > 6
table = 6
EndIf
For w = 0 To Width-1
For h = 0 To Height-1
i = h * LineWidth + 3 * w
Select table
Case 0
Bits(i+1) = ShadeColors (Bits(i+1), Bits(i+2), Int(Hue * 5.12))
Case 1
Bits(i+1) = Bits(i+2)
Bits(i+2) = ShadeColors (Bits(i+2), Bits( i ), Int((Hue - 50) * 5.12))
Case 2
Bits(i+1) = Bits(i+2)
Bits(i+2) = Bits( i )
Bits( i ) = ShadeColors (Bits( i ), Bits(i+1), Int((Hue - 100) * 5.12))
Case 3
temp = Bits( i )
Bits(i+1) = Bits( i ) = Bits(i+2)
Bits(i+2) = temp
Bits(i+1) = ShadeColors (Bits(i+1), Bits(i+2), Int((Hue - 150) * 5.12))
Case 4
temp = Bits( i )
Bits( i ) = Bits(i+2)
Bits(i+1) = Bits(i+2) = temp
Bits(i+2) = ShadeColors (Bits(i+2), Bits( i ), Int((Hue - 200) * 5.12))
Case 5
Bits(i+1) = Bits( i )
Bits( i ) = Bits(i+2)
Bits( i ) = ShadeColors (Bits( i ), Bits(i+1), Int((Hue - 250) * 5.11))
Case 6
temp = Bits(i+1)
Bits(i+1) = Bits( i )
Bits(i+1) = ShadeColors (Bits(i+1), temp, Int((Hue - 300) * 5.11))
EndSelect
Next
Next
ArrayToImage(bits())
EndProcedure
Procedure.l WebColors (DImage.l ,SImage.l )
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,Shift ,k.l, Color.l
Define.l i , j
ImageToArray()
Shift=min(max(Shift,255),0)
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
For k = 0 To 2
Color = Bits(i+k)
If (Color < 26) : Bits(i+k) = 0
ElseIf (Color < 77) : Bits(i+k) = 51
ElseIf (Color < 128) : Bits(i+k) = 102
ElseIf (Color < 179) : Bits(i+k) = 153
ElseIf (Color < 230) : Bits(i+k) = 204
Else : Bits(i+k) = 255
EndIf
Next
Next
Next
ArrayToImage(bits())
EndProcedure
Procedure.l NotePaper (DImage.l ,SImage.l ,Sensibility.l ,Depth.l ,Graininess.l ,Intensity.l ,Forecolor.l = #Black ,Backcolor.l =#White )
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
ImageToArray()
Dim Newbits.c (BitCount)
Define.l ForeR = (Forecolor & $000000FF)
Define.l ForeG = (Forecolor & $0000FF00) >> 8
Define.l ForeB = (Forecolor & $00FF0000) >> 16
Define.l BackR = (Backcolor & $000000FF)
Define.l BackG = (Backcolor & $0000FF00) >> 8
Define.l BackB = (Backcolor & $00FF0000) >> 16
If (((ForeR + ForeG + ForeB) / 3) <= 10)
ForeR + 127
ForeG + 127
ForeB + 127
EndIf
If (((BackR + BackG + BackB) / 3) <= 10)
BackR + 127
BackG + 127
BackB + 127
EndIf
Sensibility = LimitValues (Sensibility)
Depth = min(max(Depth ,5) , 1)
Graininess = min(max(Graininess ,60) , 0 )
Intensity = min(max(Intensity ,10), 0 )
Define.l i , j , h, w, RandValue, Shadow
RandomSeed(timeGetTime_())
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
If (((Bits(i+2) + Bits(i+1) + Bits(i)) / 3) < Sensibility)
Bits(i+2) = ForeR
Bits(i+1) = ForeG
Bits( i ) = ForeB
Else
Bits(i+2) = BackR
Bits(i+1) = BackG
Bits( i ) = BackB
EndIf
Next
Next
If (Graininess > 0)
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
If ((Bits(i+2) = BackR) And (Bits(i+1) = BackG) And (Bits(i) = BackB))
RandValue = Random( Graininess)
If (RandValue % 2)
RandValue = 0
EndIf
If (((Bits(i+2) + Bits(i+1) + Bits(i)) / 3) > 127)
RandValue = -RandValue
EndIf
Bits(i+2) = LimitValues (Bits(i+2) + RandValue)
Bits(i+1) = LimitValues (Bits(i+1) + RandValue)
Bits( i ) = LimitValues (Bits( i ) + RandValue)
ElseIf ((Bits(i+2) = ForeR) And (Bits(i+1) = ForeG) And (Bits(i) = ForeB))
RandValue = Random( Graininess)
If (RandValue % 2)
RandValue = 0
EndIf
If (((Bits(i+2) + Bits(i+1) + Bits(i)) / 3) > 127)
RandValue = -RandValue
EndIf
Bits(i+2) = LimitValues (Bits(i+2) + RandValue)
Bits(i+1) = LimitValues (Bits(i+1) + RandValue)
Bits( i ) = LimitValues (Bits( i ) + RandValue)
EndIf
Next
Next
EndIf
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
j = (h + Lim_Max (h, Depth, Height)) * LineWidth + 3 * (w + Lim_Max (w, Depth, Width))
Shadow = Intensity * (Bits(j+2) - Bits(i+2))
Shadow + Intensity * (Bits(j+1) - Bits(i+1))
Shadow + Intensity * (Bits( j ) - Bits( i ))
Shadow /3
NewBits(i+2) = LimitValues (Bits(i+2) - Shadow)
NewBits(i+1) = LimitValues (Bits(i+1) - Shadow)
NewBits( i ) = LimitValues (Bits( i ) - Shadow)
Next
Next
ArrayToImage(Newbits())
EndProcedure
Procedure.l Relief (DImage.l ,SImage.l)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,j.l
ImageToArray()
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
j = (h + Lim_Max (h, 2, Height)) * LineWidth + 3 * (w + Lim_Max (w, 2, Width))
bits(i+2) = LimitValues ((bits(i+2) - bits(j+2)) + 128)
bits(i+1) = LimitValues ((bits(i+1) - bits(j+1)) + 128)
bits( i ) = LimitValues ((bits( i ) - bits( j )) + 128)
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure.l Neon (DImage.l ,SImage.l ,Intensity.l =1,BW.l =1)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,j.l ,k.l ,color_1.l,color_2.l
ImageToArray()
If bw <1 : bw=1: EndIf
For h = 0 To Height-1
For w = 0 To Width-1
For k = 0 To 2
i = h * LineWidth + 3 * w
j = h * LineWidth + 3 * (w + Lim_Max (w, BW, Width))
color_1 = Int((Bits(i+k) - Bits(j+k)) * (Bits(i+k) - Bits(j+k)))
j = (h + Lim_Max (h, BW, Height)) * LineWidth + 3 * w
color_2 = Int((Bits(i+k) - Bits(j+k)) * (Bits(i+k) - Bits(j+k)))
Bits(i+k) = LimitValues (Int(Sqr ((color_1 + color_2))) << Intensity)
Next
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure.l Rock (DImage.l ,SImage.l ,Value.l =10)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,j.l
ImageToArray()
For h = 1 To Height-1
For w = 1 To Width-1
j = h * LineWidth + 3 * w
i = (h - 1) * LineWidth + 3 * (w - 1)
Bits(i+2) = LimitValues (Bits(i+2) + (Value * (Bits(i+2) - Bits(j+2))))
Bits(i+1) = LimitValues (Bits(i+1) + (Value * (Bits(i+1) - Bits(j+1))))
Bits( i ) = LimitValues (Bits( i ) + (Value * (Bits( i ) - Bits( j ))))
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure sharpen (DImage,SImage,Value.f=0.9)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,j.l
ImageToArray()
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
j = Abs((h - 1) * LineWidth + 3 * (w - 1))
Bits(i+2) = LimitValues (Bits(i+2) + Int((Value * (Bits(i+2) - Bits(j+2)))))
Bits(i+1) = LimitValues (Bits(i+1) + Int((Value * (Bits(i+1) - Bits(j+1)))))
Bits( i ) = LimitValues (Bits( i ) + Int((Value * (Bits( i ) - Bits( j )))))
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure AmbientLight (DImage,SImage,Value=10,AmbientColor=#Green)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,Intensity.l
Define.c LightR ,LightG ,LightB
ImageToArray()
Intensity = LimitValues (Value)
LightR = LimitValues (255 - Intensity - (AmbientColor & $000000FF))
LightG = LimitValues (255 - Intensity - ((AmbientColor & $0000FF00) >> 8))
LightB = LimitValues (255 - Intensity - ((AmbientColor & $00FF0000) >> 16))
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
Bits(i+2) = LimitValues (Bits(i+2) - LightR)
Bits(i+1) = LimitValues (Bits(i+1) - LightG)
Bits( i ) = LimitValues (Bits( i ) - LightB)
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure Emboss (DImage,SImage,Depth.f=5.0)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Define.l h ,w ,i ,j ,R , G , B
Define.c Gray
ImageToArray()
For h = 1 To Height-1
For w = 1 To Width-1
i = h * LineWidth + 3 * w
j = (h + Lim_Max (h, 1, Height)) * LineWidth + 3 * (w + Lim_Max (w, 1, Width))
R = Abs (((Bits(i+2) - Bits(j+2)) * Depth + 128))
G = Abs (((Bits(i+1) - Bits(j+1)) * Depth + 128))
B = Abs (((Bits( i ) - Bits( j )) * Depth + 128))
Gray = LimitValues ((R + G + B) / 3)
Bits(i+2) = Gray
Bits(i+1) = Gray
Bits( i ) = Gray
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure Solarize (DImage,SImage,invert=0)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l
ImageToArray()
For h = 1 To Height-1
For w = 1 To Width-1
i = h * LineWidth + 3 * w
If Not Invert
If (Bits(i+2) < 128)
Bits(i+2) = 255 - Bits(i+2)
EndIf
If (Bits(i+1) < 128)
Bits(i+1) = 255 - Bits(i+1)
EndIf
If (Bits( i ) < 128)
Bits( i ) = 255 - Bits( i )
EndIf
Else
If (Bits(i+2) > 127)
Bits(i+2) = 255 - Bits(i+2)
EndIf
If (Bits(i+1) > 127)
Bits(i+1) = 255 - Bits(i+1)
EndIf
If (Bits( i ) > 127)
Bits( i ) = 255 - Bits( i )
EndIf
EndIf
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure Mosaic (DImage,SImage,Size=2)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,hh.l ,w.l ,ww.l ,i.l , j.l
ImageToArray()
If size<1:size=1: ElseIf size > Height:size = Height:EndIf
For hh = 0 To Height-1
For ww = 0 To Width-1
i = (hh + (Lim_Max (hh, Size, Height) / 2)) * LineWidth + 3 * (ww + (Lim_Max (ww, Size, Width) / 2))
For H = 0 To Size-1
For W = 0 To Size-1
If (hh + H >= Height)
If (ww + W >= Width)
j = hh * LineWidth + 3 * ww
Else
j = hh * LineWidth + 3 * (ww + W)
EndIf
Else
If (ww + W >= Width)
j = (hh + H) * LineWidth + 3 * ww
Else
j = (hh + H) * LineWidth + 3 * (ww + W)
EndIf
EndIf
Bits(j+2) = Bits(i+2)
Bits(j+1) = Bits(i+1)
Bits( j ) = Bits( i )
Next
Next
ww +W - 1
Next
hh + H - 1
DoEvents ()
SetGadgetState(ProgressBar_0,100*hh/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure Melt (DImage,SImage)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,j.l
ImageToArray()
For h = 0 To Height-2 Step 2
For w = 0 To Width-1
i = h * LineWidth + 3 * w
j = (h + 1) * LineWidth + 3 * w
Bits(i+2) = Bits(j+2) - Bits(i+2) + (Bits(j+2)= Bits(i+2))
Bits(i+1) = Bits(j+1) - Bits(i+1) + (Bits(j+1)= Bits(i+1))
Bits( i ) = Bits( j ) - Bits( i ) + (Bits( j )= Bits( i ))
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*h/Height)
Next
ArrayToImage(bits())
EndProcedure
Procedure FishEye (DImage,SImage)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l
ImageToArray()
Dim newbits.c (BitCount)
Define.l i , j , nw, nh
Define.d Angle, Radius, rNew
Define.d Radmax = Sqr (Width * Width + Height * Height) / 2
For w = 1 To Width-1
For h = 1 To Height-1
nw = Width / 2 - w
nh = Height / 2 - h
Radius = Sqr (nw * nw + nh * nh)
If (Radius < Radmax)
Angle = ATan2 (nw, nh)
rNew = Radius * Radius / Radmax
nw = Int(Width / 2 + rNew * Cos (Angle))
nh = Int(Height / 2 - rNew * Sin (Angle))
nw = min(max(nw ,Width - 1),0)
nh = min(max( nh ,Height - 1),0)
i = h * LineWidth + 3 * (Width - w - 1)
j = nh * LineWidth + 3 * nw
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
EndIf
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*w/Width)
Next
ArrayToImage(Newbits())
EndProcedure
Procedure Swirl (DImage,SImage,Swirl =-255)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l
ImageToArray()
Dim newbits.c (BitCount)
Define.l i , j , nw, nh
Define.d Angle, Radius, aNew
Define.d Radmax = Sqr (Width * Width + Height * Height) / 1
For w = 1 To Width-1
For h = 1 To Height-1
nw = Width / 2 - w
nh = Height / 2 - h
Radius = Sqr (nw * nw + nh * nh)
If (Radius < Radmax)
Angle = ATan2 (nw, nh)
aNew = Angle + Radius / Swirl
nw = Int(Width / 2 + Radius * Cos (aNew))
nh = Int(Height / 2 - Radius * Sin (aNew))
nw = min(max(nw ,Width - 1),0)
nh = min(max( nh ,Height - 1),0)
i = h * LineWidth + 3 * w
j = nh * LineWidth + 3 * nw
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
EndIf
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*w/Width)
Next
ArrayToImage(Newbits())
EndProcedure
Procedure Twirl (DImage,SImage, Twirl = 15)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
ImageToArray()
Dim newbits.c (BitCount)
Define.l i , j ,w,h
Define.d half_w = Width / 2.0,half_h = Height / 2.0, nw, nh
Define.d twAngle = Twirl / (half_w * 10.0),Angle, NewAngle, AngleAcc, Radius, Radmax
For w = 0 To Width-1
For h = 0 To Height-1
i = h * LineWidth + 3 * w
nw = half_w - w
nh = half_h - h
Radius = Sqr (nw * nw + nh * nh)
Angle = ATan2 (nw, nh)
Radmax = MaximumRadius (Height, Width, Angle)
AngleAcc = twAngle * (-1.0 * (Radius - Radmax))
If (Radius < Radmax)
NewAngle = Angle + AngleAcc
nw = half_w - Cos (NewAngle) * Radius
nh = half_h - Sin (NewAngle) * Radius
If nw < 0.0: nw= 0.0 :ElseIf nw >= Width :nw= (Width - 1): EndIf
If nh < 0.0: nh= 0.0 :ElseIf nh >= Height : nh= (Height - 1) : EndIf
j = Int(nh) * LineWidth + 3 * Int(nw)
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
Else
NewBits(i+2) = Bits(i+2)
NewBits(i+1) = Bits(i+1)
NewBits( i ) = Bits( i )
EndIf
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*w/Width)
Next
ArrayToImage(Newbits())
EndProcedure
Procedure TwirlEx (DImage,SImage, TwirlMin.d = 2.0 ,TwirlMax.d = 2.0)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l
ImageToArray()
Dim newbits.c (BitCount)
Define.l i , j , nw, nh
Define.d halfw = Width / 2.0,halfh = Height / 2.0
Define.d Angle, Radius, Ratio, Radmax = sqr (Width * Width + Height * Height)
Define.d ShiftMin = TwirlMin * #PI / 8, ShiftMax = TwirlMax * #PI / 8
For w = 0 To Width-1
For h = 0 To Height-1
i = h * LineWidth + 3 * w
nw = w - halfW
nh = h - halfH
Radius = Sqr (nw * nw + nh * nh)
Angle = ATan2 (nw, nh)
Ratio = Radius / Radmax
If Ratio > 1.0
NewBits(i+2) = Bits(i+2)
NewBits(i+1) = Bits(i+1)
NewBits( i ) = Bits( i )
Else
Angle + Ratio * ShiftMin + (1 - Ratio) * ShiftMax
nw = int( halfw + Radius * Cos (Angle))
nh = int( halfh + Radius * Sin (Angle))
nw = min(max(nw ,Width - 1),0)
nh = min(max( nh ,Height - 1),0)
j = nh * LineWidth + 3 * nw
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
EndIf
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*w/Width)
Next
ArrayToImage(Newbits())
EndProcedure
Procedure Canvas (DImage,SImage,Canvas=240)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
ImageToArray()
Dim NewBits.c (BitCount)
Define.l i , j , h, w
Canvas = min(max( Canvas , Width-1) , 1)
For h = 0 To Height-1
For w = 0 To Width-1
i = h * LineWidth + 3 * w
j = h * LineWidth + 3 * (Width - w)
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
Next
Next
DoEvents ()
For w = Canvas To Width-1
For h = 0 To Height-1
i = h * LineWidth + 3 * w
Bits(i+2) = NewBits(i+2)
Bits(i+1) = NewBits(i+1)
Bits( i ) = NewBits( i )
Next
Next
ArrayToImage(bits())
EndProcedure
Procedure Waves (DImage,SImage ,Amplitude=5, Frequency.f=-10, FillSides.c =0, Direction.c =1)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l ,biSize.l ,tx.l ,ty.l ,SImage2.l ,PicSrcDC2.l
PicDestDC= StartDrawing(ImageOutput(DImage))
PicSrcDC = CreateCompatibleDC_(#Null)
SelectObject_(PicSrcDC, ImageID(SImage))
biSize = SizeOf (BITMAPINFOHEADER)
TemporaryBitmapInfo\bmiHeader\biSize = biSize
GetObject_(ImageID(SImage), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
GetDIBits_ (PicSrcDC, ImageID(DImage), 0, 0, #Null, TemporaryBitmapInfo, #DIB_RGB_COLORS)
Width = TemporaryBitmapInfo\bmiHeader\biWidth
Height = TemporaryBitmapInfo\bmiHeader\biHeight
Box(0,0,ImageWidth(DImage),ImageHeight(DImage),0)
If Direction = 1
For h = 0 To Height-1
tx = Int(Amplitude * Sin ((Frequency * 2) * h * (#PI / 180)))
BitBlt_ (PicDestDC, tx, h, Width, 1, PicSrcDC, 0, h, #SRCCOPY)
If FillSides
BitBlt_ (PicDestDC, 0, h, tx, 1, PicSrcDC, Width - tx, h, #SRCCOPY)
BitBlt_ (PicDestDC, tx + Width, h, Width - tx, 1, PicSrcDC, 0, h, #SRCCOPY)
EndIf
Next
ElseIf Direction = 0
For w = 0 To Width-1
ty = Int(Amplitude * Sin ((Frequency * 2) * w * (#PI / 180)))
BitBlt_ (PicDestDC, w, ty, 1, Height, PicSrcDC, w, 0, #SRCCOPY)
If FillSides
BitBlt_ (PicDestDC, w, 0, 1, ty, PicSrcDC, w, Height - ty, #SRCCOPY)
BitBlt_ (PicDestDC, w, ty + Height, 1, Height - ty, PicSrcDC, w, 0, #SRCCOPY)
EndIf
Next
ElseIf Direction = 2; und nun alles zusammen
SImage2=CreateImage(#PB_Any,Width,Height,24)
PicSrcDC2 = CreateCompatibleDC_(#Null)
SelectObject_(PicSrcDC2, ImageID(SImage2))
For h = 0 To Height-1
tx = Int(Amplitude * Sin ((Frequency * 2) * h * (#PI / 180)))
BitBlt_ (PicDestDC, tx, h, Width, 1, PicSrcDC, 0, h, #SRCCOPY)
If FillSides
BitBlt_ (PicDestDC, 0, h, tx, 1, PicSrcDC, Width - tx, h, #SRCCOPY)
BitBlt_ (PicDestDC, tx + Width, h, Width - tx, 1, PicSrcDC, 0, h, #SRCCOPY)
EndIf
Next
BitBlt_ (PicSrcDC2, 0, 0, Width,Height, PicDestDC, 0, 0, #SRCCOPY)
Box(0,0,ImageWidth(DImage),ImageHeight(DImage),0)
For w = 0 To Width-1
ty = Int(Amplitude * Sin ((Frequency * 2) * w * (#PI / 180)))
BitBlt_ (PicDestDC, w, ty, 1, Height, PicSrcDC2, w, 0, #SRCCOPY)
If FillSides
BitBlt_ (PicDestDC, w, 0, 1, ty, PicSrcDC2, w, Height - ty, #SRCCOPY)
BitBlt_ (PicDestDC, w, ty + Height, 1, Height - ty,PicSrcDC2, w, 0, #SRCCOPY)
EndIf
Next
DeleteDC_(PicSrcDC2)
FreeImage(SImage2)
EndIf
StopDrawing()
DeleteDC_(PicSrcDC)
EndProcedure
Procedure BlockWaves (DImage,SImage , Amplitude.f=5, Frequency.f=-10, Mode=1)
Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
Protected h.l ,w.l ,i.l
ImageToArray()
Dim NewBits.c (BitCount)
Define.l i , j ,nw, nh
Define.d Radius
For w = 1 To Width-1
For h = 1 To Height-1
i = h * LineWidth + 3 * w
nw = Width / 2 - w
nh = Height / 2 - h
Radius = Sqr (nw * nw + nh * nh)
If (Mode % 2)=0
nw = Int(w + Amplitude * Sin (Frequency * nw * (#PI / 180)))
nh = Int(h + Amplitude * Cos (Frequency * nh * (#PI / 180)))
Else
nw = Int(w + Amplitude * Sin (Frequency * w * (#PI / 180)))
nh = Int(h + Amplitude * Cos (Frequency * h * (#PI / 180)))
EndIf
nw = min(max(nw ,Width - 1),0)
nh = min(max( nh ,Height - 1),0)
j = nh * LineWidth + 3 * nw
NewBits(i+2) = Bits(j+2)
NewBits(i+1) = Bits(j+1)
NewBits( i ) = Bits( j )
Next
DoEvents ()
SetGadgetState(ProgressBar_0,100*w/Width)
Next
ArrayToImage(Newbits())
EndProcedure