jangko / nimPNG

PNG (Portable Network Graphics) decoder and encoder written in Nim
MIT License
90 stars 12 forks source link

nzCompressInit -> nimz.nzCompressInit #62

Closed bung87 closed 3 years ago

bung87 commented 3 years ago

my lib https://github.com/bung87/zopflipng use something nimPNG not exported, So I include it, but it will cause this line ambition call.

jangko commented 3 years ago

and what is that something not exported?

bung87 commented 3 years ago

type   
  PNGChunkType = distinct int32
  PNGChunk = ref object of RootObj
    length: int #range[0..0x7FFFFFFF]
    chunkType: PNGChunkType
    crc: uint32
    data: string
    pos: int
  PNGPalette = ref object of PNGChunk
    palette: seq[RGBA8]

  PNGData = ref object of PNGChunk
    idat: string

  PNGTime = ref object of PNGChunk
    year: int #range[0..65535]
    month: int #range[1..12]
    day: int #range[1..31]
    hour: int #range[0..23]
    minute: int #range[0..59]
    second: int #range[0..60] #to allow for leap seconds

  PNGPhys = ref object of PNGChunk
    physX, physY: int
    unit: int

  PNGTrans = ref object of PNGChunk
    keyR, keyG, keyB: int

  PNGBackground = ref object of PNGChunk
    bkgdR, bkgdG, bkgdB: int

  PNGText = ref object of PNGChunk
    keyword: string
    text: string

  PNGZtxt = ref object of PNGChunk
    keyword: string
    text: string

  PNGItxt = ref object of PNGChunk
    keyword: string
    text: string
    languageTag: string
    translatedKeyword: string

  PNGGamma = ref object of PNGChunk
    gamma: int

  PNGChroma = ref object of PNGChunk
    whitePointX, whitePointY: int
    redX, redY: int
    greenX, greenY: int
    blueX, blueY: int

  PNGStandarRGB = ref object of PNGChunk
    renderingIntent: int

  PNGICCProfile = ref object of PNGChunk
    profileName: string
    profile: string

  PNGSPEntry = object
    red, green, blue, alpha, frequency: int

  PNGSPalette = ref object of PNGChunk
    paletteName: string
    sampleDepth: int
    palette: seq[PNGSPEntry]

  PNGHist = ref object of PNGChunk
    histogram: seq[int]

  PNGSbit = ref object of PNGChunk

  PNGHeader = ref object of PNGChunk
    width, height: int #range[1..0x7FFFFFFF]
    bitDepth: int
    colorType: PNGColorType
    compressionMethod: int
    filterMethod: int
    interlaceMethod: PNGInterlace

  APNGFrameChunk = ref object of PNGChunk
    sequenceNumber: int

  APNGFrameData = ref object of APNGFrameChunk
    # during decoding frameDataPos points to chunk.data[pos]
    # during encoding frameDataPos points to png.apngPixels[pos] and png.apngChunks[pos]
    frameDataPos: int

  APNGAnimationControl = ref object of PNGChunk
    numFrames: int
    numPlays: int
  nzStreamMode = enum
    nzsDeflate, nzsInflate
  BitStream = object
    bitpointer: int
    data: string
    databitlen: int
  MynzStream* = ref object
    btype: range[0..3]
    use_lz77: bool
    windowsize: range[2..32768]
    minmatch: range[3..258]
    nicematch: range[3..358]
    lazymatching: bool
    bits: BitStream
    data: string
    mode: nzStreamMode
    ignoreAdler32*: bool

proc signatureMaker(): string {. compiletime .} =
  const signatureBytes = [137, 80, 78, 71, 13, 10, 26, 10]
  result = ""
  for c in signatureBytes: result.add chr(c)

template PNGFatal(msg: string): untyped =
  newException(PNGError, msg)

const
  PNGSignature = signatureMaker()
  IHDR = makeChunkType("IHDR")
  IEND = makeChunkType("IEND")
  PLTE = makeChunkType("PLTE")
  IDAT = makeChunkType("IDAT")
  tRNS = makeChunkType("tRNS")
  bKGD = makeChunkType("bKGD")
  pHYs = makeChunkType("pHYs")
  tIME = makeChunkType("tIME")
  iTXt = makeChunkType("iTXt")
  zTXt = makeChunkType("zTXt")
  tEXt = makeChunkType("tEXt")
  gAMA = makeChunkType("gAMA")
  cHRM = makeChunkType("cHRM")
  sRGB = makeChunkType("sRGB")
  iCCP = makeChunkType("iCCP")
  sBIT = makeChunkType("sBIT")
  sPLT = makeChunkType("sPLT")
  hIST = makeChunkType("hIST")

  # APNG chunks
  acTL = makeChunkType("acTL")
  fcTL = makeChunkType("fcTL")
  fdAT = makeChunkType("fdAT")
jangko commented 3 years ago

you should not include nimPNG/nimz again, because you already include nimPNG