{.compile:"stb_image_resize2.cpp".}

type StbirPixelLayout* {.size:4.} = enum
  StbirBgr      = 0  # 3-chan, with order specified (for channel flipping)
  Stbir1channel = 1
  Stbir2channel = 2
  StbirRgb      = 3  # 3-chan, with order specified (for channel flipping)
  StbirRgba     = 4
  Stbir4channel = 5

  # StbirRgba = 4      # alpha formats, where alpha is NOT premultiplied into color channels
  StbirBgra = 6
  StbirArgb = 7
  StbirAbgr = 8
  StbirRa   = 9
  StbirAr   = 10

  StbirRgbaPm = 11   # alpha formats, where alpha is premultiplied into color channels
  StbirBgraPm = 12
  StbirArgbPm = 13
  StbirAbgrPm = 14
  StbirRaPm   = 15
  StbirArPm   = 16

  # StbirRgbaNoAw = 11 # alpha formats, where NO alpha weighting is applied at all!
  # StbirBgraNoAw = 12 #   these are just synonyms for the _PM flags (which also do
  # StbirArgbNoAw = 13 #   no alpha weighting). These names just make it more clear
  # StbirAbgrNoAw = 14 #   for some folks).
  # StbirRaNoAw   = 15
  # StbirArNoAw   = 16

type StbirEdge* {.size:4.} = enum
  STBIR_EDGE_CLAMP   = 0,
  STBIR_EDGE_REFLECT = 1,
  STBIR_EDGE_WRAP    = 2,  # this edge mode is slower and uses more memory
  STBIR_EDGE_ZERO    = 3,

type StbirFilter* {.size:4.} = enum
  STBIR_FILTER_DEFAULT      = 0,  # use same filter type that easy-to-use API chooses
  STBIR_FILTER_BOX          = 1,  # A trapezoid w/1-pixel wide ramps, same result as box for integer scale ratios
  STBIR_FILTER_TRIANGLE     = 2,  # On upsampling, produces same results as bilinear texture filtering
  STBIR_FILTER_CUBICBSPLINE = 3,  # The cubic b-spline (aka Mitchell-Netrevalli with B=1,C=0), gaussian-esque
  STBIR_FILTER_CATMULLROM   = 4,  # An interpolating cubic spline
  STBIR_FILTER_MITCHELL     = 5,  # Mitchell-Netrevalli filter with B=1/3, C=1/3
  STBIR_FILTER_POINT_SAMPLE = 6,  # Simple point sampling
  STBIR_FILTER_OTHER        = 7,  # User callback specified

type StbirDatatype* {.size:4.} = enum
  STBIR_TYPE_UINT8            = 0,
  STBIR_TYPE_UINT8_SRGB       = 1,
  STBIR_TYPE_UINT8_SRGB_ALPHA = 2,  # alpha channel, when present, should also be SRGB (this is very unusual)
  STBIR_TYPE_UINT16           = 3,
  STBIR_TYPE_FLOAT            = 4,
  STBIR_TYPE_HALF_FLOAT       = 5

proc stbir_resize*(input_pixels: pointer; input_w, input_h, input_stride_in_bytes: int32;
            output_pixels: pointer; output_w, output_h, output_stride_in_bytes: int32;
            pixel_layout: StbirPixelLayout, data_type: StbirDatatype,
            edge: StbirEdge, filter: StbirFilter) {.importc,cdecl.}