summit/frontend/node_modules/three-stdlib/loaders/TGALoader.cjs.map

1 line
19 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"TGALoader.cjs","sources":["../../src/loaders/TGALoader.js"],"sourcesContent":["import { DataTextureLoader, LinearMipmapLinearFilter } from 'three'\n\nclass TGALoader extends DataTextureLoader {\n constructor(manager) {\n super(manager)\n }\n\n parse(buffer) {\n // reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js\n\n function tgaCheckHeader(header) {\n switch (header.image_type) {\n // check indexed type\n\n case TGA_TYPE_INDEXED:\n case TGA_TYPE_RLE_INDEXED:\n if (header.colormap_length > 256 || header.colormap_size !== 24 || header.colormap_type !== 1) {\n console.error('THREE.TGALoader: Invalid type colormap data for indexed type.')\n }\n\n break\n\n // check colormap type\n\n case TGA_TYPE_RGB:\n case TGA_TYPE_GREY:\n case TGA_TYPE_RLE_RGB:\n case TGA_TYPE_RLE_GREY:\n if (header.colormap_type) {\n console.error('THREE.TGALoader: Invalid type colormap data for colormap type.')\n }\n\n break\n\n // What the need of a file without data ?\n\n case TGA_TYPE_NO_DATA:\n console.error('THREE.TGALoader: No data.')\n\n // Invalid type ?\n\n default:\n console.error('THREE.TGALoader: Invalid type \"%s\".', header.image_type)\n }\n\n // check image width and height\n\n if (header.width <= 0 || header.height <= 0) {\n console.error('THREE.TGALoader: Invalid image size.')\n }\n\n // check image pixel size\n\n if (header.pixel_size !== 8 && header.pixel_size !== 16 && header.pixel_size !== 24 && header.pixel_size !== 32) {\n console.error('THREE.TGALoader: Invalid pixel size \"%s\".', header.pixel_size)\n }\n }\n\n // parse tga image buffer\n\n function tgaParse(use_rle, use_pal, header, offset, data) {\n let pixel_data, palettes\n\n const pixel_size = header.pixel_size >> 3\n const pixel_total = header.width * header.height * pixel_size\n\n // read palettes\n\n if (use_pal) {\n palettes = data.subarray(offset, (offset += header.colormap_length * (header.colormap_size >> 3)))\n }\n\n // read RLE\n\n if (use_rle) {\n pixel_data = new Uint8Array(pixel_total)\n\n let c, count, i\n let shift = 0\n const pixels = new Uint8Array(pixel_size)\n\n while (shift < pixel_total) {\n c = data[offset++]\n count = (c & 0x7f) + 1\n\n // RLE pixels\n\n if (c & 0x80) {\n // bind pixel tmp array\n\n for (i = 0; i < pixel_size; ++i) {\n pixels[i] = data[offset++]\n }\n\n // copy pixel array\n\n for (i = 0; i < count; ++i) {\n pixel_data.set(pixels, shift + i * pixel_size)\n }\n\n shift += pixel_size * count\n } else {\n // raw pixels\n\n count *= pixel_size\n\n for (i = 0; i < count; ++i) {\n pixel_data[shift + i] = data[offset++]\n }\n\n shift += count\n }\n }\n } else {\n // raw pixels\n\n pixel_data = data.subarray(offset, (offset += use_pal ? header.width * header.height : pixel_total))\n }\n\n return {\n pixel_data: pixel_data,\n palettes: palettes,\n }\n }\n\n function tgaGetImageData8bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image, palettes) {\n const colormap = palettes\n let color,\n i = 0,\n x,\n y\n const width = header.width\n\n for (y = y_start; y !== y_end; y += y_step) {\n for (x = x_start; x !== x_end; x += x_step, i++) {\n color = image[i]\n imageData[(x + width * y) * 4 + 3] = 255\n imageData[(x + width * y) * 4 + 2] = colormap[color * 3 + 0]\n imageData[(x + width * y) * 4 + 1] = colormap[color * 3 + 1]\n imageData[(x + width * y) * 4 + 0] = c