import { r as M, a as T, b as k } from "./js-binary-schema-parser.js";
var f = {}, F = {}, D;
function R() {
  if (D) return F;
  D = 1, Object.defineProperty(F, "__esModule", {
    value: !0
  }), F.deinterlace = void 0;
  var b = function(m, d) {
    for (var p = new Array(m.length), u = m.length / d, g = function(s, a) {
      var r = m.slice(a * d, (a + 1) * d);
      p.splice.apply(p, [s * d, d].concat(r));
    }, w = [0, 4, 2, 1], n = [8, 8, 4, 2], c = 0, t = 0; t < 4; t++)
      for (var e = w[t]; e < u; e += n[t])
        g(e, c), c++;
    return p;
  };
  return F.deinterlace = b, F;
}
var P = {}, G;
function O() {
  if (G) return P;
  G = 1, Object.defineProperty(P, "__esModule", {
    value: !0
  }), P.lzw = void 0;
  var b = function(m, d, p) {
    var u = 4096, g = -1, w = p, n, c, t, e, l, s, a, h, r, o, z, i, _, v, A, q, S = new Array(p), C = new Array(u), x = new Array(u), y = new Array(u + 1);
    for (i = m, c = 1 << i, l = c + 1, n = c + 2, a = g, e = i + 1, t = (1 << e) - 1, r = 0; r < c; r++)
      C[r] = 0, x[r] = r;
    var z, h, _, v, q, A;
    for (z = h = _ = v = q = A = 0, o = 0; o < w; ) {
      if (v === 0) {
        if (h < e) {
          z += d[A] << h, h += 8, A++;
          continue;
        }
        if (r = z & t, z >>= e, h -= e, r > n || r == l)
          break;
        if (r == c) {
          e = i + 1, t = (1 << e) - 1, n = c + 2, a = g;
          continue;
        }
        if (a == g) {
          y[v++] = x[r], a = r, _ = r;
          continue;
        }
        for (s = r, r == n && (y[v++] = _, r = a); r > c; )
          y[v++] = x[r], r = C[r];
        _ = x[r] & 255, y[v++] = _, n < u && (C[n] = a, x[n] = _, n++, (n & t) === 0 && n < u && (e++, t += n)), a = s;
      }
      v--, S[q++] = y[v], o++;
    }
    for (o = q; o < w; o++)
      S[o] = 0;
    return S;
  };
  return P.lzw = b, P;
}
var L;
function U() {
  if (L) return f;
  L = 1, Object.defineProperty(f, "__esModule", {
    value: !0
  }), f.decompressFrames = f.decompressFrame = f.parseGIF = void 0;
  var b = u(M()), I = T(), m = k(), d = R(), p = O();
  function u(t) {
    return t && t.__esModule ? t : { default: t };
  }
  var g = function(e) {
    var l = new Uint8Array(e);
    return (0, I.parse)((0, m.buildStream)(l), b.default);
  };
  f.parseGIF = g;
  var w = function(e) {
    for (var l = e.pixels.length, s = new Uint8ClampedArray(l * 4), a = 0; a < l; a++) {
      var r = a * 4, o = e.pixels[a], i = e.colorTable[o] || [0, 0, 0];
      s[r] = i[0], s[r + 1] = i[1], s[r + 2] = i[2], s[r + 3] = o !== e.transparentIndex ? 255 : 0;
    }
    return s;
  }, n = function(e, l, s) {
    if (!e.image) {
      console.warn("gif frame does not have associated image.");
      return;
    }
    var a = e.image, r = a.descriptor.width * a.descriptor.height, o = (0, p.lzw)(a.data.minCodeSize, a.data.blocks, r);
    a.descriptor.lct.interlaced && (o = (0, d.deinterlace)(o, a.descriptor.width));
    var i = {
      pixels: o,
      dims: {
        top: e.image.descriptor.top,
        left: e.image.descriptor.left,
        width: e.image.descriptor.width,
        height: e.image.descriptor.height
      }
    };
    return a.descriptor.lct && a.descriptor.lct.exists ? i.colorTable = a.lct : i.colorTable = l, e.gce && (i.delay = (e.gce.delay || 10) * 10, i.disposalType = e.gce.extras.disposal, e.gce.extras.transparentColorGiven && (i.transparentIndex = e.gce.transparentColorIndex)), s && (i.patch = w(i)), i;
  };
  f.decompressFrame = n;
  var c = function(e, l) {
    return e.frames.filter(function(s) {
      return s.image;
    }).map(function(s) {
      return n(s, e.gct, l);
    });
  };
  return f.decompressFrames = c, f;
}
var E = U();
export {
  E as l
};
