import { t as e } from "./basedecoder-BFm2CpEb.js";
//#region ../../node_modules/geotiff/dist-module/compression/lzw.js
var t = 9, n = 256, r = 257, i = 12;
function a(e, t, n) {
	let i = t % 8, a = Math.floor(t / 8), o = 8 - i, s = t + n - (a + 1) * 8, c = 8 * (a + 2) - (t + n), l = (a + 2) * 8 - t;
	if (c = Math.max(0, c), a >= e.length) return console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)"), r;
	let u = e[a] & 2 ** (8 - i) - 1;
	u <<= n - o;
	let d = u;
	if (a + 1 < e.length) {
		let t = e[a + 1] >>> c;
		t <<= Math.max(0, n - l), d += t;
	}
	if (s > 8 && a + 2 < e.length) {
		let r = (a + 3) * 8 - (t + n), i = e[a + 2] >>> r;
		d += i;
	}
	return d;
}
function o(e, t) {
	for (let n = t.length - 1; n >= 0; n--) e.push(t[n]);
	return e;
}
function s(e) {
	let s = new Uint16Array(4093), c = new Uint8Array(4093);
	for (let e = 0; e <= 257; e++) s[e] = 4096, c[e] = e;
	let l = 258, u = t, d = 0;
	function f() {
		l = 258, u = t;
	}
	function p(e) {
		let t = a(e, d, u);
		return d += u, t;
	}
	function m(e, t) {
		return c[l] = t, s[l] = e, l++, l - 1;
	}
	function h(e) {
		let t = [];
		for (let n = e; n !== 4096; n = s[n]) t.push(c[n]);
		return t;
	}
	let g = [];
	f();
	let _ = new Uint8Array(e), v = p(_), y;
	for (; v !== r;) {
		if (v === n) {
			for (f(), v = p(_); v === n;) v = p(_);
			if (v === r) break;
			if (v > n) throw Error(`corrupted code at scanline ${v}`);
			o(g, h(v)), y = v;
		} else if (v < l) {
			let e = h(v);
			o(g, e), y !== void 0 && m(y, e[e.length - 1]), y = v;
		} else {
			if (y === void 0) throw Error(`Invalid LZW code: ${v} with no previous code`);
			let e = h(y);
			if (!e) throw Error(`Bogus entry. Not in dictionary, ${y} / ${l}, position: ${d}`);
			o(g, e), g.push(e[e.length - 1]), m(y, e[e.length - 1]), y = v;
		}
		l + 1 >= 2 ** u && (u === i ? y = void 0 : u++), v = p(_);
	}
	return new Uint8Array(g);
}
var c = class extends e {
	decodeBlock(e) {
		return s(e).buffer;
	}
};
//#endregion
export { c as default };
