text:
# Conversions

## LPC, LSP, PARCOR conversions

function lpc2c!(dst_ceps::StridedVector{Cdouble},
                src_lpc::StridedVector{Cdouble})
    src_order = length(src_lpc) - 1
    dst_order = length(dst_ceps) - 1
    ccall((:lpc2c, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
          src_lpc, src_order, dst_ceps, dst_order)
    dst_ceps
end

function lpc2c(src_lpc::StridedVector{Cdouble}, dst_order=length(src_lpc)-1)
    src_order = length(src_lpc) - 1
    dst_ceps = Array{Cdouble}(dst_order+1)
    lpc2c!(dst_ceps, src_lpc)
end

function lpc2lsp!(lsp::StridedVector{Cdouble}, lpc::StridedVector{Cdouble};
                  numsp::Int=512,
                  maxiter::Int=4,
                  eps::Float64=1e-6,
                  loggain::Bool=false,
                  otype::Int=0,
                  fs=nothing)
    if length(lsp) != length(lpc)
        throw(DimensionMismatch("inconsistent dimentions"))
    end
    fill!(lsp, zero(eltype(lsp)))
    order = length(lsp) - 1
    ccall((:lpc2lsp, libSPTK), Void,
          (Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint, Cint, Cdouble),
          lpc, pointer(lsp, 2), order, numsp, maxiter, eps)

    if otype == 0
        for i=2:length(lsp)
            @inbounds lsp[i] *= 2π
        end
    elseif otype ∈ 2:3
        fs == nothing && error("fs must be specified when otype == 2 or 3")
        for i=2:length(lsp)
            @inbounds lsp[i] *= fs
        end
    end

    # this is really ugly...
    if otype == 3
        for i=2:length(lsp)
            @inbounds lsp[i] *= 1000.0
        end
    end

    if loggain
        lsp[1] = log(lpc[1])
    else
        lsp[1] = lpc[1]
    end

    lsp
end

function lpc2lsp(lpc::StridedVector{Cdouble}; kargs...)
    lsp = zeros(lpc)
    lpc2lsp!(lsp, lpc; kargs...)
end

function lpc2par!(par::StridedVector{Cdouble}, lpc::StridedVector{Cdouble})
    if length(par) != length(lpc)
        throw(DimensionMismatch("inconsistent dimentions"))
    end
    ccall((:lpc2par, libSPTK), Void, (Ptr{Cdouble}, Ptr{Cdouble}, Cint),
          lpc, par, length(lpc)-1)
    par
end

function lpc2par(lpc::StridedVector{Cdouble})
    par = similar(lpc)
    lpc2par!(par, lpc)
end

function par2lpc!(lpc::StridedVector{Cdouble}, par::StridedVector{Cdouble})
    if length(lpc) != length(par)
        throw(DimensionMismatch("inconsistent dimentions"))
    end
    # NOTE: Since par2lpc destroys input PARCOR coefficients,
    # so passing its copy to the ccall to keep PARCOR coeff. unchanged
    ccall((:par2lpc, libSPTK), Void, (Ptr{Cdouble}, Ptr{Cdouble}, Cint),
          copy(par), lpc, length(par)-1)
    lpc
end

function par2lpc(par::StridedVector{Cdouble})
    lpc = similar(par)
    par2lpc!(lpc, par)
    return lpc
end

# assume lsp has loggain at lsp[1]
function lsp2sp!(sp::StridedVector{Cdouble}, lsp::StridedVector{Cdouble})
    fftlen = (length(sp) - 1)<<1
    assert_fftlen(fftlen)
    ccall((:lsp2sp, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cint),
          lsp, length(lsp)-1, sp, length(sp), 1)
    sp
end

function lsp2sp(lsp::StridedVector{Cdouble}, fftlen=256)
    assert_fftlen(fftlen)
    sp = Array{Cdouble}(fftlen>>1+1)
    lsp2sp!(sp, lsp)
end

## Mel-generalized cepstrum conversions

function mc2b!(b::StridedVector{Cdouble}, mc::StridedVector{Cdouble}, α=0.35)
    if length(b) != length(mc)
        throw(DimensionMismatch("inconstent dimensions"))
    end
    order = length(b) - 1
    ccall((:mc2b, libSPTK), Void, (Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cdouble),
          mc, b, order, α)
    b
end

function mc2b(mc::StridedVector{Cdouble}, α=0.35)
    b = similar(mc)
    mc2b!(b, mc, α)
end

function b2mc!(mc::StridedVector{Cdouble}, b::StridedVector{Cdouble}, α=0.35)
    if length(mc) != length(b)
        throw(DimensionMismatch("inconstent dimensions"))
    end
    order = length(b) - 1
    ccall((:b2mc, libSPTK), Void, (Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cdouble),
          b, mc, order, α)
    mc
end

function b2mc(b::StridedVector{Cdouble}, α=0.35)
    mc = similar(b)
    b2mc!(mc, b, α)
end

function b2c!(dst_ceps::StridedVector{Cdouble}, src_b::StridedVector{Cdouble},
              α)
    src_order = length(src_b) - 1
    dst_order = length(dst_ceps) - 1
    ccall((:b2c, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cdouble),
          src_b, src_order, dst_ceps, dst_order, α)
    dst_ceps
end

function b2c(src_b::StridedVector{Cdouble}, dst_order=length(src_b)-1, α=0.35)
    dst_ceps = Array{Cdouble}(dst_order + 1)
    b2c!(dst_ceps, src_b, α)
end

function c2acr!(r::StridedVector{Cdouble}, c::StridedVector{Cdouble},
                fftlen=256)
    assert_fftlen(fftlen)
    dst_order = length(r) - 1
    ccall((:c2acr, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cint),
          c, length(c) - 1, r, dst_order, fftlen)
    r
end

function c2acr(c::StridedVector{Cdouble}, order=length(c)-1, fftlen=256)
    r = Array{Cdouble}(order + 1)
    c2acr!(r, c, fftlen)
end

function c2ir!(h::StridedVector{Cdouble}, c::StridedVector{Cdouble})
    order = length(c) # NOT length(c) - 1
    ccall((:c2ir, libSPTK), Void, (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
          c, order, h, length(h))
    h
end

function c2ir(c::StridedVector{Cdouble}, len=256)
    h = Array{Cdouble}(len)
    c2ir!(h, c)
end

function ic2ir!(c::StridedVector{Cdouble}, h::StridedVector{Cdouble})
    ccall((:ic2ir, libSPTK), Void, (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
          h, length(h), c, length(c))
    c
end

function ic2ir(h::StridedVector{Cdouble}, order=25)
    c = Array{Cdouble}(order+1)
    ic2ir!(c, h)
end

function c2ndps!(ndps::StridedVector{Cdouble}, c::StridedVector{Cdouble})
    fftlen = (length(ndps) - 1)<<1
    assert_fftlen(fftlen)
    buf = Array{Cdouble}(fftlen)
    m = length(c)-1
    ccall((:c2ndps, libSPTK), Void, (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
          c, m, buf, fftlen)
    for i = 1:length(ndps)
        @inbounds ndps[i] = buf[i]
    end

    ndps
end

function c2ndps(c::StridedVector{Cdouble}, fftlen=256)
    assert_fftlen(fftlen)
    ndps = Array{Cdouble}(fftlen>>1 + 1)
    c2ndps!(ndps, c)
end

function ndps2c!(dst_ceps::StridedVector{Cdouble}, ndps::StridedVector{Cdouble})
    order = length(dst_ceps) - 1
    fftlen = (length(ndps) - 1)<<1 # assuming the length of npds is fftsize/2+1
    assert_fftlen(fftlen)
    ccall((:ndps2c, libSPTK), Void, (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
          ndps, fftlen, dst_ceps, order)
    dst_ceps
end

function ndps2c(ndps::StridedVector{Cdouble}, order=25)
    dst_ceps = Array{Cdouble}(order + 1)
    ndps2c!(dst_ceps, ndps)
end

function gc2gc!(dst_ceps::StridedVector{Cdouble}, dst_γ,
                src_ceps::StridedVector{Cdouble}, src_γ)
    assert_gamma(dst_γ)
    assert_gamma(src_γ)
    dst_order = length(dst_ceps) - 1
    src_order = length(src_ceps) - 1
    ccall((:gc2gc, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Cdouble, Ptr{Cdouble}, Cint, Cdouble),
          src_ceps, src_order, src_γ, dst_ceps, dst_order, dst_γ)
    dst_ceps
end

function gc2gc(src_ceps::StridedVector{Cdouble}, src_γ=0.0,
               dst_order=length(src_ceps)-1, dst_γ=0.0)
    src_order = length(src_ceps) - 1
    dst_ceps = Array{Cdouble}(dst_order + 1)
    gc2gc!(dst_ceps, dst_γ, src_ceps, src_γ)
end

function gc2gc(src_ceps::StridedVector{Cdouble}, src_γ::AbstractFloat,
        dst_γ::AbstractFloat)
    gc2gc(src_ceps, src_γ, length(src_ceps)-1, dst_γ)
end

function gnorm!(dst_ceps::StridedVector{Cdouble},
                src_ceps::StridedVector{Cdouble}, γ=0.0)
    assert_gamma(γ)
    if length(dst_ceps) != length(src_ceps)
        throw(DimensionMismatch("inconsistent dimensions"))
    end
    order = length(dst_ceps) - 1
    ccall((:gnorm, libSPTK), Void,
          (Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cdouble),
          src_ceps, dst_ceps, order, γ)
    dst_ceps
end

function gnorm(src_ceps::StridedVector{Cdouble}, γ=0.0)
    dst_ceps = similar(src_ceps)
    gnorm!(dst_ceps, src_ceps, γ)
end

function ignorm!(dst_ceps::StridedVector{Cdouble},
                 src_ceps::StridedVector{Cdouble}, γ=0.0)
    assert_gamma(γ)
    if length(dst_ceps) != length(src_ceps)
        throw(DimensionMismatch("inconsistent dimensions"))
    end
    order = length(dst_ceps) - 1
    ccall((:ignorm, libSPTK), Void,
          (Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cdouble),
          src_ceps, dst_ceps, order, γ)
    dst_ceps
end

function ignorm(src_ceps::StridedVector{Cdouble}, γ=0.0)
    dst_ceps = similar(src_ceps)
    ignorm!(dst_ceps, src_ceps, γ)
end

function freqt!(dst_ceps::StridedVector{Cdouble},
                src_ceps::StridedVector{Cdouble}, α=0.0)
    src_order = length(src_ceps) - 1
    dst_order = length(dst_ceps) - 1
    ccall((:freqt, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cdouble),
          src_ceps, src_order, dst_ceps, dst_order, α)
    dst_ceps
end

function freqt(ceps::StridedVector{Cdouble}, order=25, α=0.0)
    dst_ceps = Array{Cdouble}(order + 1)
    freqt!(dst_ceps, ceps, α)
end

function freqt(ceps::StridedVector{Cdouble}, α::AbstractFloat)
    freqt(ceps, length(ceps)-1, α)
end

function frqtr!(dst_ceps::StridedVector{Cdouble},
                src_ceps::StridedVector{Cdouble}, α=0.0)
    src_order = length(src_ceps) - 1
    dst_order = length(dst_ceps) - 1
    ccall((:frqtr, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cdouble),
          src_ceps, src_order, dst_ceps, dst_order, α)
    dst_ceps
end

function frqtr(ceps::StridedVector{Cdouble}, order=25, α=0.0)
    dst_ceps = Array{Cdouble}(order + 1)
    frqtr!(dst_ceps, ceps, α)
end

function frqtr(ceps::StridedVector{Cdouble}, α::AbstractFloat)
    frqtr(ceps, length(ceps)-1, α)
end

function mgc2mgc!(dst_ceps::StridedVector{Cdouble}, dst_α, dst_γ,
                  src_ceps::StridedVector{Cdouble}, src_α, src_γ)
    assert_gamma(dst_γ)
    assert_gamma(src_γ)
    src_order = length(src_ceps) - 1
    dst_order = length(dst_ceps) - 1
    ccall((:mgc2mgc, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Cdouble, Cdouble, Ptr{Cdouble}, Cint, Cdouble,
           Cdouble),
          src_ceps, src_order, src_α, src_γ,
          dst_ceps, dst_order, dst_α, dst_γ)
    dst_ceps
end

function mgc2mgc(src_ceps::StridedVector{Cdouble}, src_α=0.0, src_γ=0.0,
                 dst_order=length(src_ceps)-1, dst_α=0.0, dst_γ=0.0)
    dst_ceps = Array{Cdouble}(dst_order + 1)
    src_order = length(src_ceps) - 1
    mgc2mgc!(dst_ceps, dst_α, dst_γ, src_ceps, src_α, src_γ)
end

function mgc2mgc(src_ceps::StridedVector{Cdouble}, src_α::AbstractFloat,
        src_γ::AbstractFloat,
        dst_α::AbstractFloat, dst_γ::AbstractFloat)
    mgc2mgc(src_ceps, src_α, src_γ, length(src_ceps)-1, dst_α, dst_γ)
end

function mgc2sp!(sp::Vector{Complex{Cdouble}},
                 mgc::StridedVector{Cdouble}, α=0.0, γ=0.0)
    assert_gamma(γ)
    fftlen = (length(sp)-1)<<1
    assert_fftlen(fftlen)

    order = length(mgc) - 1
    sp_r = zeros(Cdouble, fftlen)
    sp_i = zeros(Cdouble, fftlen)
    ccall((:mgc2sp, libSPTK), Void,
          (Ptr{Cdouble}, Cint, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}, Cint),
          mgc, order, α, γ, sp_r, sp_i, fftlen)
    for i=1:length(sp)
        @inbounds sp[i] = Complex(sp_r[i], sp_i[i])
    end
    sp
end

function mgc2sp(mgc::StridedVector{Cdouble}, α=0.0, γ=0.0, fftlen=256)
    assert_fftlen(fftlen)
    order = length(mgc) - 1
    sp = Array{Complex{Cdouble}}(fftlen>>1 + 1)
    mgc2sp!(sp, mgc, α, γ)
end

function mgclsp2sp!(sp::StridedVector{Cdouble},
                    lsp::StridedVector{Cdouble}, α=0.0, γ=0.0;
                    gain::Bool=true)
    assert_gamma(γ)
    fftlen = (length(sp) - 1)<<1
    assert_fftlen(fftlen)
    order = gain ? length(lsp)-1 : length(lsp)
    ccall((:mgclsp2sp, libSPTK), Void, (Cdouble, Cdouble, Ptr{Cdouble}, Cint,
                                        Ptr{Cdouble}, Cint, Cint),
          α, γ, lsp, order, sp, length(sp), convert(Cint, gain))
    sp
end

function mgclsp2sp(lsp::StridedVector{Cdouble}, α=0.0, γ=0.0, fftlen=256;
                   kargs...)
    assert_fftlen(fftlen)
    sp = Array{Cdouble}(fftlen>>1 + 1)
    mgclsp2sp!(sp, lsp, α, γ; kargs...)
end


text:
# Julia wrapper for header: /Volumes/BOOTCAMP/programs/compa_libs/iup/cd/include/cd.h
# Automatically generated using Clang.jl wrap_c, version 0.0.0

@static is_windows()? (const libcd_ = "cd") : (const libcd_ = "libcd")  # Name of IUP shared lib.

function cdBaseDriver()
  ccall( (:cdBaseDriver, libcd_), Cint, (), )
end
function cdRegisterAttribute(canvas::Ptr{Cint}, attrib::Ptr{cdAttribute})
  ccall( (:cdRegisterAttribute, libcd_), Void, (Ptr{Cint}, Ptr{cdAttribute}), canvas, attrib)
end
function cdUpdateAttributes(canvas::Ptr{Cint})
  ccall( (:cdUpdateAttributes, libcd_), Void, (Ptr{Cint},), canvas)
end
#=
function cdCreateVectorFont(canvas::Ptr{Cint})
  ccall( (:cdCreateVectorFont, libcd_), Ptr{cdVectorFont}, (Ptr{Cint},), canvas)
end
function cdKillVectorFont(vector_font_data::Ptr{Void})
  ccall( (:cdKillVectorFont, libcd_), Void, (Ptr{cdVectorFont},), vector_font_data)
end
=#
function wdSetDefaults(canvas::Ptr{Cint})
  ccall( (:wdSetDefaults, libcd_), Void, (Ptr{Cint},), canvas)
end
function cdInitContextPlusList(ctx_list::Ptr{Ptr{Cint}})
  ccall( (:cdInitContextPlusList, libcd_), Void, (Ptr{Ptr{Cint}},), ctx_list)
end
function cdGetContextPlus()
  ccall( (:cdGetContextPlus, libcd_), Ptr{Cint}, (), )
end
function cdRound(x::Cdouble)
  ccall( (:cdRound, libcd_), Cint, (Cdouble,), x)
end
function cdCheckBoxSize(xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCheckBoxSize, libcd_), Cint, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), xmin, xmax, ymin, ymax)
end
function cdfCheckBoxSize(xmin::Ptr{Cdouble}, xmax::Ptr{Cdouble}, ymin::Ptr{Cdouble}, ymax::Ptr{Cdouble})
  ccall( (:cdfCheckBoxSize, libcd_), Cint, (Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), xmin, xmax, ymin, ymax)
end
function cdNormalizeLimits(w::Integer, h::Integer, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdNormalizeLimits, libcd_), Void, (Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), w, h, xmin, xmax, ymin, ymax)
end
function cdGetFileName(strdata::Ptr{UInt8}, filename::Ptr{UInt8})
  ccall( (:cdGetFileName, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}), strdata, filename)
end
function cdStrEqualNoCase(str1::Ptr{UInt8}, str2::Ptr{UInt8})
  ccall( (:cdStrEqualNoCase, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}), str1, str2)
end
function cdStrEqualNoCasePartial(str1::Ptr{UInt8}, str2::Ptr{UInt8})
  ccall( (:cdStrEqualNoCasePartial, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}), str1, str2)
end
function cdStrLineCount(str::Ptr{UInt8})
  ccall( (:cdStrLineCount, libcd_), Cint, (Ptr{UInt8},), str)
end
function cdStrDup(str::Ptr{UInt8})
  ccall( (:cdStrDup, libcd_), Ptr{UInt8}, (Ptr{UInt8},), str)
end
function cdStrDupN(str::Ptr{UInt8}, len::Integer)
  ccall( (:cdStrDupN, libcd_), Ptr{UInt8}, (Ptr{UInt8}, Cint), str, len)
end
function cdStrIsAscii(str::Ptr{UInt8})
  ccall( (:cdStrIsAscii, libcd_), Cint, (Ptr{UInt8},), str)
end
function cdSetPaperSize(size::Integer, w_pt::Ptr{Cdouble}, h_pt::Ptr{Cdouble})
  ccall( (:cdSetPaperSize, libcd_), Void, (Cint, Ptr{Cdouble}, Ptr{Cdouble}), size, w_pt, h_pt)
end
function cdGetFontFileName(type_face::Ptr{UInt8}, filename::Ptr{UInt8})
  ccall( (:cdGetFontFileName, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}), type_face, filename)
end
function cdGetFontFileNameDefault(type_face::Ptr{UInt8}, style::Integer, filename::Ptr{UInt8})
  ccall( (:cdGetFontFileNameDefault, libcd_), Cint, (Ptr{UInt8}, Cint, Ptr{UInt8}), type_face, style, filename)
end
function cdGetFontFileNameSystem(type_face::Ptr{UInt8}, style::Integer, filename::Ptr{UInt8})
  ccall( (:cdGetFontFileNameSystem, libcd_), Cint, (Ptr{UInt8}, Cint, Ptr{UInt8}), type_face, style, filename)
end
function cdStrTmpFileName(filename::Ptr{UInt8})
  ccall( (:cdStrTmpFileName, libcd_), Cint, (Ptr{UInt8},), filename)
end
function cdCanvasPoly(canvas::Ptr{Cint}, mode::Integer, points::Ptr{cdPoint}, n::Integer)
  ccall( (:cdCanvasPoly, libcd_), Void, (Ptr{Cint}, Cint, Ptr{cdPoint}, Cint), canvas, mode, points, n)
end
function cdCanvasGetArcBox(xc::Integer, yc::Integer, w::Integer, h::Integer, a1::Cdouble, a2::Cdouble, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCanvasGetArcBox, libcd_), Void, (Cint, Cint, Cint, Cint, Cdouble, Cdouble, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), xc, yc, w, h, a1, a2, xmin, xmax, ymin, ymax)
end
function cdCanvasGetArcPathF(poly::Ptr{cdPoint}, xc::Ptr{Cdouble}, yc::Ptr{Cdouble}, w::Ptr{Cdouble}, h::Ptr{Cdouble}, a1::Ptr{Cdouble}, a2::Ptr{Cdouble})
  ccall( (:cdCanvasGetArcPathF, libcd_), Cint, (Ptr{cdPoint}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), poly, xc, yc, w, h, a1, a2)
end
function cdfCanvasGetArcPath(poly::Ptr{cdfPoint}, xc::Ptr{Cdouble}, yc::Ptr{Cdouble}, w::Ptr{Cdouble}, h::Ptr{Cdouble}, a1::Ptr{Cdouble}, a2::Ptr{Cdouble})
  ccall( (:cdfCanvasGetArcPath, libcd_), Cint, (Ptr{cdfPoint}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), poly, xc, yc, w, h, a1, a2)
end
function cdCanvasGetArcPath(poly::Ptr{cdPoint}, xc::Ptr{Cint}, yc::Ptr{Cint}, w::Ptr{Cint}, h::Ptr{Cint}, a1::Ptr{Cdouble}, a2::Ptr{Cdouble})
  ccall( (:cdCanvasGetArcPath, libcd_), Cint, (Ptr{cdPoint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}), poly, xc, yc, w, h, a1, a2)
end
function cdCanvasGetArcStartEnd(xc::Integer, yc::Integer, w::Integer, h::Integer, a1::Cdouble, a2::Cdouble, x1::Ptr{Cint}, y1::Ptr{Cint}, x2::Ptr{Cint}, y2::Ptr{Cint})
  ccall( (:cdCanvasGetArcStartEnd, libcd_), Void, (Cint, Cint, Cint, Cint, Cdouble, Cdouble, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), xc, yc, w, h, a1, a2, x1, y1, x2, y2)
end
function cdfCanvasGetArcStartEnd(xc::Cdouble, yc::Cdouble, w::Cdouble, h::Cdouble, a1::Cdouble, a2::Cdouble, x1::Ptr{Cdouble}, y1::Ptr{Cdouble}, x2::Ptr{Cdouble}, y2::Ptr{Cdouble})
  ccall( (:cdfCanvasGetArcStartEnd, libcd_), Void, (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), xc, yc, w, h, a1, a2, x1, y1, x2, y2)
end
function cdMatrixTransformPoint(matrix::Ptr{Cdouble}, x::Integer, y::Integer, rx::Ptr{Cint}, ry::Ptr{Cint})
  ccall( (:cdMatrixTransformPoint, libcd_), Void, (Ptr{Cdouble}, Cint, Cint, Ptr{Cint}, Ptr{Cint}), matrix, x, y, rx, ry)
end
function cdfMatrixTransformPoint(matrix::Ptr{Cdouble}, x::Cdouble, y::Cdouble, rx::Ptr{Cdouble}, ry::Ptr{Cdouble})
  ccall( (:cdfMatrixTransformPoint, libcd_), Void, (Ptr{Cdouble}, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), matrix, x, y, rx, ry)
end
function cdMatrixMultiply(matrix::Ptr{Cdouble}, mul_matrix::Ptr{Cdouble})
  ccall( (:cdMatrixMultiply, libcd_), Void, (Ptr{Cdouble}, Ptr{Cdouble}), matrix, mul_matrix)
end
function cdMatrixInverse(matrix::Ptr{Cdouble}, inv_matrix::Ptr{Cdouble})
  ccall( (:cdMatrixInverse, libcd_), Void, (Ptr{Cdouble}, Ptr{Cdouble}), matrix, inv_matrix)
end
function cdfRotatePoint(canvas::Ptr{Cint}, x::Cdouble, y::Cdouble, cx::Cdouble, cy::Cdouble, rx::Ptr{Cdouble}, ry::Ptr{Cdouble}, sin_theta::Cdouble, cos_theta::Cdouble)
  ccall( (:cdfRotatePoint, libcd_), Void, (Ptr{Cint}, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}, Cdouble, Cdouble), canvas, x, y, cx, cy, rx, ry, sin_theta, cos_theta)
end
function cdRotatePoint(canvas::Ptr{Cint}, x::Integer, y::Integer, cx::Integer, cy::Integer, rx::Ptr{Cint}, ry::Ptr{Cint}, sin_teta::Cdouble, cos_teta::Cdouble)
  ccall( (:cdRotatePoint, libcd_), Void, (Ptr{Cint}, Cint, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Cdouble, Cdouble), canvas, x, y, cx, cy, rx, ry, sin_teta, cos_teta)
end
function cdRotatePointY(canvas::Ptr{Cint}, x::Integer, y::Integer, cx::Integer, cy::Integer, ry::Ptr{Cint}, sin_theta::Cdouble, cos_theta::Cdouble)
  ccall( (:cdRotatePointY, libcd_), Void, (Ptr{Cint}, Cint, Cint, Cint, Cint, Ptr{Cint}, Cdouble, Cdouble), canvas, x, y, cx, cy, ry, sin_theta, cos_theta)
end
function cdTextTranslatePoint(canvas::Ptr{Cint}, x::Integer, y::Integer, w::Integer, h::Integer, baseline::Integer, rx::Ptr{Cint}, ry::Ptr{Cint})
  ccall( (:cdTextTranslatePoint, libcd_), Void, (Ptr{Cint}, Cint, Cint, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}), canvas, x, y, w, h, baseline, rx, ry)
end
function cdMovePoint(x::Ptr{Cint}, y::Ptr{Cint}, dx::Cdouble, dy::Cdouble, sin_theta::Cdouble, cos_theta::Cdouble)
  ccall( (:cdMovePoint, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Cdouble, Cdouble, Cdouble, Cdouble), x, y, dx, dy, sin_theta, cos_theta)
end
function cdfMovePoint(x::Ptr{Cdouble}, y::Ptr{Cdouble}, dx::Cdouble, dy::Cdouble, sin_theta::Cdouble, cos_theta::Cdouble)
  ccall( (:cdfMovePoint, libcd_), Void, (Ptr{Cdouble}, Ptr{Cdouble}, Cdouble, Cdouble, Cdouble, Cdouble), x, y, dx, dy, sin_theta, cos_theta)
end
function cdParsePangoFont(nativefont::Ptr{UInt8}, type_face::Ptr{UInt8}, style::Ptr{Cint}, size::Ptr{Cint})
  ccall( (:cdParsePangoFont, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), nativefont, type_face, style, size)
end
function cdParseIupWinFont(nativefont::Ptr{UInt8}, type_face::Ptr{UInt8}, style::Ptr{Cint}, size::Ptr{Cint})
  ccall( (:cdParseIupWinFont, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), nativefont, type_face, style, size)
end
function cdParseXWinFont(nativefont::Ptr{UInt8}, type_face::Ptr{UInt8}, style::Ptr{Cint}, size::Ptr{Cint})
  ccall( (:cdParseXWinFont, libcd_), Cint, (Ptr{UInt8}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), nativefont, type_face, style, size)
end
function cdGetFontSizePixels(canvas::Ptr{Cint}, size::Integer)
  ccall( (:cdGetFontSizePixels, libcd_), Cint, (Ptr{Cint}, Cint), canvas, size)
end
function cdGetFontSizePoints(canvas::Ptr{Cint}, size::Integer)
  ccall( (:cdGetFontSizePoints, libcd_), Cint, (Ptr{Cint}, Cint), canvas, size)
end
function cdgetfontdimEX(ctxcanvas::Ptr{Void}, max_width::Ptr{Cint}, height::Ptr{Cint}, ascent::Ptr{Cint}, descent::Ptr{Cint})
  ccall( (:cdgetfontdimEX, libcd_), Void, (Ptr{Void}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), ctxcanvas, max_width, height, ascent, descent)
end
function cdgettextsizeEX(ctxcanvas::Ptr{Void}, s::Ptr{UInt8}, len::Integer, width::Ptr{Cint}, height::Ptr{Cint})
  ccall( (:cdgettextsizeEX, libcd_), Void, (Ptr{Void}, Ptr{UInt8}, Cint, Ptr{Cint}, Ptr{Cint}), ctxcanvas, s, len, width, height)
end
function cdZeroOrderInterpolation(width::Integer, height::Integer, map::Ptr{Cuchar}, xl::Cdouble, yl::Cdouble)
  ccall( (:cdZeroOrderInterpolation, libcd_), Cuchar, (Cint, Cint, Ptr{Cuchar}, Cdouble, Cdouble), width, height, map, xl, yl)
end
function cdBilinearInterpolation(width::Integer, height::Integer, map::Ptr{Cuchar}, xl::Cdouble, yl::Cdouble)
  ccall( (:cdBilinearInterpolation, libcd_), Cuchar, (Cint, Cint, Ptr{Cuchar}, Cdouble, Cdouble), width, height, map, xl, yl)
end
function cdImageRGBInitInverseTransform(w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer, xfactor::Ptr{Cdouble}, yfactor::Ptr{Cdouble}, matrix::Ptr{Cdouble}, inv_matrix::Ptr{Cdouble})
  ccall( (:cdImageRGBInitInverseTransform, libcd_), Void, (Cint, Cint, Cint, Cint, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), w, h, xmin, xmax, ymin, ymax, xfactor, yfactor, matrix, inv_matrix)
end
function cdImageRGBInverseTransform(t_x::Integer, t_y::Integer, i_x::Ptr{Cdouble}, i_y::Ptr{Cdouble}, xfactor::Cdouble, yfactor::Cdouble, xmin::Integer, ymin::Integer, x::Integer, y::Integer, inv_matrix::Ptr{Cdouble})
  ccall( (:cdImageRGBInverseTransform, libcd_), Void, (Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cdouble, Cdouble, Cint, Cint, Cint, Cint, Ptr{Cdouble}), t_x, t_y, i_x, i_y, xfactor, yfactor, xmin, ymin, x, y, inv_matrix)
end
function cdImageRGBCalcDstLimits(canvas::Ptr{Cint}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint}, rect::Ptr{Cint})
  ccall( (:cdImageRGBCalcDstLimits, libcd_), Void, (Ptr{Cint}, Cint, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, x, y, w, h, xmin, xmax, ymin, ymax, rect)
end
function cdRGB2Gray(width::Integer, height::Integer, red::Ptr{Cuchar}, green::Ptr{Cuchar}, blue::Ptr{Cuchar}, index::Ptr{Cuchar}, color::Ptr{Clong})
  ccall( (:cdRGB2Gray, libcd_), Void, (Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Clong}), width, height, red, green, blue, index, color)
end
function cdGetZoomTable(w::Integer, rw::Integer, xmin::Integer)
  ccall( (:cdGetZoomTable, libcd_), Ptr{Cint}, (Cint, Cint, Cint), w, rw, xmin)
end
function cdCalcZoom(canvas_size::Integer, cnv_rect_pos::Integer, cnv_rect_size::Integer, new_cnv_rect_pos::Ptr{Cint}, new_cnv_rect_size::Ptr{Cint}, img_rect_pos::Integer, img_rect_size::Integer, new_img_rect_pos::Ptr{Cint}, new_img_rect_size::Ptr{Cint}, is_horizontal::Integer)
  ccall( (:cdCalcZoom, libcd_), Cint, (Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Cint), canvas_size, cnv_rect_pos, cnv_rect_size, new_cnv_rect_pos, new_cnv_rect_size, img_rect_pos, img_rect_size, new_img_rect_pos, new_img_rect_size, is_horizontal)
end
function cdCreateSimulation(canvas::Ptr{Cint})
  ccall( (:cdCreateSimulation, libcd_), Ptr{Void}, (Ptr{Cint},), canvas)
end
function cdKillSimulation(simulation::Ptr{Void})
  ccall( (:cdKillSimulation, libcd_), Void, (Ptr{Void},), simulation)
end
function cdSimInitText(simulation::Ptr{Void})
  ccall( (:cdSimInitText, libcd_), Void, (Ptr{Void},), simulation)
end
function cdSimTextFT(ctxcanvas::Ptr{Void}, x::Integer, y::Integer, s::Ptr{UInt8}, len::Integer)
  ccall( (:cdSimTextFT, libcd_), Void, (Ptr{Void}, Cint, Cint, Ptr{UInt8}, Cint), ctxcanvas, x, y, s, len)
end
function cdSimFontFT(ctxcanvas::Ptr{Void}, type_face::Ptr{UInt8}, style::Integer, size::Integer)
  ccall( (:cdSimFontFT, libcd_), Cint, (Ptr{Void}, Ptr{UInt8}, Cint, Cint), ctxcanvas, type_face, style, size)
end
function cdSimGetFontDimFT(ctxcanvas::Ptr{Void}, max_width::Ptr{Cint}, height::Ptr{Cint}, ascent::Ptr{Cint}, descent::Ptr{Cint})
  ccall( (:cdSimGetFontDimFT, libcd_), Void, (Ptr{Void}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), ctxcanvas, max_width, height, ascent, descent)
end
function cdSimGetTextSizeFT(ctxcanvas::Ptr{Void}, s::Ptr{UInt8}, len::Integer, width::Ptr{Cint}, height::Ptr{Cint})
  ccall( (:cdSimGetTextSizeFT, libcd_), Void, (Ptr{Void}, Ptr{UInt8}, Cint, Ptr{Cint}, Ptr{Cint}), ctxcanvas, s, len, width, height)
end
function cdSimMark(canvas::Ptr{Cint}, x::Integer, y::Integer)
  ccall( (:cdSimMark, libcd_), Void, (Ptr{Cint}, Cint, Cint), canvas, x, y)
end
function cdSimPutImageRectRGBA(canvas::Ptr{Cint}, iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, a::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdSimPutImageRectRGBA, libcd_), Void, (Ptr{Cint}, Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), canvas, iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdSimPutImageRectRGB(canvas::Ptr{Cint}, iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdSimPutImageRectRGB, libcd_), Void, (Ptr{Cint}, Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdSimLine(ctxcanvas::Ptr{Void}, x1::Integer, y1::Integer, x2::Integer, y2::Integer)
  ccall( (:cdSimLine, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint), ctxcanvas, x1, y1, x2, y2)
end
function cdSimRect(ctxcanvas::Ptr{Void}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdSimRect, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint), ctxcanvas, xmin, xmax, ymin, ymax)
end
function cdSimBox(ctxcanvas::Ptr{Void}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdSimBox, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint), ctxcanvas, xmin, xmax, ymin, ymax)
end
function cdSimArc(ctxcanvas::Ptr{Void}, xc::Integer, yc::Integer, width::Integer, height::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdSimArc, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdSimSector(ctxcanvas::Ptr{Void}, xc::Integer, yc::Integer, width::Integer, height::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdSimSector, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdSimChord(ctxcanvas::Ptr{Void}, xc::Integer, yc::Integer, width::Integer, height::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdSimChord, libcd_), Void, (Ptr{Void}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdSimPoly(ctxcanvas::Ptr{Void}, mode::Integer, points::Ptr{cdPoint}, n::Integer)
  ccall( (:cdSimPoly, libcd_), Void, (Ptr{Void}, Cint, Ptr{cdPoint}, Cint), ctxcanvas, mode, points, n)
end
function cdSimPolyBezier(canvas::Ptr{Cint}, points::Ptr{cdPoint}, n::Integer)
  ccall( (:cdSimPolyBezier, libcd_), Void, (Ptr{Cint}, Ptr{cdPoint}, Cint), canvas, points, n)
end
function cdSimPolyPath(canvas::Ptr{Cint}, points::Ptr{cdPoint}, n::Integer)
  ccall( (:cdSimPolyPath, libcd_), Void, (Ptr{Cint}, Ptr{cdPoint}, Cint), canvas, points, n)
end
function cdfSimLine(ctxcanvas::Ptr{Void}, x1::Cdouble, y1::Cdouble, x2::Cdouble, y2::Cdouble)
  ccall( (:cdfSimLine, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, x1, y1, x2, y2)
end
function cdfSimRect(ctxcanvas::Ptr{Void}, xmin::Cdouble, xmax::Cdouble, ymin::Cdouble, ymax::Cdouble)
  ccall( (:cdfSimRect, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, xmin, xmax, ymin, ymax)
end
function cdfSimBox(ctxcanvas::Ptr{Void}, xmin::Cdouble, xmax::Cdouble, ymin::Cdouble, ymax::Cdouble)
  ccall( (:cdfSimBox, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, xmin, xmax, ymin, ymax)
end
function cdfSimArc(ctxcanvas::Ptr{Void}, xc::Cdouble, yc::Cdouble, width::Cdouble, height::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfSimArc, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdfSimSector(ctxcanvas::Ptr{Void}, xc::Cdouble, yc::Cdouble, width::Cdouble, height::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfSimSector, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdfSimChord(ctxcanvas::Ptr{Void}, xc::Cdouble, yc::Cdouble, width::Cdouble, height::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfSimChord, libcd_), Void, (Ptr{Void}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), ctxcanvas, xc, yc, width, height, angle1, angle2)
end
function cdfSimPoly(ctxcanvas::Ptr{Void}, mode::Integer, fpoly::Ptr{cdfPoint}, n::Integer)
  ccall( (:cdfSimPoly, libcd_), Void, (Ptr{Void}, Cint, Ptr{cdfPoint}, Cint), ctxcanvas, mode, fpoly, n)
end
function cdfSimPolyBezier(canvas::Ptr{Cint}, points::Ptr{cdfPoint}, n::Integer)
  ccall( (:cdfSimPolyBezier, libcd_), Void, (Ptr{Cint}, Ptr{cdfPoint}, Cint), canvas, points, n)
end
function cdfSimPolyPath(canvas::Ptr{Cint}, points::Ptr{cdfPoint}, n::Integer)
  ccall( (:cdfSimPolyPath, libcd_), Void, (Ptr{Cint}, Ptr{cdfPoint}, Cint), canvas, points, n)
end
function cdVersion()
  ccall( (:cdVersion, libcd_), Ptr{UInt8}, (), )
end
function cdVersionDate()
  ccall( (:cdVersionDate, libcd_), Ptr{UInt8}, (), )
end
function cdVersionNumber()
  ccall( (:cdVersionNumber, libcd_), Cint, (), )
end
function cdCreateCanvas(context::Ptr{cdContext}, data::Ptr{Void})
  ccall( (:cdCreateCanvas, libcd_), Ptr{cdCanvas}, (Ptr{cdContext}, Ptr{Void}), context, data)
end
function cdCreateCanvas(context::Ptr{cdContext}, data::Ptr{UInt8})
  ccall( (:cdCreateCanvas, libcd_), Ptr{cdCanvas}, (Ptr{cdContext}, Ptr{Void}), context, data)
end
function cdKillCanvas(canvas::Ptr{cdCanvas})
  ccall( (:cdKillCanvas, libcd_), Void, (Ptr{cdCanvas},), canvas)
end
function cdCanvasGetContext(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasGetContext, libcd_), Ptr{cdContext}, (Ptr{cdCanvas},), canvas)
end
function cdCanvasActivate(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasActivate, libcd_), Cint, (Ptr{cdCanvas},), canvas)
end
function cdCanvasDeactivate(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasDeactivate, libcd_), Void, (Ptr{cdCanvas},), canvas)
end
function cdUseContextPlus(use::Integer)
  ccall( (:cdUseContextPlus, libcd_), Cint, (Cint,), use)
end
function cdInitContextPlus()
  ccall( (:cdInitContextPlus, libcd_), Void, (), )
end
function cdFinishContextPlus()
  ccall( (:cdFinishContextPlus, libcd_), Void, (), )
end
function cdContextRegisterCallback(context::Ptr{cdContext}, cb::Integer, func::cdCallback)
  ccall( (:cdContextRegisterCallback, libcd_), Cint, (Ptr{cdContext}, Cint, cdCallback), context, cb, func)
end
function cdContextCaps(context::Ptr{cdContext})
  ccall( (:cdContextCaps, libcd_), Culong, (Ptr{cdContext},), context)
end
function cdContextIsPlus(context::Ptr{cdContext})
  ccall( (:cdContextIsPlus, libcd_), Cint, (Ptr{cdContext},), context)
end
function cdContextType(context::Ptr{cdContext})
  ccall( (:cdContextType, libcd_), Cint, (Ptr{cdContext},), context)
end
function cdCanvasSimulate(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasSimulate, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasFlush(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasFlush, libcd_), Void, (Ptr{cdCanvas},), canvas)
end
function cdCanvasClear(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasClear, libcd_), Void, (Ptr{cdCanvas},), canvas)
end
function cdCanvasSaveState(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasSaveState, libcd_), Ptr{cdCanvas}, (Ptr{cdCanvas},), canvas)
end
function cdCanvasRestoreState(canvas::Ptr{cdCanvas}, state::Ptr{cdCanvas})
  ccall( (:cdCanvasRestoreState, libcd_), Void, (Ptr{cdCanvas}, Ptr{cdCanvas}), canvas, state)
end
function cdReleaseState(state::Ptr{cdCanvas})
  ccall( (:cdReleaseState, libcd_), Void, (Ptr{cdCanvas},), state)
end
function cdCanvasSetAttribute(canvas::Ptr{cdCanvas}, name, data)
  ccall( (:cdCanvasSetAttribute, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Ptr{UInt8}), canvas, name, data)
end
function cdCanvasGetAttribute(canvas::Ptr{cdCanvas}, name::Ptr{UInt8})
  ccall( (:cdCanvasGetAttribute, libcd_), Ptr{UInt8}, (Ptr{cdCanvas}, Ptr{UInt8}), canvas, name)
end
function cdCanvasPlay(canvas::Ptr{cdCanvas}, context::Ptr{cdContext}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer, data::Ptr{Void})
  ccall( (:cdCanvasPlay, libcd_), Cint, (Ptr{cdCanvas}, Ptr{cdContext}, Cint, Cint, Cint, Cint, Ptr{Void}), canvas, context, xmin, xmax, ymin, ymax, data)
end
function cdCanvasGetSize(canvas::Ptr{cdCanvas}, width::Ptr{Cint}, height::Ptr{Cint}, width_mm::Ptr{Cdouble}=C_NULL, height_mm::Ptr{Cdouble}=C_NULL)
    ccall( (:cdCanvasGetSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}),
        canvas, width, height, width_mm, height_mm)
end
function cdCanvasGetSize(canvas::Ptr{cdCanvas}, width::Ptr{Cint}, height::Ptr{Cint}, width_mm::Ptr{Void}, height_mm::Ptr{Void})
    ccall( (:cdCanvasGetSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}),
        canvas, width, height, width_mm, height_mm)
end

function cdCanvasUpdateYAxis(canvas::Ptr{cdCanvas}, y::Ptr{Cint})
  ccall( (:cdCanvasUpdateYAxis, libcd_), Cint, (Ptr{cdCanvas}, Ptr{Cint}), canvas, y)
end
function cdfCanvasUpdateYAxis(canvas::Ptr{cdCanvas}, y::Ptr{Cdouble})
  ccall( (:cdfCanvasUpdateYAxis, libcd_), Cdouble, (Ptr{cdCanvas}, Ptr{Cdouble}), canvas, y)
end
function cdCanvasInvertYAxis(canvas::Ptr{cdCanvas}, y::Integer)
  ccall( (:cdCanvasInvertYAxis, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, y)
end
function cdfCanvasInvertYAxis(canvas::Ptr{cdCanvas}, y::Cdouble)
  ccall( (:cdfCanvasInvertYAxis, libcd_), Cdouble, (Ptr{cdCanvas}, Cdouble), canvas, y)
end
function cdCanvasMM2Pixel(canvas::Ptr{cdCanvas}, mm_dx::Cdouble, mm_dy::Cdouble, dx::Ptr{Cint}, dy::Ptr{Cint})
  ccall( (:cdCanvasMM2Pixel, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{Cint}, Ptr{Cint}), canvas, mm_dx, mm_dy, dx, dy)
end
function cdCanvasPixel2MM(canvas::Ptr{cdCanvas}, dx::Integer, dy::Integer, mm_dx::Ptr{Cdouble}, mm_dy::Ptr{Cdouble})
  ccall( (:cdCanvasPixel2MM, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}), canvas, dx, dy, mm_dx, mm_dy)
end
function cdfCanvasMM2Pixel(canvas::Ptr{cdCanvas}, mm_dx::Cdouble, mm_dy::Cdouble, dx::Ptr{Cdouble}, dy::Ptr{Cdouble})
  ccall( (:cdfCanvasMM2Pixel, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), canvas, mm_dx, mm_dy, dx, dy)
end
function cdfCanvasPixel2MM(canvas::Ptr{cdCanvas}, dx::Cdouble, dy::Cdouble, mm_dx::Ptr{Cdouble}, mm_dy::Ptr{Cdouble})
  ccall( (:cdfCanvasPixel2MM, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), canvas, dx, dy, mm_dx, mm_dy)
end
function cdCanvasOrigin(canvas::Ptr{cdCanvas}, x::Integer, y::Integer)
  ccall( (:cdCanvasOrigin, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint), canvas, x, y)
end
function cdfCanvasOrigin(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble)
  ccall( (:cdfCanvasOrigin, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble), canvas, x, y)
end
function cdCanvasGetOrigin(canvas::Ptr{cdCanvas}, x::Ptr{Cint}, y::Ptr{Cint})
  ccall( (:cdCanvasGetOrigin, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}), canvas, x, y)
end
function cdfCanvasGetOrigin(canvas::Ptr{cdCanvas}, x::Ptr{Cdouble}, y::Ptr{Cdouble})
  ccall( (:cdfCanvasGetOrigin, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cdouble}, Ptr{Cdouble}), canvas, x, y)
end
function cdCanvasTransform(canvas::Ptr{cdCanvas}, matrix::Ptr{Cdouble})
  ccall( (:cdCanvasTransform, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cdouble}), canvas, matrix)
end
function cdCanvasGetTransform(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasGetTransform, libcd_), Ptr{Cdouble}, (Ptr{cdCanvas},), canvas)
end
function cdCanvasTransformMultiply(canvas::Ptr{cdCanvas}, matrix::Ptr{Cdouble})
  ccall( (:cdCanvasTransformMultiply, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cdouble}), canvas, matrix)
end
function cdCanvasTransformRotate(canvas::Ptr{cdCanvas}, angle::Cdouble)
  ccall( (:cdCanvasTransformRotate, libcd_), Void, (Ptr{cdCanvas}, Cdouble), canvas, angle)
end
function cdCanvasTransformScale(canvas::Ptr{cdCanvas}, sx::Cdouble, sy::Cdouble)
  ccall( (:cdCanvasTransformScale, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble), canvas, sx, sy)
end
function cdCanvasTransformTranslate(canvas::Ptr{cdCanvas}, dx::Cdouble, dy::Cdouble)
  ccall( (:cdCanvasTransformTranslate, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble), canvas, dx, dy)
end
function cdCanvasTransformPoint(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, tx::Ptr{Cint}, ty::Ptr{Cint})
  ccall( (:cdCanvasTransformPoint, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cint}, Ptr{Cint}), canvas, x, y, tx, ty)
end
function cdfCanvasTransformPoint(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble, tx::Ptr{Cdouble}, ty::Ptr{Cdouble})
  ccall( (:cdfCanvasTransformPoint, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}), canvas, x, y, tx, ty)
end
function cdCanvasClip(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasClip, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasClipArea(canvas::Ptr{cdCanvas}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasClipArea, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint), canvas, xmin, xmax, ymin, ymax)
end
function cdCanvasGetClipArea(canvas::Ptr{cdCanvas}, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCanvasGetClipArea, libcd_), Cint, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, xmin, xmax, ymin, ymax)
end
function cdfCanvasClipArea(canvas::Ptr{cdCanvas}, xmin::Cdouble, xmax::Cdouble, ymin::Cdouble, ymax::Cdouble)
  ccall( (:cdfCanvasClipArea, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xmin, xmax, ymin, ymax)
end
function cdfCanvasGetClipArea(canvas::Ptr{cdCanvas}, xmin::Ptr{Cdouble}, xmax::Ptr{Cdouble}, ymin::Ptr{Cdouble}, ymax::Ptr{Cdouble})
  ccall( (:cdfCanvasGetClipArea, libcd_), Cint, (Ptr{cdCanvas}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), canvas, xmin, xmax, ymin, ymax)
end
function cdCanvasIsPointInRegion(canvas::Ptr{cdCanvas}, x::Integer, y::Integer)
  ccall( (:cdCanvasIsPointInRegion, libcd_), Cint, (Ptr{cdCanvas}, Cint, Cint), canvas, x, y)
end
function cdCanvasOffsetRegion(canvas::Ptr{cdCanvas}, x::Integer, y::Integer)
  ccall( (:cdCanvasOffsetRegion, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint), canvas, x, y)
end
function cdCanvasGetRegionBox(canvas::Ptr{cdCanvas}, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCanvasGetRegionBox, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, xmin, xmax, ymin, ymax)
end
function cdCanvasRegionCombineMode(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasRegionCombineMode, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasPixel(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, color::Clong)
  ccall( (:cdCanvasPixel, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Clong), canvas, x, y, color)
end
function cdCanvasMark(canvas::Ptr{cdCanvas}, x::Integer, y::Integer)
  ccall( (:cdCanvasMark, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint), canvas, x, y)
end
function cdCanvasBegin(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasBegin, libcd_), Void, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasPathSet(canvas::Ptr{cdCanvas}, action::Integer)
  ccall( (:cdCanvasPathSet, libcd_), Void, (Ptr{cdCanvas}, Cint), canvas, action)
end
function cdCanvasEnd(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasEnd, libcd_), Void, (Ptr{cdCanvas},), canvas)
end
function cdCanvasLine(canvas::Ptr{cdCanvas}, x1::Integer, y1::Integer, x2::Integer, y2::Integer)
  ccall( (:cdCanvasLine, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint), canvas, x1, y1, x2, y2)
end
function cdCanvasVertex(canvas::Ptr{cdCanvas}, x::Integer, y::Integer)
  ccall( (:cdCanvasVertex, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint), canvas, x, y)
end
function cdCanvasRect(canvas::Ptr{cdCanvas}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasRect, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint), canvas, xmin, xmax, ymin, ymax)
end
function cdCanvasBox(canvas::Ptr{cdCanvas}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasBox, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint), canvas, xmin, xmax, ymin, ymax)
end
function cdCanvasArc(canvas::Ptr{cdCanvas}, xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdCanvasArc, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdCanvasSector(canvas::Ptr{cdCanvas}, xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdCanvasSector, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdCanvasChord(canvas::Ptr{cdCanvas}, xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdCanvasChord, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdCanvasText(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8})
    ccall( (:cdCanvasText, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}), canvas, x, y, s)
end
function cdCanvasText(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::String)
    ccall( (:cdCanvasText, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}), canvas, x, y, s)
end
function cdfCanvasLine(canvas::Ptr{cdCanvas}, x1::Cdouble, y1::Cdouble, x2::Cdouble, y2::Cdouble)
  ccall( (:cdfCanvasLine, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble), canvas, x1, y1, x2, y2)
end
function cdfCanvasVertex(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble)
  ccall( (:cdfCanvasVertex, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble), canvas, x, y)
end
function cdfCanvasRect(canvas::Ptr{cdCanvas}, xmin::Cdouble, xmax::Cdouble, ymin::Cdouble, ymax::Cdouble)
  ccall( (:cdfCanvasRect, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xmin, xmax, ymin, ymax)
end
function cdfCanvasBox(canvas::Ptr{cdCanvas}, xmin::Cdouble, xmax::Cdouble, ymin::Cdouble, ymax::Cdouble)
  ccall( (:cdfCanvasBox, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xmin, xmax, ymin, ymax)
end
function cdfCanvasArc(canvas::Ptr{cdCanvas}, xc::Cdouble, yc::Cdouble, w::Cdouble, h::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfCanvasArc, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdfCanvasSector(canvas::Ptr{cdCanvas}, xc::Cdouble, yc::Cdouble, w::Cdouble, h::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfCanvasSector, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdfCanvasChord(canvas::Ptr{cdCanvas}, xc::Cdouble, yc::Cdouble, w::Cdouble, h::Cdouble, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdfCanvasChord, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), canvas, xc, yc, w, h, angle1, angle2)
end
function cdfCanvasText(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble, s::Ptr{UInt8})
  ccall( (:cdfCanvasText, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{UInt8}), canvas, x, y, s)
end
function cdCanvasSetBackground(canvas::Ptr{cdCanvas}, color::Integer)
  ccall( (:cdCanvasSetBackground, libcd_), Void, (Ptr{cdCanvas}, Clong), canvas, color)
end
function cdCanvasSetForeground(canvas::Ptr{cdCanvas}, color::Integer)
  ccall( (:cdCanvasSetForeground, libcd_), Void, (Ptr{cdCanvas}, Clong), canvas, color)
end
function cdCanvasBackground(canvas::Ptr{cdCanvas}, color::Integer)
  ccall( (:cdCanvasBackground, libcd_), Clong, (Ptr{cdCanvas}, Clong), canvas, color)
end
function cdCanvasForeground(canvas::Ptr{cdCanvas}, color::Integer)
  ccall( (:cdCanvasForeground, libcd_), Clong, (Ptr{cdCanvas}, Clong), canvas, color)
end
function cdCanvasBackOpacity(canvas::Ptr{cdCanvas}, opacity::Integer)
  ccall( (:cdCanvasBackOpacity, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, opacity)
end
function cdCanvasWriteMode(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasWriteMode, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasLineStyle(canvas::Ptr{cdCanvas}, style::Integer)
  ccall( (:cdCanvasLineStyle, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, style)
end
function cdCanvasLineStyleDashes(canvas::Ptr{cdCanvas}, dashes::Ptr{Cint}, count::Integer)
  ccall( (:cdCanvasLineStyleDashes, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Cint), canvas, dashes, count)
end
function cdCanvasLineWidth(canvas::Ptr{cdCanvas}, width::Integer)
  ccall( (:cdCanvasLineWidth, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, width)
end
function cdCanvasLineJoin(canvas::Ptr{cdCanvas}, join::Integer)
  ccall( (:cdCanvasLineJoin, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, join)
end
function cdCanvasLineCap(canvas::Ptr{cdCanvas}, cap::Integer)
  ccall( (:cdCanvasLineCap, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, cap)
end
function cdCanvasInteriorStyle(canvas::Ptr{cdCanvas}, style::Integer)
  ccall( (:cdCanvasInteriorStyle, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, style)
end
function cdCanvasHatch(canvas::Ptr{cdCanvas}, style::Integer)
  ccall( (:cdCanvasHatch, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, style)
end
function cdCanvasStipple(canvas::Ptr{cdCanvas}, w::Integer, h::Integer, stipple::Ptr{Cuchar})
  ccall( (:cdCanvasStipple, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cuchar}), canvas, w, h, stipple)
end
function cdCanvasGetStipple(canvas::Ptr{cdCanvas}, n::Ptr{Cint}, m::Ptr{Cint})
  ccall( (:cdCanvasGetStipple, libcd_), Ptr{Cuchar}, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}), canvas, n, m)
end
function cdCanvasPattern(canvas::Ptr{cdCanvas}, w::Integer, h::Integer, pattern::Ptr{Clong})
  ccall( (:cdCanvasPattern, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Clong}), canvas, w, h, pattern)
end
function cdCanvasGetPattern(canvas::Ptr{cdCanvas}, n::Ptr{Cint}, m::Ptr{Cint})
  ccall( (:cdCanvasGetPattern, libcd_), Ptr{Clong}, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}), canvas, n, m)
end
function cdCanvasFillMode(canvas::Ptr{cdCanvas}, mode::Integer)
  ccall( (:cdCanvasFillMode, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, mode)
end
function cdCanvasFont(canvas::Ptr{cdCanvas}, type_face::Ptr{UInt8}, style::Integer, size::Integer)
  ccall( (:cdCanvasFont, libcd_), Cint, (Ptr{cdCanvas}, Ptr{UInt8}, Cint, Cint), canvas, type_face, style, size)
end
function cdCanvasFont(canvas::Ptr{cdCanvas}, type_face::Ptr{Void}, style::Integer, size::Integer)
  ccall( (:cdCanvasFont, libcd_), Cint, (Ptr{cdCanvas}, Ptr{UInt8}, Cint, Cint), canvas, type_face, style, size)
end
function cdCanvasGetFont(canvas::Ptr{cdCanvas}, type_face::Ptr{UInt8}, style::Ptr{Cint}, size::Ptr{Cint})
  ccall( (:cdCanvasGetFont, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), canvas, type_face, style, size)
end
function cdCanvasNativeFont(canvas::Ptr{cdCanvas}, font::Ptr{UInt8})
  ccall( (:cdCanvasNativeFont, libcd_), Ptr{UInt8}, (Ptr{cdCanvas}, Ptr{UInt8}), canvas, font)
end
function cdCanvasTextAlignment(canvas::Ptr{cdCanvas}, alignment::Integer)
  ccall( (:cdCanvasTextAlignment, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, alignment)
end
function cdCanvasTextOrientation(canvas::Ptr{cdCanvas}, angle::Cdouble)
  ccall( (:cdCanvasTextOrientation, libcd_), Cdouble, (Ptr{cdCanvas}, Cdouble), canvas, angle)
end
function cdCanvasMarkType(canvas::Ptr{cdCanvas}, _type::Integer)
  ccall( (:cdCanvasMarkType, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, _type)
end
function cdCanvasMarkSize(canvas::Ptr{cdCanvas}, size::Integer)
  ccall( (:cdCanvasMarkSize, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, size)
end
function cdCanvasVectorText(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8})
  ccall( (:cdCanvasVectorText, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}), canvas, x, y, s)
end
function cdCanvasMultiLineVectorText(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8})
  ccall( (:cdCanvasMultiLineVectorText, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}), canvas, x, y, s)
end
function cdCanvasVectorFont(canvas::Ptr{cdCanvas}, filename::Ptr{UInt8})
  ccall( (:cdCanvasVectorFont, libcd_), Ptr{UInt8}, (Ptr{cdCanvas}, Ptr{UInt8}), canvas, filename)
end
function cdCanvasVectorTextDirection(canvas::Ptr{cdCanvas}, x1::Integer, y1::Integer, x2::Integer, y2::Integer)
  ccall( (:cdCanvasVectorTextDirection, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint), canvas, x1, y1, x2, y2)
end
function cdCanvasVectorTextTransform(canvas::Ptr{cdCanvas}, matrix::Ptr{Cdouble})
  ccall( (:cdCanvasVectorTextTransform, libcd_), Ptr{Cdouble}, (Ptr{cdCanvas}, Ptr{Cdouble}), canvas, matrix)
end
function cdCanvasVectorTextSize(canvas::Ptr{cdCanvas}, size_x::Integer, size_y::Integer, s::Ptr{UInt8})
  ccall( (:cdCanvasVectorTextSize, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}), canvas, size_x, size_y, s)
end
function cdCanvasVectorCharSize(canvas::Ptr{cdCanvas}, size::Integer)
  ccall( (:cdCanvasVectorCharSize, libcd_), Cint, (Ptr{cdCanvas}, Cint), canvas, size)
end
function cdCanvasVectorFontSize(canvas::Ptr{cdCanvas}, size_x::Cdouble, size_y::Cdouble)
  ccall( (:cdCanvasVectorFontSize, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble), canvas, size_x, size_y)
end
function cdCanvasGetVectorFontSize(canvas::Ptr{cdCanvas}, size_x::Ptr{Cdouble}, size_y::Ptr{Cdouble})
  ccall( (:cdCanvasGetVectorFontSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cdouble}, Ptr{Cdouble}), canvas, size_x, size_y)
end
function cdCanvasGetVectorTextSize(canvas::Ptr{cdCanvas}, s::Ptr{UInt8}, x::Ptr{Cint}, y::Ptr{Cint})
  ccall( (:cdCanvasGetVectorTextSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), canvas, s, x, y)
end
function cdCanvasGetVectorTextBounds(canvas::Ptr{cdCanvas}, s::Ptr{UInt8}, x::Integer, y::Integer, rect::Ptr{Cint})
  ccall( (:cdCanvasGetVectorTextBounds, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Cint, Cint, Ptr{Cint}), canvas, s, x, y, rect)
end
function cdCanvasGetVectorTextBox(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8}, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCanvasGetVectorTextBox, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, x, y, s, xmin, xmax, ymin, ymax)
end
function cdfCanvasVectorTextDirection(canvas::Ptr{cdCanvas}, x1::Cdouble, y1::Cdouble, x2::Cdouble, y2::Cdouble)
  ccall( (:cdfCanvasVectorTextDirection, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Cdouble, Cdouble), canvas, x1, y1, x2, y2)
end
function cdfCanvasVectorTextSize(canvas::Ptr{cdCanvas}, size_x::Cdouble, size_y::Cdouble, s::Ptr{UInt8})
  ccall( (:cdfCanvasVectorTextSize, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{UInt8}), canvas, size_x, size_y, s)
end
function cdfCanvasGetVectorTextSize(canvas::Ptr{cdCanvas}, s::Ptr{UInt8}, x::Ptr{Cdouble}, y::Ptr{Cdouble})
  ccall( (:cdfCanvasGetVectorTextSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Ptr{Cdouble}, Ptr{Cdouble}), canvas, s, x, y)
end
function cdfCanvasVectorCharSize(canvas::Ptr{cdCanvas}, size::Cdouble)
  ccall( (:cdfCanvasVectorCharSize, libcd_), Cdouble, (Ptr{cdCanvas}, Cdouble), canvas, size)
end
function cdfCanvasVectorText(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble, s::Ptr{UInt8})
  ccall( (:cdfCanvasVectorText, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{UInt8}), canvas, x, y, s)
end
function cdfCanvasMultiLineVectorText(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble, s::Ptr{UInt8})
  ccall( (:cdfCanvasMultiLineVectorText, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{UInt8}), canvas, x, y, s)
end
function cdfCanvasGetVectorTextBounds(canvas::Ptr{cdCanvas}, s::Ptr{UInt8}, x::Cdouble, y::Cdouble, rect::Ptr{Cdouble})
  ccall( (:cdfCanvasGetVectorTextBounds, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Cdouble, Cdouble, Ptr{Cdouble}), canvas, s, x, y, rect)
end
function cdfCanvasGetVectorTextBox(canvas::Ptr{cdCanvas}, x::Cdouble, y::Cdouble, s::Ptr{UInt8}, xmin::Ptr{Cdouble}, xmax::Ptr{Cdouble}, ymin::Ptr{Cdouble}, ymax::Ptr{Cdouble})
  ccall( (:cdfCanvasGetVectorTextBox, libcd_), Void, (Ptr{cdCanvas}, Cdouble, Cdouble, Ptr{UInt8}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), canvas, x, y, s, xmin, xmax, ymin, ymax)
end
function cdCanvasGetFontDim(canvas::Ptr{cdCanvas}, max_width::Ptr{Cint}, height::Ptr{Cint}, ascent::Ptr{Cint}, descent::Ptr{Cint})
  ccall( (:cdCanvasGetFontDim, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, max_width, height, ascent, descent)
end
function cdCanvasGetTextSize(canvas::Ptr{cdCanvas}, s::Ptr{UInt8}, width::Ptr{Cint}, height::Ptr{Cint})
  ccall( (:cdCanvasGetTextSize, libcd_), Void, (Ptr{cdCanvas}, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), canvas, s, width, height)
end
function cdCanvasGetTextBox(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8}, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdCanvasGetTextBox, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), canvas, x, y, s, xmin, xmax, ymin, ymax)
end
function cdCanvasGetTextBounds(canvas::Ptr{cdCanvas}, x::Integer, y::Integer, s::Ptr{UInt8}, rect::Ptr{Cint})
  ccall( (:cdCanvasGetTextBounds, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{UInt8}, Ptr{Cint}), canvas, x, y, s, rect)
end
function cdCanvasGetColorPlanes(canvas::Ptr{cdCanvas})
  ccall( (:cdCanvasGetColorPlanes, libcd_), Cint, (Ptr{cdCanvas},), canvas)
end
function cdCanvasPalette(canvas::Ptr{cdCanvas}, n::Integer, palette::Ptr{Clong}, mode::Integer)
  ccall( (:cdCanvasPalette, libcd_), Void, (Ptr{cdCanvas}, Cint, Ptr{Clong}, Cint), canvas, n, palette, mode)
end
function cdCanvasGetImageRGB(canvas::Ptr{cdCanvas}, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer)
  ccall( (:cdCanvasGetImageRGB, libcd_), Void, (Ptr{cdCanvas}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint), canvas, r, g, b, x, y, w, h)
end
function cdCanvasPutImageRectRGB(canvas::Ptr{cdCanvas}, iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasPutImageRectRGB, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), canvas, iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdCanvasPutImageRectRGBA(canvas::Ptr{cdCanvas}, iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, a::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasPutImageRectRGBA, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), canvas, iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdCanvasPutImageRectMap(canvas::Ptr{cdCanvas}, iw::Integer, ih::Integer, index::Ptr{Cuchar}, colors::Ptr{Clong}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasPutImageRectMap, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Ptr{Cuchar}, Ptr{Clong}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), canvas, iw, ih, index, colors, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdCanvasCreateImage(canvas::Ptr{cdCanvas}, w::Integer, h::Integer)
  ccall( (:cdCanvasCreateImage, libcd_), Ptr{cdImage}, (Ptr{cdCanvas}, Cint, Cint), canvas, w, h)
end
function cdKillImage(image::Ptr{cdImage})
  ccall( (:cdKillImage, libcd_), Void, (Ptr{cdImage},), image)
end
function cdCanvasGetImage(canvas::Ptr{cdCanvas}, image::Ptr{cdImage}, x::Integer, y::Integer)
  ccall( (:cdCanvasGetImage, libcd_), Void, (Ptr{cdCanvas}, Ptr{cdImage}, Cint, Cint), canvas, image, x, y)
end
function cdCanvasPutImageRect(canvas::Ptr{cdCanvas}, image::Ptr{cdImage}, x::Integer, y::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdCanvasPutImageRect, libcd_), Void, (Ptr{cdCanvas}, Ptr{cdImage}, Cint, Cint, Cint, Cint, Cint, Cint), canvas, image, x, y, xmin, xmax, ymin, ymax)
end
function cdCanvasScrollArea(canvas::Ptr{cdCanvas}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer, dx::Integer, dy::Integer)
  ccall( (:cdCanvasScrollArea, libcd_), Void, (Ptr{cdCanvas}, Cint, Cint, Cint, Cint, Cint, Cint), canvas, xmin, xmax, ymin, ymax, dx, dy)
end
function cdCreateBitmap(w::Integer, h::Integer, _type::Integer)
  ccall( (:cdCreateBitmap, libcd_), Ptr{cdBitmap}, (Cint, Cint, Cint), w, h, _type)
end
function cdKillBitmap(bitmap::Ptr{cdBitmap})
  ccall( (:cdKillBitmap, libcd_), Void, (Ptr{cdBitmap},), bitmap)
end
function cdBitmapGetData(bitmap::Ptr{cdBitmap}, dataptr::Integer)
  ccall( (:cdBitmapGetData, libcd_), Ptr{Cuchar}, (Ptr{cdBitmap}, Cint), bitmap, dataptr)
end
function cdBitmapSetRect(bitmap::Ptr{cdBitmap}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdBitmapSetRect, libcd_), Void, (Ptr{cdBitmap}, Cint, Cint, Cint, Cint), bitmap, xmin, xmax, ymin, ymax)
end
function cdCanvasPutBitmap(canvas::Ptr{cdCanvas}, bitmap::Ptr{cdBitmap}, x::Integer, y::Integer, w::Integer, h::Integer)
  ccall( (:cdCanvasPutBitmap, libcd_), Void, (Ptr{cdCanvas}, Ptr{cdBitmap}, Cint, Cint, Cint, Cint), canvas, bitmap, x, y, w, h)
end
function cdCanvasGetBitmap(canvas::Ptr{cdCanvas}, bitmap::Ptr{cdBitmap}, x::Integer, y::Integer)
  ccall( (:cdCanvasGetBitmap, libcd_), Void, (Ptr{cdCanvas}, Ptr{cdBitmap}, Cint, Cint), canvas, bitmap, x, y)
end
function cdBitmapRGB2Map(bitmap_rgb::Ptr{cdBitmap}, bitmap_map::Ptr{cdBitmap})
  ccall( (:cdBitmapRGB2Map, libcd_), Void, (Ptr{cdBitmap}, Ptr{cdBitmap}), bitmap_rgb, bitmap_map)
end
function cdEncodeColor(red::Cuchar, green::Cuchar, blue::Cuchar)
  ccall( (:cdEncodeColor, libcd_), Clong, (Cuchar, Cuchar, Cuchar), red, green, blue)
end
function cdDecodeColor(color::Integer, red::Ptr{Cuchar}, green::Ptr{Cuchar}, blue::Ptr{Cuchar})
  ccall( (:cdDecodeColor, libcd_), Void, (Clong, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}), color, red, green, blue)
end
function cdDecodeAlpha(color::Integer)
  ccall( (:cdDecodeAlpha, libcd_), Cuchar, (Clong,), color)
end
function cdEncodeAlpha(color::Integer, alpha::Char)
  ccall( (:cdEncodeAlpha, libcd_), Clong, (Clong, Cuchar), color, alpha)
end
function cdRGB2Map(width::Integer, height::Integer, red::Ptr{Cuchar}, green::Ptr{Cuchar}, blue::Ptr{Cuchar}, index::Ptr{Cuchar}, pal_size::Integer, color::Ptr{Clong})
  ccall( (:cdRGB2Map, libcd_), Void, (Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Ptr{Clong}), width, height, red, green, blue, index, pal_size, color)
end
function cdActivate(canvas::Ptr{cdCanvas})
  ccall( (:cdActivate, libcd_), Cint, (Ptr{cdCanvas},), canvas)
end
function cdActiveCanvas()
  ccall( (:cdActiveCanvas, libcd_), Ptr{cdCanvas}, (), )
end
function cdSimulate(mode::Integer)
  ccall( (:cdSimulate, libcd_), Cint, (Cint,), mode)
end
function cdFlush()
  ccall( (:cdFlush, libcd_), Void, (), )
end
function cdClear()
  ccall( (:cdClear, libcd_), Void, (), )
end
function cdSaveState()
  ccall( (:cdSaveState, libcd_), Ptr{cdCanvas}, (), )
end
function cdRestoreState(state::Ptr{cdCanvas})
  ccall( (:cdRestoreState, libcd_), Void, (Ptr{cdCanvas},), state)
end
function cdSetAttribute(name::Ptr{UInt8}, data::Ptr{UInt8})
  ccall( (:cdSetAttribute, libcd_), Void, (Ptr{UInt8}, Ptr{UInt8}), name, data)
end
function cdGetAttribute(name::Ptr{UInt8})
  ccall( (:cdGetAttribute, libcd_), Ptr{UInt8}, (Ptr{UInt8},), name)
end
function cdGetContext(canvas::Ptr{cdCanvas})
  ccall( (:cdGetContext, libcd_), Ptr{cdContext}, (Ptr{cdCanvas},), canvas)
end
function cdRegisterCallback(context::Ptr{cdContext}, cb::Integer, func::cdCallback)
  ccall( (:cdRegisterCallback, libcd_), Cint, (Ptr{cdContext}, Cint, cdCallback), context, cb, func)
end
function cdPlay(context::Ptr{cdContext}, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer, data::Ptr{Void})
  ccall( (:cdPlay, libcd_), Cint, (Ptr{cdContext}, Cint, Cint, Cint, Cint, Ptr{Void}), context, xmin, xmax, ymin, ymax, data)
end
function cdGetCanvasSize(width::Ptr{Cint}, height::Ptr{Cint}, width_mm::Ptr{Cdouble}=C_NULL, height_mm::Ptr{Cdouble}=C_NULL)
  ccall( (:cdGetCanvasSize, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}), width, height, width_mm, height_mm)
end
function cdGetCanvasSize(width::Ptr{Cint}, height::Ptr{Cint}, width_mm::Ptr{Void}, height_mm::Ptr{Void})
  ccall( (:cdGetCanvasSize, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cdouble}, Ptr{Cdouble}), width, height, width_mm, height_mm)
end
function cdUpdateYAxis(y::Ptr{Cint})
  ccall( (:cdUpdateYAxis, libcd_), Cint, (Ptr{Cint},), y)
end
function cdMM2Pixel(mm_dx::Cdouble, mm_dy::Cdouble, dx::Ptr{Cint}, dy::Ptr{Cint})
  ccall( (:cdMM2Pixel, libcd_), Void, (Cdouble, Cdouble, Ptr{Cint}, Ptr{Cint}), mm_dx, mm_dy, dx, dy)
end
function cdPixel2MM(dx::Integer, dy::Integer, mm_dx::Ptr{Cdouble}, mm_dy::Ptr{Cdouble})
  ccall( (:cdPixel2MM, libcd_), Void, (Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}), dx, dy, mm_dx, mm_dy)
end
function cdOrigin(x::Integer, y::Integer)
  ccall( (:cdOrigin, libcd_), Void, (Cint, Cint), x, y)
end
function cdClip(mode::Integer)
  ccall( (:cdClip, libcd_), Cint, (Cint,), mode)
end
function cdGetClipPoly(n::Ptr{Cint})
  ccall( (:cdGetClipPoly, libcd_), Ptr{Cint}, (Ptr{Cint},), n)
end
function cdClipArea(xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdClipArea, libcd_), Void, (Cint, Cint, Cint, Cint), xmin, xmax, ymin, ymax)
end
function cdGetClipArea(xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdGetClipArea, libcd_), Cint, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), xmin, xmax, ymin, ymax)
end
function cdPointInRegion(x::Integer, y::Integer)
  ccall( (:cdPointInRegion, libcd_), Cint, (Cint, Cint), x, y)
end
function cdOffsetRegion(x::Integer, y::Integer)
  ccall( (:cdOffsetRegion, libcd_), Void, (Cint, Cint), x, y)
end
function cdRegionBox(xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdRegionBox, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), xmin, xmax, ymin, ymax)
end
function cdRegionCombineMode(mode::Integer)
  ccall( (:cdRegionCombineMode, libcd_), Cint, (Cint,), mode)
end
function cdPixel(x::Integer, y::Integer, color::Clong)
  ccall( (:cdPixel, libcd_), Void, (Cint, Cint, Clong), x, y, color)
end
function cdMark(x::Integer, y::Integer)
  ccall( (:cdMark, libcd_), Void, (Cint, Cint), x, y)
end
function cdLine(x1::Integer, y1::Integer, x2::Integer, y2::Integer)
  ccall( (:cdLine, libcd_), Void, (Cint, Cint, Cint, Cint), x1, y1, x2, y2)
end
function cdBegin(mode::Integer)
  ccall( (:cdBegin, libcd_), Void, (Cint,), mode)
end
function cdVertex(x::Integer, y::Integer)
  ccall( (:cdVertex, libcd_), Void, (Cint, Cint), x, y)
end
function cdEnd()
  ccall( (:cdEnd, libcd_), Void, (), )
end
function cdBox(xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdBox, libcd_), Void, (Cint, Cint, Cint, Cint), xmin, xmax, ymin, ymax)
end
function cdArc(xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdArc, libcd_), Void, (Cint, Cint, Cint, Cint, Cdouble, Cdouble), xc, yc, w, h, angle1, angle2)
end
function cdSector(xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdSector, libcd_), Void, (Cint, Cint, Cint, Cint, Cdouble, Cdouble), xc, yc, w, h, angle1, angle2)
end
function cdChord(xc::Integer, yc::Integer, w::Integer, h::Integer, angle1::Cdouble, angle2::Cdouble)
  ccall( (:cdChord, libcd_), Void, (Cint, Cint, Cint, Cint, Cdouble, Cdouble), xc, yc, w, h, angle1, angle2)
end
function cdText(x::Integer, y::Integer, s::Ptr{UInt8})
  ccall( (:cdText, libcd_), Void, (Cint, Cint, Ptr{UInt8}), x, y, s)
end
function cdBackground(color::Clong)
  ccall( (:cdBackground, libcd_), Clong, (Clong,), color)
end
function cdForeground(color::Clong)
  ccall( (:cdForeground, libcd_), Clong, (Clong,), color)
end
function cdBackOpacity(opacity::Integer)
  ccall( (:cdBackOpacity, libcd_), Cint, (Cint,), opacity)
end
function cdWriteMode(mode::Integer)
  ccall( (:cdWriteMode, libcd_), Cint, (Cint,), mode)
end
function cdLineStyle(style::Integer)
  ccall( (:cdLineStyle, libcd_), Cint, (Cint,), style)
end
function cdLineStyleDashes(dashes::Ptr{Cint}, count::Integer)
  ccall( (:cdLineStyleDashes, libcd_), Void, (Ptr{Cint}, Cint), dashes, count)
end
function cdLineWidth(width::Integer)
  ccall( (:cdLineWidth, libcd_), Cint, (Cint,), width)
end
function cdLineJoin(join::Integer)
  ccall( (:cdLineJoin, libcd_), Cint, (Cint,), join)
end
function cdLineCap(cap::Integer)
  ccall( (:cdLineCap, libcd_), Cint, (Cint,), cap)
end
function cdInteriorStyle(style::Integer)
  ccall( (:cdInteriorStyle, libcd_), Cint, (Cint,), style)
end
function cdHatch(style::Integer)
  ccall( (:cdHatch, libcd_), Cint, (Cint,), style)
end
function cdStipple(w::Integer, h::Integer, stipple::Ptr{Cuchar})
  ccall( (:cdStipple, libcd_), Void, (Cint, Cint, Ptr{Cuchar}), w, h, stipple)
end
function cdGetStipple(n::Ptr{Cint}, m::Ptr{Cint})
  ccall( (:cdGetStipple, libcd_), Ptr{Cuchar}, (Ptr{Cint}, Ptr{Cint}), n, m)
end
function cdPattern(w::Integer, h::Integer, pattern::Ptr{Clong})
  ccall( (:cdPattern, libcd_), Void, (Cint, Cint, Ptr{Clong}), w, h, pattern)
end
function cdGetPattern(n::Ptr{Cint}, m::Ptr{Cint})
  ccall( (:cdGetPattern, libcd_), Ptr{Clong}, (Ptr{Cint}, Ptr{Cint}), n, m)
end
function cdFillMode(mode::Integer)
  ccall( (:cdFillMode, libcd_), Cint, (Cint,), mode)
end
function cdFont(type_face::Integer, style::Integer, size::Integer)
  ccall( (:cdFont, libcd_), Void, (Cint, Cint, Cint), type_face, style, size)
end
function cdGetFont(type_face::Ptr{Cint}, style::Ptr{Cint}, size::Ptr{Cint})
  ccall( (:cdGetFont, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), type_face, style, size)
end
function cdNativeFont(font::Ptr{UInt8})
  ccall( (:cdNativeFont, libcd_), Ptr{UInt8}, (Ptr{UInt8},), font)
end
function cdTextAlignment(alignment::Integer)
  ccall( (:cdTextAlignment, libcd_), Cint, (Cint,), alignment)
end
function cdTextOrientation(angle::Cdouble)
  ccall( (:cdTextOrientation, libcd_), Cdouble, (Cdouble,), angle)
end
function cdMarkType(_type::Integer)
  ccall( (:cdMarkType, libcd_), Cint, (Cint,), _type)
end
function cdMarkSize(size::Integer)
  ccall( (:cdMarkSize, libcd_), Cint, (Cint,), size)
end
function cdVectorText(x::Integer, y::Integer, s::Ptr{UInt8})
  ccall( (:cdVectorText, libcd_), Void, (Cint, Cint, Ptr{UInt8}), x, y, s)
end
function cdMultiLineVectorText(x::Integer, y::Integer, s::Ptr{UInt8})
  ccall( (:cdMultiLineVectorText, libcd_), Void, (Cint, Cint, Ptr{UInt8}), x, y, s)
end
function cdVectorTextDirection(x1::Integer, y1::Integer, x2::Integer, y2::Integer)
  ccall( (:cdVectorTextDirection, libcd_), Void, (Cint, Cint, Cint, Cint), x1, y1, x2, y2)
end
function cdVectorTextTransform(matrix::Ptr{Cdouble})
  ccall( (:cdVectorTextTransform, libcd_), Ptr{Cdouble}, (Ptr{Cdouble},), matrix)
end
function cdVectorTextSize(size_x::Integer, size_y::Integer, s::Ptr{UInt8})
  ccall( (:cdVectorTextSize, libcd_), Void, (Cint, Cint, Ptr{UInt8}), size_x, size_y, s)
end
function cdVectorCharSize(size::Integer)
  ccall( (:cdVectorCharSize, libcd_), Cint, (Cint,), size)
end
function cdGetVectorTextSize(s::Ptr{UInt8}, x::Ptr{Cint}, y::Ptr{Cint})
  ccall( (:cdGetVectorTextSize, libcd_), Void, (Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), s, x, y)
end
function cdGetVectorTextBounds(s::Ptr{UInt8}, x::Integer, y::Integer, rect::Ptr{Cint})
  ccall( (:cdGetVectorTextBounds, libcd_), Void, (Ptr{UInt8}, Cint, Cint, Ptr{Cint}), s, x, y, rect)
end
function cdFontDim(max_width::Ptr{Cint}, height::Ptr{Cint}, ascent::Ptr{Cint}, descent::Ptr{Cint})
  ccall( (:cdFontDim, libcd_), Void, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), max_width, height, ascent, descent)
end
function cdTextSize(s::Ptr{UInt8}, width::Ptr{Cint}, height::Ptr{Cint})
  ccall( (:cdTextSize, libcd_), Void, (Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}), s, width, height)
end
function cdTextBox(x::Integer, y::Integer, s::Ptr{UInt8}, xmin::Ptr{Cint}, xmax::Ptr{Cint}, ymin::Ptr{Cint}, ymax::Ptr{Cint})
  ccall( (:cdTextBox, libcd_), Void, (Cint, Cint, Ptr{UInt8}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), x, y, s, xmin, xmax, ymin, ymax)
end
function cdTextBounds(x::Integer, y::Integer, s::Ptr{UInt8}, rect::Ptr{Cint})
  ccall( (:cdTextBounds, libcd_), Void, (Cint, Cint, Ptr{UInt8}, Ptr{Cint}), x, y, s, rect)
end
function cdGetColorPlanes()
  ccall( (:cdGetColorPlanes, libcd_), Cint, (), )
end
function cdPalette(n::Integer, palette::Ptr{Clong}, mode::Integer)
  ccall( (:cdPalette, libcd_), Void, (Cint, Ptr{Clong}, Cint), n, palette, mode)
end
function cdGetImageRGB(r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer)
  ccall( (:cdGetImageRGB, libcd_), Void, (Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint), r, g, b, x, y, w, h)
end
function cdPutImageRectRGB(iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdPutImageRectRGB, libcd_), Void, (Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), iw, ih, r, g, b, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdPutImageRectRGBA(iw::Integer, ih::Integer, r::Ptr{Cuchar}, g::Ptr{Cuchar}, b::Ptr{Cuchar}, a::Ptr{Cuchar}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdPutImageRectRGBA, libcd_), Void, (Cint, Cint, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Ptr{Cuchar}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), iw, ih, r, g, b, a, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdPutImageRectMap(iw::Integer, ih::Integer, index::Ptr{Cuchar}, colors::Ptr{Clong}, x::Integer, y::Integer, w::Integer, h::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdPutImageRectMap, libcd_), Void, (Cint, Cint, Ptr{Cuchar}, Ptr{Clong}, Cint, Cint, Cint, Cint, Cint, Cint, Cint, Cint), iw, ih, index, colors, x, y, w, h, xmin, xmax, ymin, ymax)
end
function cdCreateImage(w::Integer, h::Integer)
  ccall( (:cdCreateImage, libcd_), Ptr{cdImage}, (Cint, Cint), w, h)
end
function cdGetImage(image::Ptr{cdImage}, x::Integer, y::Integer)
  ccall( (:cdGetImage, libcd_), Void, (Ptr{cdImage}, Cint, Cint), image, x, y)
end
function cdPutImageRect(image::Ptr{cdImage}, x::Integer, y::Integer, xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer)
  ccall( (:cdPutImageRect, libcd_), Void, (Ptr{cdImage}, Cint, Cint, Cint, Cint, Cint, Cint), image, x, y, xmin, xmax, ymin, ymax)
end
function cdScrollArea(xmin::Integer, xmax::Integer, ymin::Integer, ymax::Integer, dx::Integer, dy::Integer)
  ccall( (:cdScrollArea, libcd_), Void, (Cint, Cint, Cint, Cint, Cint, Cint), xmin, xmax, ymin, ymax, dx, dy)
end
function cdPutBitmap(bitmap::Ptr{cdBitmap}, x::Integer, y::Integer, w::Integer, h::Integer)
  ccall( (:cdPutBitmap, libcd_), Void, (Ptr{cdBitmap}, Cint, Cint, Cint, Cint), bitmap, x, y, w, h)
end
function cdGetBitmap(bitmap::Ptr{cdBitmap}, x::Integer, y::Integer)
  ccall( (:cdGetBitmap, libcd_), Void, (Ptr{cdBitmap}, Cint, Cint), bitmap, x, y)
end

function cdContextDBuffer()
    ccall( (:cdContextDBuffer, libcd_), Ptr{cdContext}, (),)
end

function cdContextNativeWindow()
    ccall( (:cdContextNativeWindow, libcd_), Ptr{cdContext}, (),)
end

ext: jl


text:
# This file includes one dimensional interpolation.

using FractalTools
using Plots
plotly()

# Generate interpolation data
xi, dx, xf = 0, 0.1, 1
x = collect(xi : dx : xf)
y = sin.(2π * x .+ π/6)
z = cos.(2π * x)
u = 0.2
d = u * ones(length(x) - 1)
h = u * ones(length(x) - 1)
l = u * ones(length(x) - 1)
m = u * ones(length(x) - 1)

# Construct interpolant
# ifs = gethiddenifs(x, y, z, d, h, l, m)
interp = hiddenfif(x, y, z, d, h, l, m, niter=40)

# Plot data
xd = collect(xi : 0.01dx : xf)
yd = interp.(xd)

plt = plot(layout=(2,1))
plot!(xd, getindex.(yd, 1), label="original", subplot=1)
scatter!(x, y, marker=(:circle, 3), subplot=1)
plot!(xd, getindex.(yd, 2), label="hidden", subplot=2)
scatter!(x, z, marker=(:circle, 3), subplot=2)


text:
using Test

include("l0.jl")


text:
import Registrator.CommentBot: parse_comment

using Test

@testset "Server" begin

@testset "parse_comment" begin
    @test parse_comment("register()") == ("register", Dict{Symbol,String}())
    @test parse_comment("approved()") == ("approved", Dict{Symbol,String}())

    @test parse_comment("register(target=qux)") == ("register", Dict(:target=>"qux"))
    @test parse_comment("register(target=qux, branch=baz)") == ("register", Dict(:branch=>"baz",:target=>"qux"))
    @test parse_comment("register(target=foo, branch=bar)") == ("register", Dict(:branch=>"bar",:target=>"foo"))

    @test parse_comment("register(branch=\"release-1.0\")") == ("register", Dict(:branch=>"release-1.0"))

    @test parse_comment("register") == ("register", Dict{Symbol, String}())
    @test parse_comment("register branch=foo target=bar") == ("register", Dict(:branch => "foo", :target => "bar"))
    @test parse_comment("register branch = foo target = bar") == ("register", Dict(:branch => "foo", :target => "bar"))
    @test parse_comment("register branch=foo, target=bar") == ("register", Dict(:branch => "foo", :target => "bar"))

    @test parse_comment("register(branch=foo)\nfoobar\"") == ("register", Dict(:branch => "foo"))

    @test parse_comment("register branch=foo branch=bar") == (nothing, nothing)
end

end


text:
"""
Transient Markov
"""

function tprob(ts::Tt, Q::AbstractMatrix{Tv}, x0::Vector{Tv}; ufact=1.01, eps=1.0e-8, rmax=500) where {Tv,Tt<:Number}
    _tprob(ts, x0, Q, ufact, eps, rmax)
end

function tprob(ts::Tt, m::CTMCModel{Tv}; states = nothing, ufact=1.01, eps=1.0e-8, rmax=500) where {Tv,Tt<:Number}
    if states == nothing
        _tprob(ts, m.initv, m.Q, ufact, eps, rmax)
    else
        s = _getstates(m.states, states)
        _tprob(ts, m.initv, m.Q, ufact, eps, rmax)[s]
    end
end

function _tprob(ts::Tt, x0::Vector{Tv}, Q::AbstractMatrix{Tv}, ufact, eps, rmax)::Vector{Tv} where {Tv<:Number,Tt<:Number}
    mexp(Q, x0, ts, transpose=:T, ufact=ufact, eps=eps, rmax=rmax)
end

"""
ctprob
"""

function ctprob(ts::Tt, Q::AbstractMatrix{Tv}, x0::Vector{Tv}; ufact=1.01, eps=1.0e-8, rmax=500) where {Tv,Tt<:Number}
    _ctprob(ts, x0, Q, ufact, eps, rmax)
end

function ctprob(ts::Tt, m::CTMCModel{Tv}; states = nothing, ufact=1.01, eps=1.0e-8, rmax=500) where {Tv,Tt<:Number}
    if states == nothing
        _ctprob(ts, m.initv, m.Q, ufact, eps, rmax)
    else
        s = _getstates(m.states, states)
        _ctprob(ts, m.initv, m.Q, ufact, eps, rmax)[s]
    end
end

function _ctprob(ts::Tt, x0::Vector{Tv}, Q::AbstractMatrix{Tv}, ufact, eps, rmax)::Vector{Tv} where {Tv<:Number,Tt<:Number}
    mexpc(Q, x0, ts, transpose=:T, ufact=ufact, eps=eps, rmax=rmax)[2]
end

"""
symbolic
"""

mutable struct SymbolicCTMCExpAvExpression{Tv} <: AbstractVectorSymbolic{Tv}
    params::Set{Symbol}
    op::Symbol
    x0::AbstractVectorSymbolic{Tv}
    Q::AbstractMatrixSymbolic{Tv}
    ts
    options::Dict{Symbol,Any}
    dim::Int
end

function _toexpr(x::SymbolicCTMCExpAvExpression)
    Expr(:call, x.op, _toexpr(x.x0), _toexpr(x.Q))
end

function Base.show(io::IO, x::SymbolicCTMCExpAvExpression{Tv}) where Tv
    Base.show(io, "SymbolicCTMCExpAvExpression $(objectid(x))")
end

###

function tprob(ts::Tt, Q::AbstractMatrixSymbolic{Tv}, x0::AbstractVectorSymbolic{Tv}; ufact=1.01, eps=1.0e-8, rmax=500) where {Tv<:Number,Tt<:Number}
    _tprob(ts, x0, Q, ufact, eps, rmax)
end

function ctprob(ts::Tt, Q::AbstractMatrixSymbolic{Tv}, x0::AbstractVectorSymbolic{Tv}; ufact=1.01, eps=1.0e-8, rmax=500) where {Tv<:Number,Tt<:Number}
    _ctprob(ts, x0, Q, ufact, eps, rmax)
end

function _tprob(ts::Tt, x0::Vector{<:AbstractSymbolic{Tv}}, Q::AbstractMatrix{<:AbstractSymbolic{Tv}}, ufact, eps, rmax) where {Tv<:Number,Tt<:Number}
    _tprob(ts, convert(AbstractVectorSymbolic{Tv}, x0), convert(AbstractMatrixSymbolic{Tv}, Q), ufact, eps, rmax)
end

function _tprob(ts::Tt, x0::AbstractVectorSymbolic{Tv}, Q::AbstractMatrixSymbolic{Tv}, ufact, eps, rmax) where {Tv<:Number,Tt<:Number}
    s = union(x0.params, Q.params)
    SymbolicCTMCExpAvExpression{Tv}(s, :tprob, x0, Q, ts, Dict(:ufact=>ufact, :eps=>eps, :rmax=>rmax), Q.dim[1])
end

function _ctprob(ts::Tt, x0::Vector{<:AbstractSymbolic{Tv}}, Q::AbstractMatrix{<:AbstractSymbolic{Tv}}, ufact, eps, rmax) where {Tv<:Number,Tt<:Number}
    _ctprob(ts, convert(AbstractVectorSymbolic{Tv}, x0), convert(AbstractMatrixSymbolic{Tv}, Q), ufact, eps, rmax)
end

function _ctprob(ts::Tt, x0::AbstractVectorSymbolic{Tv}, Q::AbstractMatrixSymbolic{Tv}, ufact, eps, rmax) where {Tv<:Number,Tt<:Number}
    s = union(x0.params, Q.params)
    SymbolicCTMCExpAvExpression{Tv}(s, :ctprob, x0, Q, ts, Dict(:ufact=>ufact, :eps=>eps, :rmax=>rmax), Q.dim[1])
end

"""
seval
"""

function _eval(::Val{:tprob}, f::SymbolicCTMCExpAvExpression{Tv}, env::SymbolicEnv, cache::SymbolicCache)::Vector{Tv} where {Tv<:Number}
    x0 = seval(f.x0, env, cache)
    Q = seval(f.Q, env, cache)
    _tprob(f.ts, x0, Q, f.options[:ufact], f.options[:eps], f.options[:rmax])
end

function _eval(::Val{:tprob}, f::SymbolicCTMCExpAvExpression{Tv}, dvar::Symbol, env::SymbolicEnv, cache::SymbolicCache) where {Tv<:Number}
    Q = seval(f.Q, env, cache)
    dQ = seval(f.Q, dvar, env, cache)
    x = seval(f.x0, env, cache)
    dx = seval(f.x0, dvar, env, cache)
    ts = f.ts

    n = length(x)

    QQ = SparseCSC(BlockCOO(2, 2, [(1,1,Q), (1,2,dQ), (2,2,Q)]))
    xx = [x..., dx...]
    ret = n+1:2n
    mexp(QQ, xx, ts, transpose=:T, ufact=f.options[:ufact], eps=f.options[:eps], rmax=f.options[:rmax])[ret]
end

function _eval(::Val{:tprob}, f::SymbolicCTMCExpAvExpression{Tv}, dvar::Tuple{Symbol,Symbol}, env::SymbolicEnv, cache::SymbolicCache) where {Tv<:Number}
     Q = seval(f.Q, env, cache)
    x = seval(f.x0, env, cache)

    dQ_a = seval(f.Q, dvar[1], env, cache)
    dx_a = seval(f.x0, dvar[1], env, cache)

    dQ_b = seval(f.Q, dvar[2], env, cache)
    dx_b = seval(f.x0, dvar[2], env, cache)

    dQ_ab = seval(f.Q, dvar, env, cache)
    dx_ab = seval(f.x0, dvar, env, cache)

    ts = f.ts

    n = length(x)
    QQ = SparseCSC(BlockCOO(4, 4, [(1,1,Q), (2,2,Q), (3,3,Q), (4,4,Q), (1,2,dQ_a), (1,3,dQ_b), (1,4,dQ_ab), (2,4,dQ_b), (3,4,dQ_a)]))
    xx = [x..., dx_a..., dx_b..., dx_ab...]
    ret = 3n+1:4n
    mexp(QQ, xx, ts, transpose=:T, ufact=f.options[:ufact], eps=f.options[:eps], rmax=f.options[:rmax])[ret]
end

###

function _eval(::Val{:ctprob}, f::SymbolicCTMCExpAvExpression{Tv}, env::SymbolicEnv, cache::SymbolicCache)::Vector{Tv} where {Tv<:Number}
    x0 = seval(f.x0, env, cache)
    Q = seval(f.Q, env, cache)
    _ctprob(f.ts, x0, Q, f.options[:ufact], f.options[:eps], f.options[:rmax])
end

function _eval(::Val{:ctprob}, f::SymbolicCTMCExpAvExpression{Tv}, dvar::Symbol, env::SymbolicEnv, cache::SymbolicCache) where {Tv<:Number}
    Q = seval(f.Q, env, cache)
    dQ = seval(f.Q, dvar, env, cache)
    x = seval(f.x0, env, cache)
    dx = seval(f.x0, dvar, env, cache)
    ts = f.ts

    n = length(x)

    QQ = SparseCSC(BlockCOO(2, 2, [(1,1,Q), (1,2,dQ), (2,2,Q)]))
    xx = [x..., dx...]
    ret = n+1:2n
    mexpc(QQ, xx, ts, transpose=:T, ufact=f.options[:ufact], eps=f.options[:eps], rmax=f.options[:rmax])[2][ret]
end

function _eval(::Val{:ctprob}, f::SymbolicCTMCExpAvExpression{Tv}, dvar::Tuple{Symbol,Symbol}, env::SymbolicEnv, cache::SymbolicCache) where {Tv<:Number}
    Q = seval(f.Q, env, cache)
    x = seval(f.x0, env, cache)

    dQ_a = seval(f.Q, dvar[1], env, cache)
    dx_a = seval(f.x0, dvar[1], env, cache)

    dQ_b = seval(f.Q, dvar[2], env, cache)
    dx_b = seval(f.x0, dvar[2], env, cache)

    dQ_ab = seval(f.Q, dvar, env, cache)
    dx_ab = seval(f.x0, dvar, env, cache)

    ts = f.ts

    n = length(x)
    QQ = SparseCSC(BlockCOO(4, 4, [(1,1,Q), (2,2,Q), (3,3,Q), (4,4,Q), (1,2,dQ_a), (1,3,dQ_b), (1,4,dQ_ab), (2,4,dQ_b), (3,4,dQ_a)]))
    xx = [x..., dx_a..., dx_b..., dx_ab...]
    ret = 3n+1:4n
    mexpc(QQ, xx, ts, transpose=:T, ufact=f.options[:ufact], eps=f.options[:eps], rmax=f.options[:rmax])[2][ret]
end


text:
"""
    NormInfinityBridge{T}

The `NormInfinityCone` is representable with LP constraints, since
``t \\ge \\max_i \\lvert x_i \\rvert`` if and only if
``t \\ge x_i`` and ``t \\ge -x_i`` for all ``i``.
"""
struct NormInfinityBridge{T,F,G} <:
       SetMapBridge{T,MOI.Nonnegatives,MOI.NormInfinityCone,F,G}
    constraint::MOI.ConstraintIndex{F,MOI.Nonnegatives}
end

function concrete_bridge_type(
    ::Type{<:NormInfinityBridge{T}},
    G::Type{<:MOI.AbstractVectorFunction},
    ::Type{MOI.NormInfinityCone},
) where {T}
    F = MOI.Utilities.promote_operation(+, T, G, G)
    return NormInfinityBridge{T,F,G}
end

function MOI.Bridges.map_set(
    ::Type{<:NormInfinityBridge},
    set::MOI.NormInfinityCone,
)
    return MOI.Nonnegatives(2 * (MOI.dimension(set) - 1))
end

function MOI.Bridges.inverse_map_set(
    ::Type{<:NormInfinityBridge},
    set::MOI.Nonnegatives,
)
    return MOI.NormInfinityCone(div(MOI.dimension(set), 2) + 1)
end

function MOI.Bridges.map_function(
    ::Type{<:NormInfinityBridge{T}},
    func,
) where {T}
    scalars = MOI.Utilities.eachscalar(func)
    t = scalars[1]
    lb = scalars[2:end]
    ub = MOI.Utilities.operate(-, T, lb)
    f_new = MOI.Utilities.operate(vcat, T, ub, lb)
    for i in 1:(2*(length(scalars)-1))
        MOI.Utilities.operate_output_index!(+, T, i, f_new, t)
    end
    return f_new
end

function MOI.Bridges.inverse_map_function(
    ::Type{<:NormInfinityBridge{T}},
    func,
) where {T}
    scalars = MOI.Utilities.eachscalar(func)
    t = MOI.Utilities.operate!(/, T, sum(scalars), T(length(scalars)))
    d = div(length(scalars), 2)
    x = MOI.Utilities.operate!(
        /,
        T,
        MOI.Utilities.operate!(-, T, scalars[(d+1):end], scalars[1:d]),
        T(2),
    )
    return MOI.Utilities.operate(vcat, T, t, x)
end

# Given a_i is dual on t - x_i >= 0 and b_i is dual on t + x_i >= 0,
# the dual on (t, x) in NormInfinityCone is (u, v) in NormOneCone, where
# v_i = -a_i + b_i and u = sum(a) + sum(b).
function MOI.Bridges.adjoint_map_function(::Type{<:NormInfinityBridge}, func)
    scalars = MOI.Utilities.eachscalar(func)
    t = sum(scalars)
    d = div(length(scalars), 2)
    x = (scalars[(d+1):end] - scalars[1:d])
    return vcat(t, x)
end

function MOI.Bridges.inverse_adjoint_map_function(
    ::Type{<:NormInfinityBridge{T}},
    func::AbstractVector{T},
) where {T}
    # This is used by `MOI.ConstraintDualStart`.
    # The result should belong to `MOI.Nonnegatives` and the sum of the elements
    # should be `t`.
    # Only one of dual of the upper and lower bound should be active so one of
    # the two duals is zero. We know which one since they should be nonnegative.
    # Then if `t = sum abs(x_i)`, we will indeed have only one of them being
    # zero.
    t = func[1]
    y = func[2:end]
    lb = [x > 0 ? x : zero(x) for x in y]
    ub = [x < 0 ? -x : zero(x) for x in y]
    x = [ub; lb]
    return x .+ (t - sum(x)) / length(x)
end

"""
    NormOneBridge{T}

The `NormOneCone` is representable with LP constraints, since
``t \\ge \\sum_i \\lvert x_i \\rvert`` if and only if there exists a vector y
such that
``t \\ge \\sum_i y_i`` and ``y_i \\ge x_i``, ``y_i \\ge -x_i`` for all ``i``.
"""
struct NormOneBridge{T,F,G} <: AbstractBridge
    y::Vector{MOI.VariableIndex}
    nn_index::MOI.ConstraintIndex{F,MOI.Nonnegatives}
end

function bridge_constraint(
    ::Type{NormOneBridge{T,F,G}},
    model::MOI.ModelLike,
    f::G,
    s::MOI.NormOneCone,
) where {T,F,G}
    f_scalars = MOI.Utilities.eachscalar(f)
    d = MOI.dimension(s)
    y = MOI.add_variables(model, d - 1)
    rhs = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(one(T), y), zero(T))
    ge = MOI.Utilities.operate(-, T, f_scalars[1], rhs)
    lb = f_scalars[2:d]
    ub = MOI.Utilities.operate(-, T, lb)
    lb = MOI.Utilities.operate!(+, T, lb, MOI.VectorOfVariables(y))
    ub = MOI.Utilities.operate!(+, T, ub, MOI.VectorOfVariables(y))
    f_new = MOI.Utilities.operate(vcat, T, ge, ub, lb)
    nn_index = MOI.add_constraint(model, f_new, MOI.Nonnegatives(2d - 1))
    return NormOneBridge{T,F,G}(y, nn_index)
end

function MOI.supports_constraint(
    ::Type{NormOneBridge{T}},
    ::Type{<:MOI.AbstractVectorFunction},
    ::Type{MOI.NormOneCone},
) where {T}
    return true
end

function MOI.Bridges.added_constrained_variable_types(::Type{<:NormOneBridge})
    return Tuple{Type}[]
end

function MOI.Bridges.added_constraint_types(
    ::Type{<:NormOneBridge{T,F}},
) where {T,F}
    return Tuple{Type,Type}[(F, MOI.Nonnegatives)]
end

function concrete_bridge_type(
    ::Type{<:NormOneBridge{T}},
    G::Type{<:MOI.AbstractVectorFunction},
    ::Type{MOI.NormOneCone},
) where {T}
    S = MOI.Utilities.scalar_type(G)
    F = MOI.Utilities.promote_operation(
        vcat,
        T,
        MOI.Utilities.promote_operation(+, T, S, S),
        MOI.Utilities.promote_operation(-, T, S, S),
    )
    return NormOneBridge{T,F,G}
end

MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables)::Int64 = length(b.y)

MOI.get(b::NormOneBridge, ::MOI.ListOfVariableIndices) = copy(b.y)

function MOI.get(
    ::NormOneBridge{T,F},
    ::MOI.NumberOfConstraints{F,MOI.Nonnegatives},
)::Int64 where {T,F}
    return 1
end

function MOI.get(
    b::NormOneBridge{T,F},
    ::MOI.ListOfConstraintIndices{F,MOI.Nonnegatives},
) where {T,F}
    return [b.nn_index]
end

function MOI.delete(model::MOI.ModelLike, c::NormOneBridge)
    MOI.delete(model, c.nn_index)
    MOI.delete(model, c.y)
    return
end

function MOI.get(
    model::MOI.ModelLike,
    ::MOI.ConstraintFunction,
    c::NormOneBridge{T,F,G},
) where {T,F,G}
    nn_func = MOI.Utilities.eachscalar(
        MOI.get(model, MOI.ConstraintFunction(), c.nn_index),
    )
    t = MOI.Utilities.operate!(/, T, nn_func[1] + sum(nn_func), T(2))
    d = div(length(nn_func) - 1, 2)
    x = MOI.Utilities.operate!(
        /,
        T,
        MOI.Utilities.operate!(-, T, nn_func[(d+2):end], nn_func[2:(d+1)]),
        T(2),
    )
    return MOI.Utilities.convert_approx(
        G,
        MOI.Utilities.remove_variable(
            MOI.Utilities.operate(vcat, T, t, x),
            c.y,
        ),
    )
end

function MOI.get(model::MOI.ModelLike, ::MOI.ConstraintSet, c::NormOneBridge)
    dim = div(
        MOI.dimension(MOI.get(model, MOI.ConstraintSet(), c.nn_index)) + 1,
        2,
    )
    return MOI.NormOneCone(dim)
end

function MOI.supports(
    model::MOI.ModelLike,
    attr::Union{MOI.ConstraintPrimalStart,MOI.ConstraintDualStart},
    ::Type{NormOneBridge{T,F,G}},
) where {T,F,G}
    return MOI.supports(model, attr, MOI.ConstraintIndex{F,MOI.Nonnegatives})
end

function MOI.set(
    model::MOI.ModelLike,
    attr::MOI.ConstraintPrimalStart,
    bridge::NormOneBridge{T},
    value,
) where {T}
    x_value = value[1 .+ (1:length(bridge.y))]
    y_value = abs.(x_value)
    for i in eachindex(bridge.y)
        MOI.set(model, MOI.VariablePrimalStart(), bridge.y[i], y_value[i])
    end
    nn_value = vcat(
        value[1] - reduce(+, y_value, init = zero(T)),
        y_value - x_value,
        y_value + x_value,
    )
    MOI.set(model, attr, bridge.nn_index, nn_value)
    return
end

function MOI.get(
    model::MOI.ModelLike,
    attr::Union{MOI.ConstraintPrimal,MOI.ConstraintPrimalStart},
    bridge::NormOneBridge,
)
    nn_primal = MOI.get(model, attr, bridge.nn_index)
    t = (nn_primal[1] + sum(nn_primal)) / 2
    d = length(bridge.y)
    x = (nn_primal[(d+2):end] - nn_primal[2:(d+1)]) / 2
    return vcat(t, x)
end

# Given a_i is dual on y_i - x_i >= 0 and b_i is dual on y_i + x_i >= 0 and c is
# dual on t - sum(y) >= 0, the dual on (t, x) in NormOneCone is
# (u, v) in NormInfinityCone, where v_i = -a_i + b_i and u = c.
function MOI.get(
    model::MOI.ModelLike,
    attr::Union{MOI.ConstraintDual,MOI.ConstraintDualStart},
    bridge::NormOneBridge,
)
    nn_dual = MOI.get(model, attr, bridge.nn_index)
    d = length(bridge.y)
    x = nn_dual[(d+2):end] - nn_dual[2:(d+1)]
    return vcat(nn_dual[1], x)
end

# value[1 + i] = nn_dual[1 + d + i] - nn_dual[1 + i]
# and `nn_dual` is nonnegative. By complementarity slackness, only one of each
# `nn_dual` can be nonzero (except if `x = 0`) so we can set
# depending on the sense of `value[1 + i]`.
function MOI.set(
    model::MOI.ModelLike,
    ::MOI.ConstraintDualStart,
    bridge::NormOneBridge,
    value,
)
    d = length(bridge.y)
    nn_dual = zeros(eltype(value), 2d + 1)
    nn_dual[1] = value[1]
    for i in eachindex(bridge.y)
        v = value[1+i]
        if v < 0
            nn_dual[1+i] = -v
        else
            nn_dual[1+d+i] = v
        end
    end
    MOI.set(model, MOI.ConstraintDualStart(), bridge.nn_index, nn_dual)
    return
end


text:
"""
三角晶系相关
"""

"""
普通的三角格子
"""
function common_triangle_lattice(μ)
    disp(x, y) = -2cos(x) - 4cos(sqrt(3)*y/2.0)*cos(x/2.0) + μ
    return TriangularSystem{:COM}(
        [disp]
    )
end


text:
using Printf
using Formatting
using DifferentialEquations
using ProgressMeter
using JLD2, FileIO

include("Yfind.jl")
include("is_it.jl")
using PyCall
pygui(:qt)
using PyPlot
pygui(true)

tol_dist=1e-2
Max_hit=500

condition(u,t,integrator)= u[5]>Max_hit
function condition2(u,t,integrator) # Event when event_f(u,t) == 0
 u[1]
end
affect!(integrator) = terminate!(integrator)
function affect2!(integrator)
integrator.u[5]=integrator.u[5]+1
 end
cb2 = ContinuousCallback(condition2,affect2!,nothing)
cb1 = DiscreteCallback(condition,affect!)

cb=CallbackSet(cb2,cb1)

Energy=0.25
Energy=.45
Energy=0.1257895
Energy=0.25

H=(2*Energy)^2
n_iter=100
t_end=10000

# H1(p,q,t)= ( (q[2]-q[1])^2+(p[2]-p[1])^2 )*( (q[2]+q[1])^2+(p[2]+a[1])^2 )
# H2(p,q,t)= (p[2]^4+2*p[2]^2*(q[1]^2-1)+(1+q[1]^2)^2 )*(q[2]^4+2*q[2]^2*(p[1]^2+1)+(p[1]^2-1)^2 )
# HAM(p,q,t)=H1(p,q,t)/H2(p,q,t)
H_test(u)=( (u[3]-u[1])^2+(u[2]-u[4])^2 )*( (u[3]+u[1])^2+(u[2]+u[4])^2 )/ ((u[2]^4+2*u[2]^2*(u[1]^2-1)+(1+u[1]^2)^2 )*(u[3]^4+2*u[3]^2*(u[4]^2+1)+(u[4]^2-1)^2 ))

ODE1(z,w)=conj(  im * w.*( 1 ./(z.^2-w.^2)+1 ./(1+w.^2) ))
ODE2(z,w)=conj(  im * z.*( 1 ./(w.^2-z.^2)+1 ./(1+z.^2) ))
function Eq_of_M(du,u,p,t)
    du[1]=real(ODE1(u[1]+im*u[2],u[3]+im*u[4]))
    du[2]=imag(ODE1(u[1]+im*u[2],u[3]+im*u[4]))
    du[3]=real(ODE2(u[1]+im*u[2],u[3]+im*u[4]))
    du[4]=imag(ODE2(u[1]+im*u[2],u[3]+im*u[4]))
    du[5]=0
    return
end
# refernce
# z=X+iP W=Q+iY . Plane Q=0, P=0
# z=u[1]+i u[2] ; w=u[3]+i u[4]

#Q=0, have P find Y

# ArrQ=range(1e-5,stop=.1,length=n_iter)
# ArrP=range(1e-5,stop=.01,length=n_iter)

ArrQ=range(1e-5,stop=2,length=n_iter)
ArrP=range(1e-5,stop=.01,length=n_iter)
#initialize stuff
#initialize stuff

Last_Q=zeros(0)
Last_P=zeros(0)

#all colors but red, reserve for exit points
COLOR=["b", "g", "c", "m", "y", "k", "w"]
# figure()

# axis([ -.3,.3,-.03, .03]);# Efigure(dpi=3600)
# axis([ -.025, .025,-.25, .25]) #around E=0.1257895
axis([ -5, 5, -2, 2])
@showprogress 1 "Computing..."    for j=1:n_iter
        Q=ArrQ[j]
            for k=1:n_iter
                    P=ArrP[k]
                    Y=Yfind(Q,P,H)
                    if ~isempty(Y) && Y>0

                        u0=zeros(5)
                        u0[1]=0 #X
                        u0[2]=P #P
                        u0[3]=Q #Q
                        u0[4]=Y #Y
                        u0[5]=0 # counter variable
                        #are the initial conditions right?

                        prob = ODEProblem(Eq_of_M,u0,(0., t_end))
                        sol=solve(prob, Vern9(),maxiters=1e20, reltol=1e-13,abstol=1e-15,callback=cb,save_start=true,save_end=true,save_everystep=false)
                        # sol=solve(prob, RK4(),maxiters=1e20,reltol=1e-6,abstol=1e-8,callback=cb,save_start=true,save_end=true,save_everystep=false)
                        # plot(A[3,:],-A[2,:],color=current_color,",")
                        #testing if energy is conserved at end?
                        A=sol[:,:]
                        #values at end to check if energy is coservered
                        dH=zeros(length(A[1,:]))
                        umax=zeros(length(A[1,:]))
                        uf=zeros(4)
                        for i=1:length(A[1,:])
                        uf[1]=A[1,i] #X
                        uf[2]=A[2,i] #P
                        uf[3]=A[3,i]#Q
                        uf[4]=A[4,i] #Y
                        dH[i]=abs(H_test(uf)-H)
                        umax[i]=maximum(uf)

                        end
                        dH_max=maximum(dH)
                        #filter if energy is not conservered-toss
                        if dH_max<1e-5# t,A=solve(prob, RK4(),maxiters=1e20, reltol=1e-6,abstol=1e-8,callback=cb,save_start=true,save_end=true,save_everystep=false)
                            current_color=COLOR[mod(k,length(COLOR))+1]
                            plot(A[2,2:end-1],A[3,2:end-1],color=current_color,".",markersize=.1, markeredgewidth=.1)
                            plot(-A[2,2:end-1],A[3,2:end-1],color=current_color,".",markersize=.1, markeredgewidth=.1)
                            plot(A[2,2:end-1],-A[3,2:end-1],color=current_color,".",markersize=.1, markeredgewidth=.1)
                            plot(-A[2,2:end-1],-A[3,2:end-1],color=current_color,".",markersize=.1, markeredgewidth=.1)
                            #testing if energy is conserved at end?

                            # add final values to list- I had to let the callback save the final value so
                            # I need to check if the final value is actually on the section X=0
                            # println(abs(A[1,end]))
                            # println(abs(A[1,end-1]))
                            uf=zeros(5)
                            uf[1]=A[1,end] #X
                            uf[2]=A[2,end] #P
                            uf[3]=A[3,end]#Q
                            uf[4]=A[4,end] #Y
                            uf[5]=0
                            if is_it_exit(uf,H,tol_dist)
                                push!(Last_Q,A[3,end-1])
                                push!(Last_P,A[2,end-1])

                            end
                        end
                    end
                end
            end

# titleS="P-Q Plane  PSS where X=0 at Energy "*string(Energy)*" with "*string(n_iter^2)*" iterations."
# filenameS="PSS_Red_ExitE_"*string(Energy)*"_n_iter_"*string(n_iter)*"_t_"*string(t_end)*"withprojection.png"
plot(Last_P,Last_Q,color="r",".",markersize=.2, markeredgewidth=.1)
plot(Last_P,-Last_Q,color="r",".",markersize=.2,  markeredgewidth=.1)
plot(-Last_P,Last_Q,color="r",".",markersize=.2,  markeredgewidth=.1)
plot(-Last_P,-Last_Q,color="r",".",markersize=.2, markeredgewidth=.1)
xlabel("P")
ylabel("Q")

# title(titleS)
# savefig(filenameS)
#
# H_vec=zeros(length(Last_P))
# u_max=zeros(length(Last_P))
# for j=1:length(Last_P)
#     uf[1]=Last_X[j]
#     uf[2]=Last_P[j]
#     uf[3]=Last_Q[j]
#     uf[4]=Last_Y[j]
#     u_max[j]=maximum(abs.([uf[1],uf[2],uf[3],uf[4]]))
#     H_vec[j]=H_test(uf)/H
# end
#
# figure()
# title("Is energy conserved?")
# plot(1:length(Last_P)-1,log.(H_vec[1:end-1]))
# figure()
# plot(1:length(Last_P),sort(Last_T) )
# figure()
# plot(sort(MAX))