import {
    sampler2d_compute_texel_value_conversion_scale_to_uint8
} from "./sampler2d_compute_texel_value_conversion_scale_to_uint8.js";
import sampler2d_to_html_canvas from "./sampler2d_to_html_canvas.js";

/**
 * Converts an input image to a data url string
 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
 * @param {Sampler2D} sampler
 * @returns {string}
 */
export function sampler2d_to_data_url(sampler) {

    const canvas = document.createElement('canvas');

    const { scale, offset } = sampler2d_compute_texel_value_conversion_scale_to_uint8(sampler);

    sampler2d_to_html_canvas(sampler, scale, offset, canvas);

    return canvas.toDataURL('image/png');

}
