Crosshair Studio

@itzchill / crosshair-studiov1.5.9Public

Overlay crosshair for games and apps that have none.

Files

png.luau1.8 KB

-- Minimal RGBA PNG encoder using stored deflate blocks.
local band, bxor, rshift, bnot = bit32.band, bit32.bxor, bit32.rshift, bit32.bnot

local crc_table = {}
for i = 0, 255 do
  local c = i
  for _ = 1, 8 do
    if band(c, 1) == 1 then c = bxor(0xEDB88320, rshift(c, 1))
    else c = rshift(c, 1) end
  end
  crc_table[i] = c
end

local function u32(n)
  n = n % 0x100000000
  return string.char(
    band(rshift(n, 24), 255), band(rshift(n, 16), 255),
    band(rshift(n, 8), 255), band(n, 255))
end

local function crc32(s)
  local c = 0xffffffff
  local byte = string.byte
  for i = 1, #s do
    c = bxor(crc_table[band(bxor(c, byte(s, i)), 255)], rshift(c, 8))
  end
  return bnot(c) % 0x100000000
end

local function chunk(kind, data)
  return u32(#data) .. kind .. data .. u32(crc32(kind .. data))
end

local function adler32(s)
  local a, b = 1, 0
  for i = 1, #s do
    a = a + s:byte(i)
    b = b + a
  end
  return (b % 65521) * 65536 + (a % 65521)
end

local function zlib_stored(raw)
  local parts = { string.char(0x78, 0x01) }
  local pos = 1
  while pos <= #raw do
    local n = math.min(65535, #raw - pos + 1)
    local last = pos + n > #raw
    parts[#parts + 1] = string.char(last and 1 or 0, n % 256, math.floor(n / 256),
      (65535 - n) % 256, math.floor((65535 - n) / 256))
    parts[#parts + 1] = raw:sub(pos, pos + n - 1)
    pos = pos + n
  end
  parts[#parts + 1] = u32(adler32(raw))
  return table.concat(parts)
end

return function(w, h, rgba)
  local rows = {}
  for y = 1, h do
    local p = (y - 1) * w * 4 + 1
    rows[y] = "\0" .. rgba:sub(p, p + w * 4 - 1)
  end
  local filtered = table.concat(rows)
  local ihdr = u32(w) .. u32(h) .. string.char(8, 6, 0, 0, 0)
  return "\137PNG\r\n\26\n" .. chunk("IHDR", ihdr)
    .. chunk("IDAT", zlib_stored(filtered)) .. chunk("IEND", "")
end

136 files, 165.2 KB. 130 have no text preview.