GraphicalDLL VC++ --> PB

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

GraphicalDLL VC++ --> PB

Beitrag von SoS »

Ich habe vor ein paar Jahren die GraphicalDLL im Netz gefunden.
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. :mrgreen:

Code: Alles auswählen

FrostGlass() bzw RandomColor()
Das Ergebnis sieht nicht so aus, wie es aussehen sollte.
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
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von SoS »

teil 2

Code: Alles auswählen

Procedure DetectBorders (DImage,SImage , Border=10, ColorBorder= #Yellow, BGColor=#Black)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	Protected h.l ,w.l ,i.l ,k.l
 	Define.l i , j , color_1, color_2
	Define.l  GR, GG, GB, Gray, BackR, BackG, BackB, BorderR, BorderG, BorderB
	ImageToArray()
	
	
	BackR = (BGColor & $000000FF)
	BackG = (BGColor & $0000FF00) >> 8
	BackB = (BGColor & $00FF0000) >> 16
	
	BorderR = (ColorBorder & $000000FF)
	BorderG = (ColorBorder & $0000FF00) >> 8
	BorderB = (ColorBorder & $00FF0000) >> 16	
	Border = LimitValues (Border)
	For w = 1 To Width-1
		For  h = 1 To Height-1
			For k=0 To 2
				i = h * LineWidth + 3 * w
				j = h * LineWidth + 3 * (w + Lim_Max (w, 1, Width))
				color_1 = Int((Bits(i+k) - Bits(j+k)) * (Bits(i+k) - Bits(j+k)))
				j = (h + Lim_Max (h, 1, Height)) * LineWidth + 3 * w
				color_2 = Int((Bits(i+k) - Bits(j+k)) * (Bits(i+k) - Bits(j+k)))
				Select k
					Case 0
						GB = LimitValues (Int(Sqr ((color_1 + color_2))) << 1)
					Case 1
						GG = LimitValues (Int(Sqr ((color_1 + color_2))) << 1)
					Case 2
						GR = LimitValues (Int(Sqr ((color_1 + color_2))) << 1)
				EndSelect
			Next
			Gray = (GR + GG + GB) / 3
			If (Gray > Border)
				
				Bits(i+2) = BorderR
				Bits(i+1) = BorderG
				Bits( i ) = BorderB
				
			Else
				
				Bits(i+2) = BackR
				Bits(i+1) = BackG
				Bits( i ) = BackB
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*w/Width)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Blur (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 ,k.l
	ImageToArray()
	
	For w = 1 To Width-2
		For  h = 1 To Height-2
			i = h * LineWidth + 3 * w
			j = (h + 1) * LineWidth + 3 * w
			k = (h - 1) * LineWidth + 3 * w
			
			Bits(i+2) = (Bits(i-1) + Bits(j-1) + Bits(k-1) +Bits(i+2) + Bits(j+2) + Bits(k+2) +Bits(i+5) + Bits(j+5) + Bits(k+5)) / 9
			Bits(i+1) = (Bits(i-2) + Bits(j-2) + Bits(k-2) +Bits(i+1) + Bits(j+1) + Bits(k+1) +Bits(i+4) + Bits(j+4) + Bits(k+4)) / 9
			Bits( i ) = (Bits(i-3) + Bits(j-3) + Bits(k-3) +Bits( i ) + Bits( j ) + Bits( k ) +Bits(i+3) + Bits(j+3) + Bits(k+3)) / 9
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*w/Width)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Saturation (DImage,SImage, Saturation= -127)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	Protected h.l ,w.l ,i.l ,k.l, Gray.l
	ImageToArray()
	
	For w = 1 To Width-1
		For  h = 1 To Height-1
			i = h * LineWidth + 3 * w
			Gray = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
			Bits(i+2) = LimitValues (ShadeColors (Gray, Bits(i+2), 255 + Saturation))
			Bits(i+1) = LimitValues (ShadeColors (Gray, Bits(i+1), 255 + Saturation))
			Bits( i ) = LimitValues (ShadeColors (Gray, Bits( i ), 255 + Saturation))
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*w/Width)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure FindEdges (DImage,SImage, Intensity=1, BW=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 Intensity < 0: Intensity =0:ElseIf Intensity > 5 : Intensity =5:EndIf
	If BW <1 : BW =1: ElseIf BW >5:BW =5: 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) = 255 -LimitValues (Int(Sqr ((color_1 + color_2))) << Intensity)
			Next
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Make3DEffect (DImage,SImage, Normal=30)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	Protected h.l ,w.l ,y.l,i.l
	ImageToArray()
	
	Dim newbits.c (BitCount)
	If normal <1:normal=1:ElseIf normal>50:normal=50:EndIf
	
	Define.l i , j, tStep
	
	For w = 0 To Width-1
		For  h =0 To Height-1
			i = (Height - h - 1) * LineWidth + 3 * w
			tStep = Int(((Bits(i+2) + Bits(i+1) + Bits(i)) / 3) / Normal)
			If (h - tStep) > 0
				For  y = 0 To tStep-1
					j = (Height - (h - Lim_Max (h, y, Height)) - 1) * LineWidth + 3 * w
					NewBits(j+2) = Bits(i+2)
					NewBits(j+1) = Bits(i+1)
					NewBits( j ) = Bits( i )
				Next
			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 FourCorners (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim newbits.c (BitCount)
	
	Define.l i , j , nw, nh,w ,h
	Define.d Angle, Radius, rNew
	Define.d Radmax = Sqr (Width * Width + Height * Height) / 2
	
	For w = 0 To Width-1
		For  h =0 To Height-1
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			If (Radius < Radmax)
				Angle = ATan2 (nw, nh) * 2
				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 * 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 Caricature (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim newbits.c (BitCount)
	
	Define.l i , j , nw, nh, w, h
	Define.d Angle, Radius, rNew
	Define.d Radmax = Sqr (Width * Width + Height * Height) / 2
	
	For w = 0 To Width-1
		For  h =0 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 = Sqr (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 Tile (DImage,SImage, WSize =10,HSize =10,Random = 10)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	Define.l biSize ,w ,h ,tx ,ty
	PicDestDC= StartDrawing(ImageOutput(DImage))
		
		PicSrcDC = CreateCompatibleDC_(#Null)
		SelectObject_(PicSrcDC, ImageID(SImage))
		biSize = SizeOf (BITMAPINFOHEADER)
		TemporaryBitmapInfo\bmiHeader\biSize = biSize
		GetObject_(ImageID(SImage), SizeOf(BITMAP), TemporaryBitmap)
		GetDIBits_ (PicSrcDC, ImageID(DImage), 0, 0, #Null, TemporaryBitmapInfo, #DIB_RGB_COLORS)
		Width   = TemporaryBitmapInfo\bmiHeader\biWidth
		Height   = TemporaryBitmapInfo\bmiHeader\biHeight
		
		If (WSize < 1)
			WSize = 1
		EndIf
		If (HSize < 1)
			HSize = 1
		EndIf
		If (Random < 1)
			Random = 1
		EndIf
		RandomSeed(timeGetTime_())		
		For h = 0 To Height-1
			For w = 0 To Width-1
				tx = Int(Random(Random)) - (Random / 2)
				ty = Int(Random(Random)) - (Random / 2)
				BitBlt_ (PicDestDC, w + tx, h + ty, WSize, HSize, PicSrcDC, w, h, #SRCCOPY)
				w+WSize-1
			Next
			h+HSize-1
			DoEvents ()
			SetGadgetState(ProgressBar_0,100*h/Height)
		Next
	StopDrawing()
	DeleteDC_(PicSrcDC)
EndProcedure

Procedure Roll (DImage,SImage,Value.d=2.0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim newbits.c (BitCount)
	
	Define.l i , j , nw, nh,w ,h
	Define.d Angle, Radius
	Define.d Radmax = Sqr (Width * Width + Height * Height) / 2
	
	For w = 0 To Width-1
		For  h =0 To Height-1
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			If (Radius < Radmax)
				Angle = ATan2 (nw, nh)/ Value
				nw = Int(Width / 2 + Radius * Cos (Angle))
				nh = Int(Height / 2 - Radius * 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 CircularWaves (DImage,SImage, Amplitude = 10,Frequency = 10)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim newbits.c (BitCount)
	
	If (Amplitude < 0)
		Amplitude = 0
	EndIf
	If (Frequency < 0)
		Frequency = 0
	EndIf
	Define.l i , j , nw, nh,w ,h
	Define.d  Radius
	For w = 0 To Width-1
		For  h =0 To Height-1
			i = h * LineWidth + 3 * w
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			nw = Int(w + Amplitude * Sin (Frequency * Radius * (#PI / 180)))
			nh = Int(h + Amplitude * Cos (Frequency * Radius * (#PI / 180)))
			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

Procedure FishEyeEX (DImage,SImage,  Value.d=1.0623)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount.l ,result.l,Width.l,Height.l,LineWidth =0
	ImageToArray()
	Dim newbits.c (BitCount)
	
	If Value < 0.00001: Value = 0.00001: EndIf
	Define.l i , j , nw, nh, RadMax = min (Height, Width) / 2, halfH = Height / 2, halfW = Width / 2,h ,w
	Define.d r, a
	Define.d coeff = RadMax / Log (Abs (Value) * RadMax + 1)		
	
	For  h = -1* halfH To Height-1- halfH
		For w = -1* halfW To Width-1 - halfW
			r = Sqr (w * w + h * h)
			a = ATan2 (w, h)
			
			i = (h + halfH) * LineWidth + 3 * (w + halfW)
			If r <= RadMax
				If Value > 0
					r = (Exp (r / coeff) - 1) / Value
				Else
					r = coeff * Log(1 + (-1 * Value) * r)
				EndIf
				nw = halfW + Int(r * Cos (a))
				nh = halfH + Int(r * Sin (a))
				nw = min(max(nw ,Width ),0)
				nh = min(max( nh ,Height ),0)
				j = nh * LineWidth + 3 * 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*h/(Height-1- halfH))
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure Cilindrical (DImage,SImage, Value.d= 15)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim NewBits.c (BitCount)
	Value * 0.001
	Define.l i, j, RadMax = min (Height, Width) / 2,nw, nh, h, w
	Define.l halfH = Height / 2, halfW = Width / 2
	Define.d r, coeff = RadMax / Log (Abs (Value) * RadMax + 1)
	
	For  h = -1 * halfH To Height- halfH-1
		For w = -1 * halfW To Width- halfW-1
			r = Abs (w)
			i = (h + halfH) * LineWidth + 3 * (w + halfW)
			If (r <= RadMax)
				If (Value > 0)
					r = (Exp (r / coeff) - 1) / Value
				Else
					r = coeff * Log (1 + (-1 * Value) * r)
				EndIf
				If (w >= 0)
					nw = halfW + r
				Else
					nw = halfW - r
				EndIf
				nh = halfH + h
				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 )
			Else
				NewBits(i+2) = Bits(i+2)
				NewBits(i+1) = Bits(i+1)
				NewBits( i ) = Bits( i )
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/(Height- halfH-1))
	Next		
	
	ArrayToImage(Newbits())
EndProcedure

Procedure CircularWavesEX (DImage,SImage ,Amplitude = 100,Frequency = 3)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim newbits.c (BitCount)
	
	If (Amplitude < 0)
		Amplitude = 0
	EndIf
	If (Frequency < 0)
		Frequency = 0
	EndIf
	
	Define.l i , j , nw, nh, NewAmp, h, w
	Define.d  Radius, RadMax
	For w = 0 To Width-1
		For  h =0 To Height-1
			i = h * LineWidth + 3 * w
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			RadMax = Sqr (Width * Width + Height * Height)
			NewAmp = Int((Amplitude * Radius) / RadMax)
			nw = Int(w + NewAmp * Sin (Frequency * Radius * (#PI / 180)))
			nh = Int(h + NewAmp * Cos (Frequency * Radius * (#PI / 180)))
			nw=Min(Max(int(nw) ,Width-1),0)
			nh=Min(Max(int(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

Procedure PolarCoordinates (DImage,SImage,value.d=1.0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount.l ,result.l,Width.l,Height.l,LineWidth.l =0
	ImageToArray()
	
	Dim newbits.c (BitCount)
	Dim flags.c (BitCount)
	
	Define.l i , j , m , h, w
	
	Define.d  k, l, nw, nh, Angle, Radius, R, m_w = Width / 2, m_h = Height / 2
	For w = 0 To Width-1
		For  h =0 To Height-1
			nw = m_w - w
			nh = h - m_h
			Radius = Sqr (nw * nw + nh * nh)
			Angle = ATan2 (nh, nw)*value
			R = MaximumRadius (Height, Width, Angle)
			nh = (Radius * Height / R)
			nw = (Angle * Width / 6.2832)
			
			nh = Height - nh - 1
			nw +m_w
			
			nw=Min(Max(int(nw) ,Width-1),0)
			nh=Min(Max(int(nh) ,Height-1),0)
			
			k = w * m_h / m_w
			l = h * m_w / m_h
			
			l=Min(Max(int(l) ,Width-1),0)
			k=Min(Max(int(k) ,Height-1),0)
			
			i = Int(k) * LineWidth + 3 * Int(l)
			j = Int(nh) * LineWidth + 3 * Int(nw)
			
			NewBits(i+2) = Bits(j+2)
			NewBits(i+1) = Bits(j+1)
			NewBits( i ) = Bits( j )
			flags( i ) = 1
		Next
	Next
	DoEvents ()
	For w = 1 To Width-2
		For  h =0 To Height-1
			i = h * LineWidth + 3 * w
			If Not flags(i)
				j = h * LineWidth + 3 * (w + 1)
				m = h * LineWidth + 3 * (w - 1)
				NewBits(i+2) = (NewBits(j+2) + NewBits(m+2)) >> 1
				NewBits(i+1) = (NewBits(j+1) + NewBits(m+1)) >> 1
				NewBits( i ) = (NewBits( j ) + NewBits( m )) >> 1
			EndIf
		Next
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure Metallic (DImage,SImage,level=1,shift=1,mode=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	If (Level % 2)
		Level+1
	EndIf
	
	Define.l i ,h ,w
	Define.l Gray
	For h = 0 To Height-1
		For w = 0 To Width-1
			
			i = h * LineWidth + 3 * w
			Gray = Int(Bits(i+2) + Bits(i+1) + Bits(i) / 3)
			Bits(i+2)= Gray
			Bits(i+1) = Gray
			Bits(i) = Gray
		Next
	Next
	DoEvents ()
	ApplyMetallicShiftLayer (Bits(), Width, Height, Level, Shift)
	
	Select Mode
			
		Case #GRAD_GOLD:
			ApplyGoldLayer (Bits(), Width, Height)
			
		Case #GRAD_ICE:
			ApplyIceLayer (Bits(), Width, Height)
	EndSelect
	
	ArrayToImage(bits())
EndProcedure

Procedure Colorize(DImage,SImage,Brightness,Color)
	Define.l h, w, i
	Protected Counter
	Protected OldBrightness,NewBrightness,DeltaLight
	Protected Red,Green,Blue
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Red=FastRed(Color)
	Green=FastGreen(Color)
	Blue=FastBlue(Color)
	NewBrightness=(Red+Green+Blue)/3
	For h = 0 To Height-1
		For w = 0 To Width-1
			
			i = h * LineWidth + 3 * w
			OldBrightness=(bits(i+2) + bits(i+1) + bits(i))/3
			DeltaLight=OldBrightness-NewBrightness+Brightness
			bits(i+2)=  LimitValues((Red+OldBrightness)>>1+DeltaLight)
			bits(i+1)=  LimitValues((Green+OldBrightness)>>1+DeltaLight)
			bits(i)=  LimitValues((Blue+OldBrightness)>>1+DeltaLight)
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Sepia (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i ,h ,w ,GrayPixel
	
	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
			If GrayPixel > 202: GrayPixel= 255 : Bits(i+2) = GrayPixel : Else : GrayPixel + 53 : Bits(i+2) = GrayPixel : EndIf
			If GrayPixel > 235: GrayPixel= 255 : Bits(i+1) = GrayPixel : Else : GrayPixel + 20 : Bits(i+1) = GrayPixel : EndIf
			If GrayPixel <		33: GrayPixel=		0 : Bits(i)		 = GrayPixel : Else : GrayPixel-	33 : Bits(i)	 = GrayPixel : EndIf
			If Bits(i+1) < 30	:  Bits(i+1)= 30 : EndIf
			If Bits(i) < 30:  Bits(i) = 20 :  EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure ReduceTo2Colors (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , h, w, GrayPixel
	
	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
			If  GrayPixel > 127 : GrayPixel = 255 : Else : GrayPixel = 0 : EndIf
			Bits(i+2) = GrayPixel
			Bits(i+1) = GrayPixel
			Bits(i)		 = GrayPixel
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure ReduceTo8Colors (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l i
	Dim c_Table.c(#COLOR_SIZE)
	For i = 0 To 255
		If  i >127
			c_Table(i)=255
		Else
			c_Table(i)=0
		EndIf
	Next
	
	AssignTables (c_Table(), c_Table(),c_Table(), bits(), Width, Height)
	
	ArrayToImage(bits())
EndProcedure

Procedure ReduceColors (DImage,SImage,Levels = 0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l i
	If Levels < 1 :Levels = 1 : EndIf
	Dim rc.c(#COLOR_SIZE)
	
	For i = 0 To 255
		rc(i)=LimitValues (i - (i % Levels))
	Next
	
	AssignTables (rc(), rc(),rc(), bits(), Width, Height)
	
	ArrayToImage(bits())
EndProcedure

Procedure Stamp (DImage,SImage,Levels = 0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l h, w, i ,GrayPixel
	If Levels < 0 :Levels = 0:EndIf
	For h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			GrayPixel = Int(Bits(i+2) + Bits(i+1) + Bits(i) / 3)
			If GrayPixel > Levels : GrayPixel = 255 : Else : GrayPixel = 0 : EndIf
			Bits(i+2)=GrayPixel
			Bits(i+1) =GrayPixel
			Bits(i) = GrayPixel
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Brightness (DImage,SImage,Levels = 0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l i
	Dim rc.c(#COLOR_SIZE)
	
	For i = 0 To 255
		rc(i)=LimitValues (i +  Levels)
	Next
	
	AssignTables (rc(), rc(),rc(), bits(), Width, Height)
	
	ArrayToImage(bits())
EndProcedure

Procedure AntiAlias (DImage.l,SImage.l,Sensibility.l)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim Temp.c(3,9)
	Define .l i , j, k, GrayCmp, Gray, yadd,h ,w  ,y
	
	For h = 1 To Height - 2
		For w = 1 To Width - 2
			i = h * LineWidth + 3 * w
			j = (h + 1) * LineWidth + 3 * w
			k = (h - 1) * LineWidth + 3 * w
			Gray = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
			For y = 0 To 2
				yadd = y * 3
				GrayCmp = (Bits(j+yadd-1) + Bits(j+yadd-2) + Bits(j+yadd-3)) / 3
				If Not ((GrayCmp > Gray + Sensibility) Or  (GrayCmp < Gray - Sensibility))
					Temp(0,y) = Bits( i )
					Temp(1,y) = Bits(i+1)
					Temp(2,y) = Bits(i+2)
				Else
					Temp(0,y) = Bits(j+yadd-3)
					Temp(1,y) = Bits(j+yadd-2)
					Temp(2,y) = Bits(j+yadd-1)
				EndIf
			Next
			For y = 0 To 2
				yadd = y * 3
				GrayCmp = (Bits(i+yadd-1) + Bits(i+yadd-2) + Bits(i+yadd-3)) / 3
				If Not ((GrayCmp > Gray + Sensibility) Or  (GrayCmp < Gray - Sensibility))
					Temp(0,y+3) = Bits( i )
					Temp(1,y+3) = Bits(i+1)
					Temp(2,y+3) = Bits(i+2)
				Else
					Temp(0,y+3) = Bits(i+yadd-3)
					Temp(1,y+3) = Bits(i+yadd-2)
					Temp(2,y+3) = Bits(i+yadd-1)
				EndIf
			Next
			For y = 0 To 2
				yadd = y * 3
				GrayCmp = (Bits(k+yadd-1) + Bits(k+yadd-2) + Bits(k+yadd-3)) / 3
				If Not ((GrayCmp > Gray + Sensibility) Or (GrayCmp < Gray - Sensibility))
					Temp(0,y+6) = Bits( i )
					Temp(1,y+6) = Bits(i+1)
					Temp(2,y+6) = Bits(i+2)
				Else
					Temp(0,y+6) = Bits(k+yadd-3)
					Temp(1,y+6) = Bits(k+yadd-2)
					Temp(2,y+6) = Bits(k+yadd-1)
				EndIf
			Next
			Bits(i+2) = (Temp(2,0) + Temp(2,1) + Temp(2,2) +Temp(2,3) + Temp(2,4) + Temp(2,5) +Temp(2,6) + Temp(2,7) + Temp(2,8)) / 9
			Bits(i+1) = (Temp(1,0) + Temp(1,1) + Temp(1,2) +Temp(1,3) + Temp(1,4) + Temp(1,5) +Temp(1,6) + Temp(1,7) + Temp(1,8)) / 9
			Bits( i ) = (Temp(0,0) + Temp(0,1) + Temp(0,2) +Temp(0,3) + Temp(0,4) + Temp(0,5) +Temp(0,6) + Temp(0,7) + Temp(0,8)) / 9
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Gamma (DImage,SImage,Gamma.f)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l i
	Dim gTable.c(#COLOR_SIZE)
	
	If (Gamma < 0.0)
		Gamma = 0.0
	EndIf
	If (Gamma > 10.0)
		Gamma = 10.0
	EndIf
	
	For i = 0 To 255
		gTable(i)= (255.0 * Pow((i / 255.0), (1.0 / Gamma)))
	Next
	AssignTables (gTable(), gTable(), gTable(), Bits(), Width, Height)
	
	ArrayToImage(bits())
EndProcedure

Procedure Invert (DImage,SImage,Intensity.l=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , h, w
	
	If (Intensity > 255)
		Intensity = 255
	EndIf
	If (Intensity < 0)
		Intensity = 0
	EndIf
	
	For h = 0 To Height - 1
		For w = 0 To  Width - 1
			i = h * LineWidth + 3 * w
			Bits(i+2) = LimitValues (Abs(Intensity - Bits(i+2)))
			Bits(i+1) = LimitValues (Abs(Intensity - Bits(i+1)))
			Bits( i ) = LimitValues (Abs(Intensity - Bits( i )))
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Tone (DImage,SImage,Tone.l=0,Color.l=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , h ,w
	Define.l R = (Color & $000000FF),G = (Color & $0000FF00) >>  8,B = (Color &$00FF0000) >> 16
	
	If (Tone > 255)
		Tone = 255
	EndIf
	If (Tone < 0)
		Tone = 0
	EndIf
	Tone = LimitValues (255 - Tone)
	
	For h = 0 To Height - 1
		For w = 0 To  Width - 1
			i = h * LineWidth + 3 * w
			
			Bits(i+2) = ShadeColors (R, Bits(i+2), Tone)
			Bits(i+1) = ShadeColors (G, Bits(i+1), Tone)
			Bits( i ) = ShadeColors (B, Bits( i ), Tone)
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Contrast (DImage,SImage,red.f,green.f,blue.f)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i
	If Red   < 0.0 :  Red = 0.1 : EndIf
	If Green < 0.0: Green = 0.1 : EndIf
	If Blue  < 0 .0 : Blue = 0.1 : EndIf
	
	Dim TableR.c(#COLOR_SIZE)
	Dim TableG.c(#COLOR_SIZE)
	Dim TableB.c(#COLOR_SIZE)
	
	For i = 0 To 255
		TableR(i) = LimitValues (Int(((i - 127) *   Red) + 127))
		TableG(i) = LimitValues (Int(((i - 127) * Green) + 127))
		TableB(i) = LimitValues (Int(((i - 127) *  Blue) + 127))
	Next
	AssignTables (TableR(), TableG(), TableB(), Bits(), Width, Height)
	
	ArrayToImage(bits())
EndProcedure

Procedure GrayScale (DImage,SImage,Scale.l)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Define.l i , j , h ,w
	Define.l GrayPixel
	
	If (Scale < -255)
		Scale = -255
	ElseIf (Scale > 255)
		Scale = 255
	EndIf
	For h = 0 To Height - 1
		For w = 0 To  Width - 1
			i = h * LineWidth + 3 * w
			GrayPixel =Int(Bits(i+2) + Bits(i+1) + Bits(i) / 3)
			If (Scale >= 0)
				GrayPixel = LimitValues (GrayPixel + Scale)
			Else
				GrayPixel = ShadeColors (GrayPixel, $0, Abs (Scale))
			EndIf
			Bits(i+2) = LimitValues (GrayPixel )
			Bits(i+1) =LimitValues (GrayPixel )
			Bits( i ) =LimitValues (GrayPixel )
			
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	ArrayToImage(bits())
EndProcedure

Procedure RandomicalPointse (DImage,SImage,RandValue.l=0,BackColor.l=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , h ,w, r
	Define.l BackR = (BackColor & $000000FF),BackG = (BackColor & $0000FF00) >>  8,BackB = (BackColor &$00FF0000) >> 16
	
	If (RandValue < 1)
		RandValue = 1
	ElseIf (RandValue > 255)
		RandValue = 255
	EndIf
	
	RandomSeed(timeGetTime_())
	For h = 0 To Height - 1
		For w = 0 To  Width - 1
			i = h * LineWidth + 3 * w
			r = 1+Random ( RandValue)
			If ((r = 2) Or (r = 1))
				Bits(i+2) = BackR
				Bits(i+1) = BackG
				Bits( i ) = BackB
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure ColorRandomize (DImage,SImage,RandValue.l=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , h, w, r
	
	If (RandValue < -255)
		RandValue = -255
	ElseIf (RandValue > 255)
		RandValue = 255
	EndIf
	
	RandomSeed(timeGetTime_())
	For h = 0 To Height - 1
		For w = 0 To  Width - 1
			i = h * LineWidth + 3 * w
			r = 1+Random (3)
			If (r = 1)
				Bits(i+2) = LimitValues (Bits(i+2) + RandValue)
			ElseIf (r = 2)
				Bits(i+1) = LimitValues (Bits(i+1) + RandValue)
			Else
				Bits( i ) = LimitValues (Bits( i ) + RandValue)
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Diffuse (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , rx, ry,h ,w
	
	RandomSeed(timeGetTime_())
	For h =2 To Height -4
		For w =2 To  Width -4
			rx = (Random(4)) - 2
			ry = (Random(4)) - 2
			i = h * LineWidth + 3 * w
			j = (h + ry) * LineWidth + 3 * (w + rx)
			Bits(i+2) = Bits(j+2)
			Bits(i+1) = Bits(j+1)
			Bits( i ) = Bits( j )
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure AsciiMorph (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount.l ,result.l,Width.l,Height.l
	Protected  w_new.l,h_new,SImage2.l
	Define.l i , pos  , GrayColor,color_table, biSize, LineWidth, h, w
	
	SImage2=CopyImage(SImage,#PB_Any)
	w_new =ImageWidth(SImage2)/8
	h_new =ImageHeight(SImage2)/8
	AspectSize(ImageWidth(SImage2),ImageHeight(SImage2),@w_new,@h_new)
	ResizeImage(SImage2,w_new,h_new)
	
	PicSrcDC = CreateCompatibleDC_(#Null)
	SelectObject_(PicSrcDC, ImageID(SImage2))
	biSize = SizeOf (BITMAPINFOHEADER)
	TemporaryBitmapInfo\bmiHeader\biSize = biSize
	
	GetObject_(ImageID(SImage2), SizeOf(BITMAP), TemporaryBitmap)
	GetDIBits_ (PicSrcDC, ImageID(SImage2), 0, 0, #Null, TemporaryBitmapInfo, #DIB_RGB_COLORS)
	TemporaryBitmapInfo\bmiHeader\biCompression   = 0
	TemporaryBitmapInfo\bmiHeader\biBitCount      = 24
	Width   = TemporaryBitmapInfo\bmiHeader\biWidth
	Height   = TemporaryBitmapInfo\bmiHeader\biHeight
	LineWidth = Width * 3
	If (LineWidth % 4)
		LineWidth + (4 - LineWidth % 4)
	EndIf
	BitCount = LineWidth * Height
	
	Dim bits.c (BitCount)
	GetDIBits_ (PicSrcDC, ImageID(SImage2), 0, Height, bits(), @TemporaryBitmapInfo, #DIB_RGB_COLORS)
	DeleteDC_(PicSrcDC)
	
	PicDestDC= StartDrawing(ImageOutput(DImage))
		Box(0,0,ImageWidth(DImage),ImageHeight(DImage),0)
		DrawingFont(FontID(ASCII_font))
		DrawingMode(#PB_2DDrawing_Transparent)	
		For h = 0 To Height - 1
			For w = 0 To  Width - 1
				i = h * LineWidth + 3 * w
				GrayColor = (Bits(i) + Bits(i+1) + Bits(i+2)) / 3
				
				color_table=Min(Max(Int(GrayColor / 14.22),17),0)
				
				DrawText(w*8+1,ImageHeight(DImage)-(h*8+8),Chr( ASCII_table(17-color_table)),#White,#Black)
			Next
			DoEvents ()
			SetGadgetState(ProgressBar_0,100*h/Height)
		Next
	StopDrawing()
	
	If IsImage(SImage2)
		FreeImage(SImage2)
	EndIf
EndProcedure

Procedure SmartBlur (DImage,SImage,Sensibility.l=1)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim temp.c (3,9)
	
	Define.l i , j , k , GrayCmp, Gray, addx, h, w, y
	
	For  h = 1 To Height-2
		For w = 1 To Width-2
			i = h * LineWidth + 3 * w
			j = (h + 1) * LineWidth + 3 * w
			k = (h - 1) * LineWidth + 3 * w
			Gray = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
			For y = 0 To 2
				addx = y * 3
				GrayCmp = (Bits(j+addx-1) + Bits(j+addx-2) + Bits(j+addx-3)) / 3
				If ((GrayCmp > Gray + Sensibility) Or (GrayCmp < Gray - Sensibility))
					Temp(0,y) = Bits( i )
					Temp(1,y) = Bits(i+1)
					Temp(2,y) = Bits(i+2)
				Else
					Temp(0,y) = Bits(j+addx-3)
					Temp(1,y) = Bits(j+addx-2)
					Temp(2,y) = Bits(j+addx-1)
				EndIf
			Next
			For y = 0 To 2
				addx = y * 3
				GrayCmp = (Bits(i+addx-1) + Bits(i+addx-2) + Bits(i+addx-3)) / 3
				If ((GrayCmp > Gray + Sensibility) Or (GrayCmp < Gray - Sensibility))
					Temp(0,y+3) = Bits( i )
					Temp(1,y+3) = Bits(i+1)
					Temp(2,y+3) = Bits(i+2)
				Else
					Temp(0,y+3) = Bits(i+ADDx-3)
					Temp(1,y+3) = Bits(i+ADDx-2)
					Temp(2,y+3) = Bits(i+ADDx-1)
				EndIf
			Next
			For y = 0 To 2
				addx = y * 3
				GrayCmp = (Bits(k+addx-1) + Bits(k+addx-2) + Bits(k+addx-3)) / 3
				If ((GrayCmp > Gray + Sensibility) Or (GrayCmp < Gray - Sensibility))
					Temp(0,y+6) = Bits( i )
					Temp(1,y+6) = Bits(i+1)
					Temp(2,y+6) = Bits(i+2)
				Else
					Temp(0,y+6) = Bits(k+addx-3)
					Temp(1,y+6) = Bits(k+addx-2)
					Temp(2,y+6) = Bits(k+addx-1)
				EndIf
			Next
			Bits(i+2) = (Temp(2,0) + Temp(2,1) + Temp(2,2) +Temp(2,3) + Temp(2,4) + Temp(2,5) +Temp(2,6) + Temp(2,7) + Temp(2,8)) / 9
			Bits(i+1) = (Temp(1,0) + Temp(1,1) + Temp(1,2) +Temp(1,3) + Temp(1,4) + Temp(1,5) +Temp(1,6) + Temp(1,7) + Temp(1,8)) / 9
			Bits( i ) = (Temp(0,0) + Temp(0,1) + Temp(0,2) +Temp(0,3) + Temp(0,4) + Temp(0,5) +Temp(0,6) + Temp(0,7) + Temp(0,8)) / 9
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure AdvancedBlur (DImage,SImage,Blur.l=1,Sense.l=1,Smart.l=1)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	If (Blur < 1)
		ProcedureReturn #True
	EndIf
	If (Blur > 10)
		Blur = 10
	EndIf
	Define.l Orig = Blur
	Blur = Blur * 2 + 1
	Define.l Size = Blur * Blur
	Define.l i , j , k , GrayCmp, Gray, SomaR , SomaG , SomaB , h, w, a, b
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			Gray = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
			For a = -Orig To Orig
				For b = -Orig To Orig
					j = (h + Lim_Max (h, a, Height)) * LineWidth + 3 * (w + Lim_Max (w, b, Width))
					If ((h + a < 0) Or (w + b < 0))
						j = i
					EndIf		
					If (Smart)
						GrayCmp = (Bits(j+2) + Bits(j+1) + Bits(j)) / 3
						If ((GrayCmp > Gray + Sense) Or (GrayCmp < Gray - Sense))
							j = i
						EndIf
					EndIf
					SomaR + Bits(j+2)
					SomaG + Bits(j+1)
					SomaB + Bits( j )
				Next
			Next
			Bits(i+2) = SomaR / Size
			Bits(i+1) = SomaG / Size
			Bits( i ) = SomaB / Size
			SomaR = 0
			SomaG = 0
			SomaB = 0
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure SoftnerBlur (DImage,SImage)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , j , k , GrayCmp, Gray, SomaR , SomaG , SomaB , h, w, a, b
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			Gray = (Bits(i+2) + Bits(i+1) + Bits(i)) / 3
			If (Gray > 127)
				For a = -3 To 3
					For b = -3 To 3
						j = (h + Lim_Max (h, a, Height)) * LineWidth + 3 * (w + Lim_Max (w, b, Width))
						If ((h + a < 0) Or (w + b < 0))
							j = i
						EndIf		
						SomaR + Bits(j+2)
						SomaG + Bits(j+1)
						SomaB + Bits( j )
					Next
				Next
				Bits(i+2) = SomaR / 49
				Bits(i+1) = SomaG / 49
				Bits( i ) = SomaB / 49
				SomaR = 0
				SomaG = 0
				SomaB = 0
			Else
				For a = -1 To 1
					For b = -1 To 1
						j = (h + Lim_Max (h, a, Height)) * LineWidth + 3 * (w + Lim_Max (w, b, Width))
						If ((h + a < 0) Or (w + b < 0))
							j = i
						EndIf		
						SomaR + Bits(j+2)
						SomaG + Bits(j+1)
						SomaB + Bits( j )
					Next
				Next
				Bits(i+2) = SomaR / 9
				Bits(i+1) = SomaG / 9
				Bits( i ) = SomaB / 9
				SomaR = 0
				SomaG = 0
				SomaB = 0
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure MotionBlur (DImage,SImage,Angle.d=45.0,Distance.l=5)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim Newbits.c (BitCount)
	
	If (Angle = 0.0)
		Angle = 0.0001
	EndIf
	
	Define.l i , j, R , G , B , Size = Distance * 2 + 1, h, w, a
	Define.d nw, nh
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			For a = -Distance To Distance
				nw = (w + a * Cos ((2 * #PI) / (360 / Angle)))
				nh = (h + a * Sin ((2 * #PI) / (360 / Angle)))
				nw=Min(Max(nw ,Width-1),0)
				nh=Min(Max(nh ,Height-1),0)
				
				j = Int(nh * LineWidth + 3 * nw)
				R + Bits(j+2)
				G + Bits(j+1)
				B + Bits( j )
			Next
			NewBits(i+2) = R / Size
			NewBits(i+1) = G / Size
			NewBits( i ) = B / Size
			R = 0
			G = 0
			B = 0
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure ColorBalance (DImage,SImage,r.c=0,g.c=0,b.c=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , w, h
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			Bits(i+2) = LimitValues (Int(Bits(i+2) + R))
			Bits(i+1) = LimitValues (Int(Bits(i+1) + G))
			Bits( i ) = LimitValues (Int(Bits( i ) + B))
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure Fragment (DImage,SImage,Distance.l=2)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim Layer1.c (BitCount)
	Dim Layer2.c (BitCount)
	Dim Layer3.c (BitCount)
	Dim Layer4.c (BitCount)
	
	
	Define.l i , j , nw, nh, h, w
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			nh=Max(h + Distance,Height-1)
			
			j = nh * LineWidth + 3 * w
			Layer1(i+2) = Bits(j+2)
			Layer1(i+1) = Bits(j+1)
			Layer1( i ) = Bits( j )
			nh=Min(h - Distance ,0)
			
			j = nh * LineWidth + 3 * w
			Layer2(i+2) = Bits(j+2)
			Layer2(i+1) = Bits(j+1)
			Layer2( i ) = Bits( j )
			nw=Max(w + Distance,Width-1)
			
			j = h * LineWidth + 3 * nw
			Layer3(i+2) = Bits(j+2)
			Layer3(i+1) = Bits(j+1)
			Layer3( i ) = Bits( j )
			nw=Min(w - Distance ,0)
			
			j = h * LineWidth + 3 * nw
			Layer4(i+2) = Bits(j+2)
			Layer4(i+1) = Bits(j+1)
			Layer4( i ) = Bits( j )
		Next
	Next
	DoEvents ()
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			Bits(i+2) = (Layer1(i+2) + Layer2(i+2) + Layer3(i+2) + Layer4(i+2)) / 4
			Bits(i+1) = (Layer1(i+1) + Layer2(i+1) + Layer3(i+1) + Layer4(i+1)) / 4
			Bits( i ) = (Layer1( i ) + Layer2( i ) + Layer3( i ) + Layer4( i )) / 4
		Next
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure FarBlur (DImage,SImage,Distance.l=1)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim Newbits.c (BitCount)
	
	If (Distance < 1)
		Distance = 1
	EndIf
	
	Define.l i , j , nw, nh, counter , SomaR , SomaG , SomaB , h, w, a, b
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			For a = -Distance To Distance
				For b = -Distance To Distance
					If ((a = -Distance) Or (a = Distance))
						nw=Min(Max(w + b,Width-1),0) : w + b
						nh=Min(Max(h + a,Height-1),0) : h + a
						j = nh * LineWidth + 3 * nw
						SomaR + Bits(j+2)
						SomaG + Bits(j+1)
						SomaB + Bits( j )
						counter+1
					Else
						nw=Min(Max(w - Distance,Width-1),0) : w - Distance
						nh=Min(Max(h + a,Height-1),0) : h + a
						j = nh * LineWidth + 3 * nw
						SomaR + Bits(j+2)
						SomaG + Bits(j+1)
						SomaB + Bits( j )
						nw=Min(Max(w + Distance,Width-1),0) : w + Distance
						nh=Min(Max(h + a,Height-1),0) : h + a
						j = nh * LineWidth + 3 * nw
						SomaR + Bits(j+2)
						SomaG + Bits(j+1)
						SomaB + Bits( j )
						
						counter + 2
						b = Distance
					EndIf
				Next
			Next
			i = h * LineWidth + 3 * w
			NewBits(i+2) =  SomaR / counter
			NewBits(i+1) =  SomaG / counter
			NewBits( i ) =  SomaB / counter
			SomaR = 0
			SomaG = 0
			SomaB = 0
			counter = 0
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure RadialBlur (DImage,SImage,Distance.l=5)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	If Distance <= 0
		ProcedureReturn #True
	EndIf
	ImageToArray()
	Dim Newbits.c (BitCount)
	
	If (Distance < 1)
		Distance = 1
	EndIf
	
	Define.l i , j , nw, nh, SomaR , SomaG , SomaB , counter , h, w , a
	Define.d AngleRad, Radius, Angle
	
	For w = 0 To Width-1
		For  h = 0 To Height-1
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			AngleRad = ATan2 (nw, nh)
			For a = -Distance To Distance
				Angle = AngleRad + (a * #ANGLE_PERCENTAGE)
				
				nw=Min(Max( Int(Width / 2 - Radius * Cos (Angle)),Width-1),0)
				nh=Min(Max(Int(Height / 2 - Radius * Sin (Angle)) ,Height-1),0)
				j = nh * LineWidth + 3 * nw
				SomaR + Bits(j+2)
				SomaG + Bits(j+1)
				SomaB + Bits( j )
				counter+1
			Next
			i = h * LineWidth + 3 * w
			NewBits(i+2) = SomaR / counter
			NewBits(i+1) = SomaG / counter
			NewBits( i ) = SomaB / counter
			SomaR = 0
			SomaG = 0
			SomaB = 0
			counter = 0
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*w/Width)
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure ZoomBlur (DImage,SImage,Distance.l=5)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	If Distance <= 0
		ProcedureReturn #True
	EndIf
	ImageToArray()
	Dim Newbits.c (BitCount)
	
	If (Distance < 1)
		Distance = 1
	EndIf
	
	Define.l i , j , nw, nh, SomaR , SomaG , SomaB ,n1,n2,w , h, a
	Define.d AngleRad, Radius, dNew, Radmax = Sqr (Height * Height + Width * Width)
	
	For w = 0 To Width-1
		For  h = 0 To Height-1
			nw = Width / 2 - w
			nh = Height / 2 - h
			Radius = Sqr (nw * nw + nh * nh)
			AngleRad = ATan2 (nw, nh)
			dNew = (Radius * Distance) / Radmax
			For a = 0 To dNew-1
				nw=Min(Max(  Int(Width / 2 - (Radius - a) * Cos (AngleRad)),Width-1),0)
				nh=Min(Max( Int(Height / 2 - (Radius - a) * Sin (AngleRad)),Height-1),0)
				j = nh * LineWidth + 3 * nw
				SomaR + Bits(j+2)
				SomaG + Bits(j+1)
				SomaB + Bits( j )
			Next
			i = h * LineWidth + 3 * w
			If dNew
				NewBits(i+2) = SomaR / Int(dNew+1 )
				NewBits(i+1) = SomaG / Int(dNew +1)
				NewBits( i ) = SomaB / Int(dNew+1 )
			Else
				NewBits(i+2) = Bits(i+2)
				NewBits(i+1) = Bits(i+1)
				NewBits( i ) = Bits( i )
			EndIf
			SomaR = 0
			SomaG = 0
			SomaB = 0
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*w/Width)
	Next
	ArrayToImage(Newbits())
EndProcedure

Procedure xFog (DImage,SImage,Fogvalue.l=5)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , h , w
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			If (Bits(i+2) > 127)
				Bits(i+2) = LimitValues (Bits(i+2) - Fogvalue)
				Bits(i+2) = min(Bits(i+2) , 127)
			Else
				Bits(i+2) = LimitValues (Bits(i+2) + Fogvalue)
				Bits(i+2) = max(Bits(i+2) , 127)
			EndIf
			If (Bits(i+1) > 127)
				Bits(i+1) = LimitValues (Bits(i+1) - Fogvalue)
				Bits(i+1) = min(Bits(i+1) , 127)
			Else
				Bits(i+1) = LimitValues (Bits(i+1) + Fogvalue)
				Bits(i+1) = max(Bits(i+1) , 127)
			EndIf
			If (Bits( i ) > 127)
				Bits( i ) = LimitValues (Bits( i ) - Fogvalue)
				Bits( i ) = min(Bits( i ) , 127)
			Else
				Bits( i ) = LimitValues (Bits( i ) + Fogvalue)
				Bits( i ) = max(Bits( i ) , 127)
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure MediumTones (DImage,SImage,level.l=5)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Define.l i , HalfR, HalfG, HalfB, h, w
	Define.d RAdd , GAdd , BAdd
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			RAdd + Bits(i+2)
			GAdd + Bits(i+1)
			BAdd + Bits( i )
		Next
	Next
	
	HalfR = RAdd / (BitCount / 3) + 1
	HalfG = GAdd / (BitCount / 3) + 1
	HalfB = BAdd / (BitCount / 3) + 1
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			Bits(i+2) = LimitValues ((Bits(i+2) * Level) / HalfR)
			Bits(i+1) = LimitValues ((Bits(i+1) * Level) / HalfG)
			Bits( i ) = LimitValues ((Bits( i ) * Level) / HalfB)
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure OilPaint (DImage,SImage,BrushSize.l=5 , Smoothness.l = 10)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim Newbits.c (BitCount)
	
	BrushSize = Min(Max( BrushSize,5 ), 1)
	Smoothness = Min(Max( Smoothness,255 ), 10)
	
	Define.l i , color, h, w
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			color = MostFrequentColor (Bits(), Width, Height, w, h, BrushSize, Smoothness)
			NewBits(i+2) = color & $000000FF
			NewBits(i+1) = (color & $0000FF00) >>  8
			NewBits( i ) = (color & $00FF0000) >> 16
			
		Next
		DoEvents (); <<-- Drinn lassen,Berechnung dauert u.U. sehr lange
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Procedure BackDropRemoval (DImage,SImage, Range ,SelectColor, SubstituteColor)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	
	Define.l SelectR = (SelectColor & $000000FF),SelectG = (SelectColor & $0000FF00) >> 8,SelectB = (SelectColor & $00FF0000) >> 16
	Define.l SubsR = (SubstituteColor & $000000FF),SubsG = (SubstituteColor & $0000FF00) >> 8,SubsB = (SubstituteColor & $00FF0000) >> 16
	Define.l TempVar, RangeMinR, RangeMinG, RangeMinB
	Define.l RangeMaxR, RangeMaxG, RangeMaxB, i ,h ,w
	
	TempVar = int(SelectR - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinR = min(TempVar , 0)
	TempVar = int(SelectG - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinG = min(TempVar , 0)
	TempVar = int(SelectB - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinB = min(TempVar , 0)
	TempVar = int(SelectR + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxR = max(TempVar , 255)
	TempVar = int(SelectG + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxG = max(TempVar , 255)
	TempVar = int(SelectB + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxB = max(TempVar , 255)
	
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			If (((Bits(i+2) >= RangeMinR) And (Bits(i+2) <= RangeMaxR)) And ((Bits(i+1) >= RangeMinG) And (Bits(i+1) <= RangeMaxG)) And ((Bits( i ) >= RangeMinB) And (Bits( i ) <= RangeMaxB)))
				Bits(i+2) = SubsR
				Bits(i+1) = SubsG
				Bits( i ) = SubsB
			EndIf
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure BackDropRemovalEx (DImage,SImage, Range ,SelectColor, SubstituteColor, Top=0, Left=0, Right=0, Botton=0)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim Flags.c(BitCount)
	
	Define.l SelectR = (SelectColor & $000000FF),SelectG = (SelectColor & $0000FF00) >> 8,SelectB = (SelectColor & $00FF0000) >> 16
	Define.l SubsR = (SubstituteColor & $000000FF),SubsG = (SubstituteColor & $0000FF00) >> 8,SubsB = (SubstituteColor & $00FF0000) >> 16
	Define.l TempVar, RangeMinR, RangeMinG, RangeMinB
	Define.l RangeMaxR, RangeMaxG, RangeMaxB, i,h ,w
	
	TempVar = int(SelectR - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinR = min(TempVar , 0)
	TempVar = int(SelectG - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinG = min(TempVar , 0)
	TempVar = int(SelectB - ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMinB = min(TempVar , 0)
	TempVar = int(SelectR + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxR = max(TempVar , 255)
	TempVar = int(SelectG + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxG = max(TempVar , 255)
	TempVar = int(SelectB + ((Range / 2) * #COLOR_PERCENTAGE))
	RangeMaxB = max(TempVar , 255)
	
	If (Top)
		For w = 0 To Width-1
			For  h = 0 To Height-1
				i =(Height - h - 1) * LineWidth + 3 * w
				If ((Bits(i+2) = SubsR) And (Bits(i+1) = SubsG) And (Bits(i) = SubsB))
					Continue
				Else
					If (((Bits(i+2) >= RangeMinR) And (Bits(i+2) <= RangeMaxR)) And ((Bits(i+1) >= RangeMinG) And (Bits(i+1) <= RangeMaxG)) And ((Bits( i ) >= RangeMinB) And (Bits( i ) <= RangeMaxB)))
						Flags(i) = 1
					Else
						h = Height
					EndIf
				EndIf
			Next
		Next
	EndIf
	
	If (Left)
		For  h = 0 To Height-1
			For w = 0 To Width-1
				i = h * LineWidth + 3 * w
				If ((Bits(i+2) = SubsR) And (Bits(i+1) = SubsG) And (Bits(i) = SubsB))
					Continue
				Else
					If (((Bits(i+2) >= RangeMinR) And (Bits(i+2) <= RangeMaxR)) And ((Bits(i+1) >= RangeMinG) And (Bits(i+1) <= RangeMaxG)) And ((Bits( i ) >= RangeMinB) And (Bits( i ) <= RangeMaxB)))
						Flags(i) = 1
					Else
						w = Width
					EndIf
				EndIf
			Next
		Next
	EndIf
	
	If (Right)
		For  h = 0 To Height-1
			For w = 0 To Width-1
				i = h * LineWidth + 3 * (Width - w - 1)
				If ((Bits(i+2) = SubsR) And (Bits(i+1) = SubsG) And (Bits(i) = SubsB))
					Continue
				Else
					If (((Bits(i+2) >= RangeMinR) And (Bits(i+2) <= RangeMaxR)) And ((Bits(i+1) >= RangeMinG) And (Bits(i+1) <= RangeMaxG)) And ((Bits( i ) >= RangeMinB) And (Bits( i ) <= RangeMaxB)))
						Flags(i) = 1
					Else
						w = Width
					EndIf
				EndIf	
			Next
		Next
	EndIf
	
	If (Botton)
		For w = 0 To Width-1
			For  h = 0 To Height-1
				i = h * LineWidth + 3 * w
				If ((Bits(i+2) = SubsR) And (Bits(i+1) = SubsG) And (Bits(i) = SubsB))
					Continue
				Else
					If (((Bits(i+2) >= RangeMinR) And (Bits(i+2) <= RangeMaxR)) And ((Bits(i+1) >= RangeMinG) And (Bits(i+1) <= RangeMaxG)) And ((Bits( i ) >= RangeMinB) And (Bits( i ) <= RangeMaxB)))
						Flags(i) = 1
					Else
						h = Height
					EndIf
				EndIf
			Next
		Next
	EndIf
	DoEvents ()
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			If (Flags(i) = 1)
				Bits(i+2) = SubsR
				Bits(i+1) = SubsG
				Bits( i ) = SubsB
			EndIf
		Next
	Next
	
	ArrayToImage(bits())
EndProcedure

Procedure UnsharpMask (DImage,SImage, Blur.l ,Unsharp.d)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	Dim BlurBits.c(BitCount)
	Dim NewBits.c(BitCount)
	
	If (Blur < 1)
		ProcedureReturn #True
	EndIf
	If (Blur > 10)
		Blur = 10
	EndIf
	If (Unsharp < 0.0)
		ProcedureReturn #True
	EndIf
	If (Unsharp > 10.0)
		Unsharp = 10.0
	EndIf
	
	Define.d UnsharpPlus = Unsharp + 1.0
	Define.l i, j, h, w, SomaR , SomaG , SomaB , Orig = Blur, a, b
	
	Blur = Blur * 2 + 1
	
	Define.l Size = Blur * Blur
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			For a = -Orig To Orig
				For b = -Orig To Orig
					j = (h + Lim_Max (h, a, Height)) * LineWidth + 3 * (w + Lim_Max (w, b, Width))
					If ((h + a < 0) Or (w + b < 0))
						j = i
					EndIf	
					SomaR + Bits(j+2)
					SomaG + Bits(j+1)
					SomaB + Bits( j )
				Next
			Next
			BlurBits(i+2) = SomaR / Size
			BlurBits(i+1) = SomaG / Size
			BlurBits( i ) = SomaB / Size
			SomaR = 0
			SomaG = 0
			SomaB = 0
			
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			NewBits(i+2) = LimitValues (int(UnsharpPlus * Bits(i+2) - Unsharp * BlurBits(i+2)))
			NewBits(i+1) = LimitValues (int(UnsharpPlus * Bits(i+1) - Unsharp * BlurBits(i+1)))
			NewBits( i ) = LimitValues (int(UnsharpPlus * Bits( i ) - Unsharp * BlurBits( i )))
		Next
	Next
	
	ArrayToImage(Newbits())
EndProcedure
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von SoS »

Rest

Code: Alles auswählen

Procedure.l FrostGlass (DImage,SImage,Frost.l)
	Protected TemporaryBitmapInfo.BITMAPINFO, TemporaryBitmap.BITMAP ,PicDestDC.l,PicSrcDC.l ,BitCount ,Width,Height,LineWidth =0
	ImageToArray()
	
	Dim NewBits.c (BitCount)
	
	Frost = min(max(Frost , 10) ,1)
	
	Define.l i , j , h, w,color
	
	For  h = 0 To Height-1
		For w = 0 To Width-1
			i = h * LineWidth + 3 * w
			color = RandomColor (Bits(), Width, Height, w, h, Frost)
			NewBits(i+2) = (color & $000000FF)
			NewBits(i+1) = (color & $0000FF00) >>  8
			NewBits( i ) = (color & $00FF0000) >> 16
		Next
		DoEvents ()
		SetGadgetState(ProgressBar_0,100*h/Height)
	Next
	
	ArrayToImage(Newbits())
EndProcedure

Macro args(anzahl)
	Select anzahl
		Case 0
			DisableGadget(TrackBar_6, 1)
			DisableGadget(TrackBar_0, 1)
			DisableGadget(TrackBar_1, 1)
			DisableGadget(TrackBar_2, 1)
			DisableGadget(TrackBar_3, 1)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 1
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 1)
			DisableGadget(TrackBar_1, 1)
			DisableGadget(TrackBar_2, 1)
			DisableGadget(TrackBar_3, 1)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 2
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 1)
			DisableGadget(TrackBar_2, 1)
			DisableGadget(TrackBar_3, 1)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 3
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 0)
			DisableGadget(TrackBar_2, 1)
			DisableGadget(TrackBar_3, 1)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 4
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 0)
			DisableGadget(TrackBar_2, 0)
			DisableGadget(TrackBar_3, 1)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 5
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 0)
			DisableGadget(TrackBar_2, 0)
			DisableGadget(TrackBar_3, 0)
			DisableGadget(TrackBar_4, 1)
			DisableGadget(TrackBar_5, 1)
		Case 6
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 0)
			DisableGadget(TrackBar_2, 0)
			DisableGadget(TrackBar_3, 0)
			DisableGadget(TrackBar_4, 0)
			DisableGadget(TrackBar_5, 1)
		Case 7
			DisableGadget(TrackBar_6, 0)
			DisableGadget(TrackBar_0, 0)
			DisableGadget(TrackBar_1, 0)
			DisableGadget(TrackBar_2, 0)
			DisableGadget(TrackBar_3, 0)
			DisableGadget(TrackBar_4, 0)
			DisableGadget(TrackBar_5, 0)
	EndSelect
EndMacro

Macro set()
	SetGadgetAttribute(ScrollArea_0, #PB_ScrollArea_InnerHeight,ImageHeight(SCR_Image))				
	SetGadgetAttribute(ScrollArea_0, #PB_ScrollArea_InnerWidth, ImageWidth(SCR_Image))
	SendMessage_(GadgetID(Image_37),#STM_SETIMAGE,#IMAGE_BITMAP,ImageID(DES_Image))
EndMacro

Procedure menuselect (FX)
	Protected wtxt.s ,Ticks.l
	Shared GFX.l
	GFX=FX
	If IsImage(DES_Image) And IsImage(SCR_Image)
		wtxt =GetMenuItemText(Menu_0, FX)
		
		Select FX
			Case F1 ;  "Color Adjustment"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 512)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Colorize(DES_Image,SCR_Image,-256+GetGadgetState(TrackBar_6),RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F2 ;  "Brightness"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Brightness (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F3 ;  "Contrast"
				args(4)
				DisableGadget(TrackBar_6, 1)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 2550)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 2550)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 2550)
				Ticks = timeGetTime_()
				Contrast (DES_Image,SCR_Image,GetGadgetState(TrackBar_0)* 0.001,GetGadgetState(TrackBar_1)* 0.001,GetGadgetState(TrackBar_2)* 0.001)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F4 ;  "Sharpening"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 89)
				Ticks = timeGetTime_()
				sharpen (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F5 ;  "Gamma Adjust"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 100)
				Ticks = timeGetTime_()
				Gamma (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F6 ;  "Reduce Colors"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 256)
				Ticks = timeGetTime_()
				ReduceColors (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F7 ;  "Reduce to 8 colors"
				args(0)
				Ticks = timeGetTime_()
				Reduceto8Colors (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F8 ;  "Shift Effect"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Shift (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F9 ;  "Saturation"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 767)
				Ticks = timeGetTime_()
				Saturation (DES_Image,SCR_Image,-255+GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F10 ;  "Hue Adjust"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 350)
				Ticks = timeGetTime_()
				Hue (DES_Image,SCR_Image, GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F11 ;  "Color Balance"
				args(4)
				DisableGadget(TrackBar_6, 1)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				ColorBalance (DES_Image,SCR_Image,GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F12 ;  "WebColors Mode"
				args(0)
				Ticks = timeGetTime_()
				WebColors (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F13 ;  "Medium Tones"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				MediumTones (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F14 ;  "Stretch Histogram"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 8)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 200)
				Ticks = timeGetTime_()
				StretchHistogram (DES_Image,SCR_Image, GetGadgetState(TrackBar_6), GetGadgetState(TrackBar_0)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F15 ;  "AntiAlias"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				AntiAlias (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F16 ;  "Blur"
				args(0)
				Ticks = timeGetTime_()
				Blur (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F17 ;  "SmartBlur"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				SmartBlur (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F18 ;  "More Blur"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				AdvancedBlur (DES_Image,SCR_Image,GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F19 ;  "Softner Blur"
				args(0)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				SoftnerBlur (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F20 ;  "Motion Blur"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 2550)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 25)
				Ticks = timeGetTime_()
				MotionBlur (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.1,GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F21 ;  "Far Blur"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 900)
				Ticks = timeGetTime_()
				FarBlur (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F22 ;  "Radial Blur"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				RadialBlur (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F23 ;  "Zoom Blur"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				ZoomBlur (DES_Image,SCR_Image,100+GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F24 ;  "Unsharp Mask"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 100)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 10)
				Ticks = timeGetTime_()
				UnsharpMask (DES_Image,SCR_Image, GetGadgetState(TrackBar_0) ,GetGadgetState(TrackBar_6)*0.1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F25 ;  "Gray Tones"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 512)
				Ticks = timeGetTime_()
				GrayScale (DES_Image,SCR_Image,-256+GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F26 ;  "Sepia Effect"
				args(0)
				Ticks = timeGetTime_()
				Sepia (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F27 ;  "Ambient Light"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				AmbientLight (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F28 ;  "Tone Adjust"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Tone (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F29 ;  "Mosaic"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 50)
				Ticks = timeGetTime_()
				Mosaic (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F30 ;  "Diffuse"
				args(0)
				Ticks = timeGetTime_()
				Diffuse (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F31 ;  "Rock Effect"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 50)
				Ticks = timeGetTime_()
				Rock (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F32 ;  "Noise"
				
			Case F33 ;  "Melt"
				args(0)
				Ticks = timeGetTime_()
				Melt (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F34 ;  "Fish Eye"
				args(0)
				Ticks = timeGetTime_()
				FishEye (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F35 ;  "Fish Eye Ex"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1000)
				Ticks = timeGetTime_()
				FishEyeEX (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.001)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F36 ;  "Twirl"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 720)
				Ticks = timeGetTime_()
				Twirl (DES_Image,SCR_Image, -360+GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F37 ;  "TwirlEx"
				args(3)
				DisableGadget(TrackBar_6, 1)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 10000)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 10000)
				Ticks = timeGetTime_()
				TwirlEx (DES_Image,SCR_Image, -50.0+ GetGadgetState(TrackBar_0)*0.01,-50.0+ GetGadgetState(TrackBar_1)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F38 ;  "Swirl"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 720)
				Ticks = timeGetTime_()
				Swirl (DES_Image,SCR_Image,-360+GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F39 ;  "Make 3d"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 40)
				Ticks = timeGetTime_()
				Make3DEffect (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F40 ;  "Four Corners"
				args(0)
				Ticks = timeGetTime_()
				FourCorners (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F41 ;  "Caricature"
				args(0)
				Ticks = timeGetTime_()
				Caricature (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F42 ;  "Enroll"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1000)
				Ticks = timeGetTime_()
				Roll (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F43 ;  "Polar Coordinates"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1000)
				Ticks = timeGetTime_()
				PolarCoordinates (DES_Image,SCR_Image,0.0001+GetGadgetState(TrackBar_6)*0.01)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F44 ;  "Cilindrical"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1000)
				Ticks = timeGetTime_()
				Cilindrical (DES_Image,SCR_Image,0.001+GetGadgetState(TrackBar_6)/50)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F45 ;  "Waves"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 300)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 1)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 2)
				Ticks = timeGetTime_()
				Waves (DES_Image,SCR_Image,-127+GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0)*0.01,GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F46 ;  "Block Waves"
				args(3)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum,20)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 1000)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 5)
				Ticks = timeGetTime_()
				BlockWaves (DES_Image,SCR_Image,GetGadgetState(TrackBar_6)*0.3,GetGadgetState(TrackBar_0)*0.1,GetGadgetState(TrackBar_1))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F47 ;  "Circular Waves"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 50)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 50)
				Ticks = timeGetTime_()
				CircularWaves (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F48 ;  "Circular Waves Enhanced"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 100)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 100)
				Ticks = timeGetTime_()
				CircularWavesEX (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F49 ;  "Backdrop Removal"
	 			args(7)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_3, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_4, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_5, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				BackDropRemovalex (DES_Image,SCR_Image, GetGadgetState(TrackBar_6) ,RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)),RGB(GetGadgetState(TrackBar_3),GetGadgetState(TrackBar_4),GetGadgetState(TrackBar_5)),1,1,1,1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F50 ;  "Emboss / Engrave"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1000)
				Ticks = timeGetTime_()
				Emboss (DES_Image,SCR_Image,0.1+GetGadgetState(TrackBar_6)/99)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F51 ;  "Neon"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 5)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 10)
				Ticks = timeGetTime_()
				Neon (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F52 ;  "Detect Borders"
				args(7)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_3, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_4, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_5, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				DetectBorders (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)),RGB(GetGadgetState(TrackBar_3),GetGadgetState(TrackBar_4),GetGadgetState(TrackBar_5)))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F53 ;  "Find Edges"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 20)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 10)
				Ticks = timeGetTime_()
				FindEdges (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F54 ;  "Note Paper"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 5)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 60)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 10)
				Ticks = timeGetTime_()
				NotePaper (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F55 ;  "AlphaBlend"
				
			Case F56 ;  "Blend Modes"
				
			Case F57 ;  "Glass Blend Mode"
				
			Case F58 ;  "Metallic"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 10)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Metallic (DES_Image,SCR_Image, 1+GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0),1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F59 ;  "Gold"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 10)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Metallic (DES_Image,SCR_Image, 1+GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0),2)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F60 ;  "Ice"
				args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 10)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Metallic (DES_Image,SCR_Image, 1+GetGadgetState(TrackBar_6),GetGadgetState(TrackBar_0),3)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F61 ;  "Invertion Adjust"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Invert (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F62 ;  "Monochrome"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				Stamp (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F63 ;  "Replace Color"
				
			Case F64 ;  "Ascii Effect"
	 			args(0)
				Ticks = timeGetTime_()
				AsciiMorph (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F65 ;  "Random Points"
				args(4)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 10)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 255)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 255)
				Ticks = timeGetTime_()
				RandomicalPointse (DES_Image,SCR_Image,GetGadgetState(TrackBar_6),RGB(GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2)))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F66 ;  "Solarize"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 1)
				Ticks = timeGetTime_()
				Solarize (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F67 ;  "Canvas Adjust"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, ImageWidth(SCR_Image))
				Ticks = timeGetTime_()
				Canvas (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F68 ;  "Relief"
				args(0)
				Ticks = timeGetTime_()
				Relief (DES_Image,SCR_Image)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F69 ;  "Tile Effect"
				args(4)
				DisableGadget(TrackBar_6, 1)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 127)
				SetGadgetAttribute(TrackBar_1, #PB_TrackBar_Maximum, 127)
				SetGadgetAttribute(TrackBar_2, #PB_TrackBar_Maximum, 127)
				Ticks = timeGetTime_()
				Tile (DES_Image,SCR_Image, GetGadgetState(TrackBar_0),GetGadgetState(TrackBar_1),GetGadgetState(TrackBar_2))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F70 ;  "Fragment"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 512)
				Ticks = timeGetTime_()
				Fragment (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F71 ;  "Fog Effect"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 127)
				Ticks = timeGetTime_()
				xFog (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F72 ;  "Oil Paint"
	 			args(2)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 9)
				SetGadgetAttribute(TrackBar_0, #PB_TrackBar_Maximum, 245)
				Ticks = timeGetTime_()
				OilPaint (DES_Image,SCR_Image,1+GetGadgetState(TrackBar_6),10+GetGadgetState(TrackBar_0))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F73 ;  "Frost Glass"
				args(1)
				SetGadgetAttribute(TrackBar_6, #PB_TrackBar_Maximum, 10)
				Ticks = timeGetTime_()
				FrostGlass (DES_Image,SCR_Image,GetGadgetState(TrackBar_6))
				Ticks = timeGetTime_() - Ticks
				set()
			Case F74 ;  "Flip Horizontal"
				args(0)
				Ticks = timeGetTime_()
				Flip (DES_Image,SCR_Image,ImageWidth(SCR_Image),ImageHeight(SCR_Image),1,0)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F75 ;  "Flip Vertical"
				args(0)
				Ticks = timeGetTime_()
				Flip (DES_Image,SCR_Image,ImageWidth(SCR_Image),ImageHeight(SCR_Image),0,1)
				Ticks = timeGetTime_() - Ticks
				set()
			Case F76 ;  "Flip Both"
				args(0)
				Ticks = timeGetTime_()
				Flip (DES_Image,SCR_Image,ImageWidth(SCR_Image),ImageHeight(SCR_Image),1,1)
				Ticks = timeGetTime_() - Ticks
				set()
		EndSelect
		
		SetWindowTitle(Window_0, wtxt+"   "+Str(ticks)+"  ms"+" @"+str(ImageWidth(SCR_Image))+"x"+str(ImageHeight(SCR_Image)))
	EndIf
EndProcedure

Structure VisualDesignerGadgets
  Gadget.l
  EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()

Procedure RegisterGadgetEvent(Gadget, *Function)
	
  If IsGadget(Gadget)
    AddElement(EventProcedures())
    EventProcedures()\Gadget        = Gadget
    EventProcedures()\EventFunction = *Function
	EndIf
	
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
	
  ForEach EventProcedures()
    If EventProcedures()\Gadget = Gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
      LastElement(EventProcedures())
		EndIf
	Next
	
EndProcedure


Procedure Button_2_Event(Window, Event, Gadget, Type)
 	If IsImage(SCR_Image)
		FreeImage(SCR_Image)
	EndIf
	SCR_Image=CopyImage(DES_Image,#PB_Any)
EndProcedure

Procedure Button_1_Event(Window, Event, Gadget, Type)
	Protected FileName$
  FileName$ = OpenFileRequester("SELECT IMAGE","","All supported formats |*.bmp;BMP image (*.bmp)",0)
	If FileName$
		SaveImage(DES_Image, FileName$ , #PB_ImagePlugin_BMP )
	EndIf
EndProcedure

Procedure Button_0_Event(Window, Event, Gadget, Type)
	Protected FileName$
	Shared GFX
	Define.l w_new ,h_new
	FileName$ = OpenFileRequester("SELECT IMAGE","","All supported formats|*.bmp;*.ico;*.cur;*.gif;*.jpg;*.jpeg;*.wmf;*.emf;*.png;*.tiff;*.tga|TGA image (*.tga)|*.tga|TIFF image (*.tiff)|*.tiff|PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|Icon file (*.ico)|*.ico|Cursor file (*.cur)|*.cur|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif|Windows Metafile (*.wmf)|*.wmf|Enhanced Metafile (*.emf)|*.emf",0)
	If FileName$
		SCR_Image=ImageFromFile(Filename$)
		If IsImage(SCR_Image) And GetGadgetState(CheckBox_0)
			If IsImage(SCR_Image)
				w_new=530
				h_new=510
				AspectSize(ImageWidth(SCR_Image),ImageHeight(SCR_Image),@w_new,@h_new)
				ResizeImage(SCR_Image,w_new,h_new,#PB_Image_Smooth)
				If IsImage(DES_Image)
					FreeImage(DES_Image)
					DES_Image=CreateImage(#PB_Any,ImageWidth(SCR_Image),ImageHeight(SCR_Image),24)	
				Else
					DES_Image=CreateImage(#PB_Any,ImageWidth(SCR_Image),ImageHeight(SCR_Image),24)
				EndIf
				menuselect(GFX)
			EndIf
		ElseIf  IsImage(SCR_Image)
			If 	ImageWidth(SCR_Image) % 4
				w_new.l=ImageWidth(SCR_Image)
				h_new.l=ImageHeight(SCR_Image)
				AspectSize(ImageWidth(SCR_Image),ImageHeight(SCR_Image),@w_new,@h_new)
				ResizeImage(SCR_Image,w_new,h_new,#PB_Image_Smooth)
			EndIf
			If IsImage(DES_Image)
				FreeImage(DES_Image)
				DES_Image=CreateImage(#PB_Any,ImageWidth(SCR_Image),ImageHeight(SCR_Image),24)	
			Else
				DES_Image=CreateImage(#PB_Any,ImageWidth(SCR_Image),ImageHeight(SCR_Image),24)
			EndIf
			menuselect(GFX)
		EndIf
	EndIf
EndProcedure


Procedure TrackBar_6_Event(Window, Event, Gadget, Type)
  Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_5_Event(Window, Event, Gadget, Type)
  Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_4_Event(Window, Event, Gadget, Type)
	Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_3_Event(Window, Event, Gadget, Type)
  Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_2_Event(Window, Event, Gadget, Type)
	Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_1_Event(Window, Event, Gadget, Type)
  Shared GFX
	menuselect(GFX)
EndProcedure

Procedure TrackBar_0_Event(Window, Event, Gadget, Type)
  Shared GFX
	menuselect(GFX)
EndProcedure


Procedure ScrollArea_0_Event(Window, Event, Gadget, Type)
  Debug "ScrollArea_0"
EndProcedure



Procedure Open_Window_0()
  Shared GFX
	Define.l x
  Window_0 = OpenWindow(#PB_Any, 31, 38, 704, 600, "Window 0",  #PB_Window_SystemMenu | #PB_Window_TitleBar )
  Menu_0 = CreateImageMenu(#PB_Any, WindowID(Window_0), #PB_Menu_ModernLook);
	If Menu_0
		x=1	
		MenuTitle( "Effects" )
		F1= x :  MenuItem(  x  ,   "Color Adjustment" ) : x+1
		F2= x :  MenuItem(  x  ,   "Brightness" ) : x+1
		F3= x :  MenuItem(  x  ,   "Contrast" ) : x+1
		F4= x :  MenuItem(  x  ,   "Sharpening" ) : x+1
		F5= x :  MenuItem(  x  ,   "Gamma Adjust" ) : x+1
		F6= x :  MenuItem(  x  ,   "Reduce Colors" ) : x+1
		F7= x :  MenuItem(  x  ,   "Reduce to 8 colors" ) : x+1
		F8= x :  MenuItem(  x  ,   "Shift Effect" ) : x+1
		F9= x :  MenuItem(  x  ,   "Saturation" ) : x+1
		F10= x :  MenuItem(  x  ,   "Hue Adjust" ) : x+1
		F11= x :  MenuItem(  x  ,   "Color Balance" ) : x+1
		F12= x :  MenuItem(  x  ,   "WebColors Mode" ) : x+1
		F13= x :  MenuItem(  x  ,   "Medium Tones" ) : x+1
		F14= x :  MenuItem(  x  ,   "Stretch Histogram" ) : x+1
		
		MenuTitle( "Blur" )
		F15= x :  MenuItem(  x  ,   "AntiAlias" ) : x+1
		F16= x :  MenuItem(  x  ,   "Blur" ) : x+1
		F17= x :  MenuItem(  x  ,   "SmartBlur" ) : x+1
		F18= x :  MenuItem(  x  ,   "More Blur" ) : x+1
		F19= x :  MenuItem(  x  ,   "Softner Blur" ) : x+1
		F20= x :  MenuItem(  x  ,   "Motion Blur" ) : x+1
		F21= x :  MenuItem(  x  ,   "Far Blur" ) : x+1
		F22= x :  MenuItem(  x  ,   "Radial Blur" ) : x+1
		F23= x :  MenuItem(  x  ,   "Zoom Blur" ) : x+1
		F24= x :  MenuItem(  x  ,   "Unsharp Mask" ) : x+1
		
		MenuTitle( "Tones" )
		F25= x :  MenuItem(  x  ,   "Gray Tones" ) : x+1
		F26= x :  MenuItem(  x  ,   "Sepia Effect" ) : x+1
		F27= x :  MenuItem(  x  ,   "Ambient Light" ) : x+1
		F28= x :  MenuItem(  x  ,   "Tone Adjust" ) : x+1
		
		MenuTitle( "Distortion" )
		F29= x :  MenuItem(  x  ,   "Mosaic" ) : x+1
		F30= x :  MenuItem(  x  ,   "Diffuse" ) : x+1
		F31= x :  MenuItem(  x  ,   "Rock Effect" ) : x+1
		F32= x :  MenuItem(  x  ,   "Noise" ) : x+1
		F33= x :  MenuItem(  x  ,   "Melt" ) : x+1
		F34= x :  MenuItem(  x  ,   "Fish Eye" ) : x+1
		F35= x :  MenuItem(  x  ,   "Fish Eye Ex" ) : x+1
		F36= x :  MenuItem(  x  ,   "Twirl" ) : x+1
		F37= x :  MenuItem(  x  ,   "TwirlEx" ) : x+1
		F38= x :  MenuItem(  x  ,   "Swirl" ) : x+1
		F39= x :  MenuItem(  x  ,   "Make 3d" ) : x+1
		F40= x :  MenuItem(  x  ,   "Four Corners" ) : x+1
		F41= x :  MenuItem(  x  ,   "Caricature" ) : x+1
		F42= x :  MenuItem(  x  ,   "Enroll" ) : x+1
		F43= x :  MenuItem(  x  ,   "Polar Coordinates" ) : x+1
		F44= x :  MenuItem(  x  ,   "Cilindrical" ) : x+1
		
		MenuTitle( "Waves" )
		F45= x :  MenuItem(  x  ,   "Waves" ) : x+1
		F46= x :  MenuItem(  x  ,   "Block Waves" ) : x+1
		F47= x :  MenuItem(  x  ,   "Circular Waves" ) : x+1
		F48= x :  MenuItem(  x  ,   "Circular Waves Enhanced" ) : x+1
		
		MenuTitle( "Borders" )
		F49= x :  MenuItem(  x  ,   "Backdrop Removal" ) : x+1
		F50= x :  MenuItem(  x  ,   "Emboss / Engrave" ) : x+1
		F51= x :  MenuItem(  x  ,   "Neon" ) : x+1
		F52= x :  MenuItem(  x  ,   "Detect Borders" ) : x+1
		F53= x :  MenuItem(  x  ,   "Find Edges" ) : x+1
		F54= x :  MenuItem(  x  ,   "Note Paper" ) : x+1
		
		; MenuTitle( "Blend Modes" )
		; F55= x :  MenuItem(  x  ,   "AlphaBlend" ) : x+1
		; F56= x :  MenuItem(  x  ,   "Blend Modes" ) : x+1
		; F57= x :  MenuItem(  x  ,   "Glass Blend Mode" ) : x+1
		
		MenuTitle( "Metallic Effects" )
		F58= x :  MenuItem(  x  ,   "Metallic" ) : x+1
		F59= x :  MenuItem(  x  ,   "Gold" ) : x+1
		F60= x :  MenuItem(  x  ,   "Ice" ) : x+1
		
		MenuTitle( "Other Effects" )
		F61= x :  MenuItem(  x  ,   "Invertion Adjust" ) : x+1
		F62= x :  MenuItem(  x  ,   "Monochrome" ) : x+1
		F63= x :  MenuItem(  x  ,   "Replace Color" ) : x+1
		F64= x :  MenuItem(  x  ,   "Ascii Effect" ) : x+1
		F65= x :  MenuItem(  x  ,   "Random Points" ) : x+1
		F66= x :  MenuItem(  x  ,   "Solarize" ) : x+1
		F67= x :  MenuItem(  x  ,   "Canvas Adjust" ) : x+1
		F68= x :  MenuItem(  x  ,   "Relief" ) : x+1
		F69= x :  MenuItem(  x  ,   "Tile Effect" ) : x+1
		F70= x :  MenuItem(  x  ,   "Fragment" ) : x+1
		F71= x :  MenuItem(  x  ,   "Fog Effect" ) : x+1
		F72= x :  MenuItem(  x  ,   "Oil Paint" ) : x+1
		F73= x :  MenuItem(  x  ,   "Frost Glass" ) : x+1
		
		MenuTitle( "Image" )
		F74= x :  MenuItem(  x  ,   "Flip Horizontal" ) : x+1
		F75= x :  MenuItem(  x  ,   "Flip Vertical" ) : x+1
		F76= x :  MenuItem(  x  ,   "Flip Both" ) : x+1
	EndIf	
	ScrollArea_0 = ScrollAreaGadget(#PB_Any, 0, 0, 540, 520, 540, 520, 0)
		Image_37 = ImageGadget(#PB_Any, 0, 0, 660, 690, 0, #PB_Image_Border)
	CloseGadgetList()
	RegisterGadgetEvent(ScrollArea_0, @ScrollArea_0_Event())
	
	Container_0 = ContainerGadget(#PB_Any, 550, 0, 140, 520,#PB_Container_Raised)
		
		TrackBar_0 = TrackBarGadget(#PB_Any, 10, 10, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_1 = TrackBarGadget(#PB_Any, 40, 10, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_2 = TrackBarGadget(#PB_Any, 70, 10, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_3 = TrackBarGadget(#PB_Any, 10, 260, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_4 = TrackBarGadget(#PB_Any, 40, 260, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_5 = TrackBarGadget(#PB_Any, 70, 260, 26, 240, 0, 10, #PB_TrackBar_Vertical)
		TrackBar_6 = TrackBarGadget(#PB_Any, 100, 10, 30, 490, 0, 10, #PB_TrackBar_Vertical)
		RegisterGadgetEvent(TrackBar_6, @TrackBar_6_Event())
		RegisterGadgetEvent(TrackBar_5, @TrackBar_5_Event())
		RegisterGadgetEvent(TrackBar_4, @TrackBar_4_Event())
		RegisterGadgetEvent(TrackBar_3, @TrackBar_3_Event())
		RegisterGadgetEvent(TrackBar_2, @TrackBar_2_Event())
		RegisterGadgetEvent(TrackBar_1, @TrackBar_1_Event())
		RegisterGadgetEvent(TrackBar_0, @TrackBar_0_Event())
	CloseGadgetList()
	Container_1 = ContainerGadget(#PB_Any, 0, 525, 690, 50,#PB_Container_Raised)
		Button_0 = ButtonGadget(#PB_Any, 10, 7, 90, 30, "Öffnen")
		Button_1 = ButtonGadget(#PB_Any, 120, 7, 90, 30, "Speichern")
		Button_2 = ButtonGadget(#PB_Any, 230, 7, 90, 30, "Übernehmen")
		ProgressBar_0 = ProgressBarGadget(#PB_Any,350, 7, 200, 10, 0, 100, #PB_ProgressBar_Smooth)
		CheckBox_0 = CheckBoxGadget(#PB_Any, 570,7, 110, 30, "Grösse Anpassen" , #PB_CheckBox_Center)
		RegisterGadgetEvent(Button_2, @Button_2_Event())
		RegisterGadgetEvent(Button_1, @Button_1_Event())
		RegisterGadgetEvent(Button_0, @Button_0_Event())
	CloseGadgetList()
	GFX=F33
EndProcedure

Open_Window_0()

Repeat
	
  Event  = WaitWindowEvent(20)
  Gadget = EventGadget()
  Type   = EventType()
  Window = EventWindow()
	
  Select Event
		Case #PB_Event_Gadget
      CallEventFunction(Window, Event, Gadget, Type)
		Case #PB_Event_Menu
			menuselect (EventMenu())
	EndSelect
	
Until Event = #PB_Event_CloseWindow

End

DataSection
	table:
	Data.c '#', 'W', 'M', 'B', 'R', 'X', 'V', 'Y', 'I', 't', 'i', '+', '=', ';', ':', ',', '.',' '
EndDataSection
Benutzeravatar
dige
Beiträge: 1236
Registriert: 08.09.2004 08:53

Re: GraphicalDLL VC++ --> PB

Beitrag von dige »

Boah!!! :allright: Das ist ja randvoll mit grafischen Effekten. Werds erstmal intensiv testen..
"Papa, ich laufe schneller - dann ist es nicht so weit."
c4s
Beiträge: 1235
Registriert: 19.09.2007 22:18

Re: GraphicalDLL VC++ --> PB

Beitrag von c4s »

Fantastisch - Ich bin sehr beeindruckt!
Vielen Dank, dass du uns diese unglaubliche Fülle an Bildbearbeitungsfunktionen bereitstellst. :allright:

Nur ein kleiner Tipp:
Das nächste mal solltest du den Quellcode auch in einer einzelnen Datei bei z.B. http://em.q-soft.ch/ hochladen, damit man vor lauter Code, immerhin 4300 Zeilen, die Kommentare nicht übersieht.
"Menschenskinder, das Niveau dieses Forums singt schon wieder!" — GronkhLP ||| "ich hogffe ihr könnt den fehle endecken" — Marvin133 ||| "Ideoten gibts ..." — computerfreak ||| "Jup, danke. Gruss" — funkheld
Benutzeravatar
neotoma
Beiträge: 202
Registriert: 13.09.2004 16:16
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von neotoma »

Beeindruckend!

Ich habe allerdings nur die schiere Menge PB-Code gesehen - und dann erstmal die C++-Sourcen runtergeladen.

Wäre es nicht möglich - nur als anregung - das ganze als Statische Bibliothek mit VC zu bauen und in PB über Import-Befehle dazu linken?

Man verliert dann zwar die flexibilität, den Code schnell zu änder/erweitern ect.
Dahingegen hätten man das original - das auch so funktionieren sollte wie vom Autor geplant. (Und auch schneller...)

Gruß,
Mike
Alle Rechtschreibfehler unterliegen der GPL und dürfen frei kopiert und modifiziert werden.
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von SoS »

neotoma hat geschrieben: Wäre es nicht möglich - nur als anregung - das ganze als Statische Bibliothek mit VC zu bauen und in PB über Import-Befehle dazu linken?
Sicher wäre es möglich,müsste sich nur jemand finden der sich damit auskennt und das übernimmt.
Weiterhin müssten auch noch einige Bugs gefixt werden die im VC Code noch drinn sind.
z.b. funktioniert Emboss mit der Dll nicht (bekomme nur ein komplett graues Image),mein 1:1 übesetzter
Code läuft dagegen tadellos.
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 7028
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von STARGÅTE »

Nette Sammlung,

aber ein paar Befehle könnte man noch schneller machen, wenn man sie mit PB-Befehlen realisiert.
Stichwort: CustomFilterCallback()
Zumindest die Farbmanipulationen (wie zB. Helligkeit) wäre damit schneller.

Hier n Beispiel für Helligkeit:

Code: Alles auswählen

Enumeration
  #Window
  #Gadget
  #Image
  #SaveImage
  #TrackBarGadget
EndEnumeration
 
Procedure Until255(Value.i)
  If Value > 255 : ProcedureReturn 255 : Else : ProcedureReturn Value : EndIf
EndProcedure
 
Global IC_BN.i
Procedure ImageBrightnessCallback(x, y, TopColor, BottomColor)
  ProcedureReturn Until255(TopColor&$FF+IC_BN)+Until255(TopColor>>8&$FF+IC_BN)<<8+Until255(TopColor>>16&$FF+IC_BN)<<16
EndProcedure

Procedure ImageBrightness(Image, Brightness)
  StartDrawing(ImageOutput(Image))
    DrawingMode(#PB_2DDrawing_CustomFilter)
    IC_BN = Brightness
    CustomFilterCallback(@ImageBrightnessCallback())
    DrawImage(ImageID(#SaveImage), 0, 0)
  StopDrawing()
EndProcedure


UseJPEGImageDecoder()
UsePNGImageDecoder()

LoadImage(#Image, OpenFileRequester("", "", "", 0))
CopyImage(#Image, #SaveImage)
 
OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image)+20, "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
  ImageGadget(#Gadget, 0, 20, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
  TrackBarGadget(#TrackBarGadget, 0, 0, 255, 20, 0, 255)
 
Repeat
  Event = WaitWindowEvent()
  Select Event
   Case #PB_Event_Gadget
    Select EventGadget()
     Case #TrackBarGadget
     Time = timeGetTime_()
     ImageBrightness(#Image, GetGadgetState(#TrackBarGadget))
     Time1 = timeGetTime_()-Time
     SetWindowTitle(#Window, "Image - "+Str(Time1))
     SetGadgetState(#Gadget, ImageID(#Image))
    EndSelect
   Case #PB_Event_CloseWindow
    End
  EndSelect
ForEver
Zeit-Vergleich beim selben Bild ( 3000 x 2000 Pixel ):
Deins : 175ms
Meins : 130ms
(Natürlich beides ohne Debugger)

Klar das man die Sachen wo sich Pixel verschieben damit nicht lösen kann, bzw es langsammer wäre ...

Da wäre auch nocht eine Frage ...
Das ganze ist ja bei dir zur Zeit noch "nur" 24Bit, wird es später auch noch mit Alpha-Unterstützen sein ?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: GraphicalDLL VC++ --> PB

Beitrag von SoS »

STARGÅTE hat geschrieben:Nette Sammlung,

aber ein paar Befehle könnte man noch schneller machen, wenn man sie mit PB-Befehlen realisiert.
Stichwort: CustomFilterCallback()
Zumindest die Farbmanipulationen (wie zB. Helligkeit) wäre damit schneller.

Hier n Beispiel für Helligkeit:


Zeit-Vergleich beim selben Bild ( 3000 x 2000 Pixel ):
Deins : 175ms
Meins : 130ms
(Natürlich beides ohne Debugger)

Klar das man die Sachen wo sich Pixel verschieben damit nicht lösen kann, bzw es langsammer wäre ...

Da wäre auch nocht eine Frage ...
Das ganze ist ja bei dir zur Zeit noch "nur" 24Bit, wird es später auch noch mit Alpha-Unterstützen sein ?
Mit Speedtests bin ich immer vorsichtig, mein Image (hatte gerade nix grösseres) 1500x999

Deins 63 ms
"Meins" 31 ms

Hab allerdings etwas am Code geändert.

Ich schicke Dir noch ne PN.
Benutzeravatar
DrShrek
Beiträge: 1970
Registriert: 08.09.2004 00:59

Re: GraphicalDLL VC++ --> PB

Beitrag von DrShrek »

neotoma hat geschrieben:Beeindruckend!
Wäre es nicht möglich - nur als anregung - das ganze als Statische Bibliothek mit VC zu bauen und in PB über Import-Befehle dazu linken?
Hallo Mike,
Ich habe hier mal schnell die DLL generiert. Mit VisualStudio 2010.
Eine StaticLib kann ich sicher auch noch rauspurzeln lassen.
http://em.q-soft.ch/files/get/_qyt_Bt2C ... caldll.zip

Hier noch die Funktionsliste:

Code: Alles auswählen

	GPX_BackDropRemoval	
	GPX_BackDropRemovalEx
	GPX_Sepia
	GPX_ReduceTo2Colors	
	GPX_ReduceTo8Colors	
	GPX_ReduceColors
	GPX_Stamp	
	GPX_Brightness
	GPX_Rock
	GPX_Sharpening	
	GPX_AmbientLight
	GPX_AntiAlias
	GPX_Emboss	
	GPX_Gamma
	GPX_Invert
	GPX_Shift
	GPX_Tone
	GPX_Contrast
	GPX_GrayScale
	GPX_RandomicalPoints
	GPX_ColorRandomize
	GPX_Solarize
	GPX_Diffuse
	GPX_Mosaic
	GPX_Melt	
	GPX_FishEye
	GPX_Swirl	
	GPX_Twirl
	GPX_Neon	
	GPX_Canvas
	GPX_Waves
	GPX_BlockWaves
	GPX_DetectBorders
	GPX_Blur	
	GPX_Relief
	GPX_Saturation
	GPX_FindEdges
	GPX_AllocBufferSize
	GPX_AsciiMorph	
	GPX_Hue
	GPX_AlphaBlend
	GPX_Make3DEffect
	GPX_FourCorners
	GPX_Caricature
	GPX_Tile
	GPX_Roll
	GPX_SmartBlur
	GPX_AdvancedBlur
	GPX_SoftnerBlur
	GPX_MotionBlur
	GPX_ColorBalance
	GPX_Fragment
	GPX_FarBlur
	GPX_RadialBlur
	GPX_ZoomBlur
	GPX_WebColors
	GPX_Fog
	GPX_MediumTones
	GPX_CircularWaves
	GPX_CircularWavesEx
	GPX_PolarCoordinates
	GPX_OilPaint
	GPX_FrostGlass
	GPX_NotePaper
	GPX_FishEyeEx
	GPX_RainDrops
	GPX_Cilindrical
	GPX_UnsharpMask
	GPX_Flip
	GPX_BitBlt
	GPX_StretchHistogram
	GPX_BlendMode
	GPX_TwirlEx
	GPX_GlassBlendMode
	GPX_Metallic
Siehste! Geht doch....?!
PB*, *4PB, PetriDish, Movie2Image, PictureManager, TrainYourBrain, ...
Antworten