#Include Once "windows.bi"
#Include Once "win/ole2.bi"
#include once "win/commdlg.bi"
#INCLUDE Once "win/gdiplus.bi"
#Include Once "crt.bi"
Using GDIPLUS

Dim gdiplusToken As ULONG_PTR
Dim GDIPLUSSTARTUPINPUT_01 As GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
If (GdiplusStartup(@gdiplusToken, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) Then
    Print "FAIL"
EndIf

#Undef true
#Undef false
#Define false 0 
#Define true (Not false)

#Undef BOOLEAN
type BOOLEAN as Byte

Type PropertyItem
    propId As Long
    Length As Long
    type As Integer
    Value As Long ptr
End Type

Type ColorPalette
    flags As Long
    Count As Long
    Entries(0 To 255) As Long
End Type

Type clsOctree
	Public:
		IsLeaf As Boolean                                                ' True - "лист"
		Depth As Long                                                    ' Глубина
		ColorIndex As Long                                               ' Индекс в палитре
		ChildCount As Long                                               ' Количество дочерних валидных элементов
		ColorCount As Long                                               ' Количество обращений
		Nxt As clsOctree  Ptr                                               ' Позиция следующего листа в связном списке
		R As Long                                                        ' Компоненты цвета
		G As Long
		B As Long
		Declare Property Child(ByVal Index As Long) As clsOctree Ptr
		Declare Property Child(ByVal Index As Long, ByRef Value As clsOctree Ptr)
		Declare Property GetNearestPaletteIndex(Col As RGBTriple) As Long 
		Declare Property GetNearestPaletteIndex(i As Integer) 
		Declare Sub GetPalette(Pal() As Long, ByRef StartIndex As Long = 0)
		Declare Sub AddTree(Col As RGBTriple ptr, ByVal Depth As Long)
		Declare Sub KillChild()
		Declare Sub ReduceTree()
		Declare Constructor()
	Private:
		ReDim mChild(Any) As clsOctree Ptr                                          ' Дочерние узлы
		ReDim Mask(Any) As Long                                                  ' Маска глубины битности	
End Type


Const EncoderParameterValueTypeLong = 4
Const EncoderValueMultiFrame = 18
Const EncoderValueFlush = 20
Const EncoderValueFrameDimensionTime = 21
Const PaletteFlagsHasAlpha = &H1

Dim shared As Guid GuidEncoderSaveFlag = Type(&h292266fc,&hac40,&h47bf,{&h8c, &hfc, &ha8, &h5b, &h89, &ha6, &h55, &hde})
' Глобальные переменные октодерева
Dim Shared TreeLeafLevel As Long, _
       TreeSize As Long, _
       TreeReduceLevel As Long
ReDim Shared TreeReduceList() As clsOctree Ptr
Dim  Shared ListCount As Integer
Dim Shared As Integer LastValidLoopCount
Dim Shared pix8 As Byte Ptr 'указатель на палитру 8 бит
Dim Shared dimfiles(100) As ZString*max_path ' массив для сохранений путей изображений 
Declare Function Conv256(ByRef Bitmap As Any ptr, ByRef Threshold As Long) As Boolean
Declare Function SetDispMode(ByVal pt As byte Ptr, ByVal Count As Long) As Boolean