import { Sampler2D } from "./Sampler2D.js";
import { sampler2d_to_uint8_RGBA } from "./sampler2d_to_uint8_RGBA.js";

/**
 *
 * @param {Sampler2D} input
 * @returns {Sampler2D}
 */
export function sampler2d_ensure_uint8_RGBA(input) {
    if (
        input.itemSize === 4
        && (input.data.constructor === Uint8Array || input.data.constructor === Uint8ClampedArray)
    ) {
        return input;
    }

    const resampled = Sampler2D.uint8(4, input.width, input.height);

    sampler2d_to_uint8_RGBA(resampled, input);

    return resampled;
}
