// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import { estimateObjectSize } from "@foxglove/studio-base/players/messageMemoryEstimation.js";
import { ensureWebCodecsSupported } from "../../../utils/compatibility.js";
import { parseMessage } from "../../utils.js";
import { copyVideoFrameToI420 } from "./h264.js";
export async function deserializeMJPEGFrame({ topic, message, callback }) {
    const { receiveTime } = parseMessage(message);
    const supported = ensureWebCodecsSupported("ImageDecoder");
    if (!supported) {
        return;
    }
    const decoder = new ImageDecoder({
        type: "image/jpeg",
        data: message.data
    });
    const { image: frame } = await decoder.decode();
    const { data: buffer, width, height } = await copyVideoFrameToI420(frame, "MJPEG");
    const foxgloveMessage = {
        timestamp: receiveTime,
        frame_id: "camera",
        width,
        height,
        data: buffer,
        encoding: "yuv420p",
        step: width,
    };
    frame.close();
    callback({
        topic,
        receiveTime,
        message: foxgloveMessage,
        sizeInBytes: estimateObjectSize(foxgloveMessage),
        schemaName: "foxglove.RawImage",
        depthaiTransformation: message.transformation,
    });
}
//# sourceMappingURL=mjpeg.js.map