package provide Freetype::ftlcdfil 0.1

if {![info exists _source([file tail [info script]])]} {
package require Freetype::ft2build
package require $FT_FREETYPE

set FT_LCD_FILTER_NONE    0
set FT_LCD_FILTER_DEFAULT 1
set FT_LCD_FILTER_LIGHT   2
set FT_LCD_FILTER_LEGACY  16
set FT_LCD_FILTER_MAX     17


if {[catch {::ffidl::symbol $::ft::lib FT_Library_SetLcdFilter} _symbol] == 0} {
::ffidl::callout _FT_Library_SetLcdFilter {pointer int} int $_symbol
proc FT_Library_SetLcdFilter {library filter} {
    set result [_FT_Library_SetLcdFilter [$library getPointer] $filter]
    return $result
}
}

if {[catch {::ffidl::symbol $::ft::lib FT_Library_SetLcdFilterWeights} _symbol] == 0} {
::ffidl::callout _FT_Library_SetLcdFilterWeights {pointer pointer} int $_symbol
proc FT_Library_SetLcdFilterWeights {library weights} {
    set temp [list]
    lappend $weights 0 0 0 0 0
    for {set i 0} {$i < 5} {incr i} {
        set v [lindex $weights $i]
        if {$v > 0xFF} {set v 0xFF}
        if {$v < 0x00} {set v 0x00}
        lappend temp $v
    }
    set buf [::ft::_bytearray_from_list $temp FT_Byte]
    ::ft::get_bytearray_pointer buf adr len

    set result [_FT_Library_SetLcdFilterWeights [$library getPointer] $adr]
    return $result
}
}
    
set _source([file tail [info script]]) 1
}
