<commit_before>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tcambinconversion.h"

#include "../../logging.h"

using namespace tcam::gst;



static const GEnumValue _tcam_bin_conversion_element_values[] =
{
    { TCAM_BIN_CONVERSION_AUTO, "TCAM_BIN_CONVERSION_AUTO", "auto"},
    { TCAM_BIN_CONVERSION_CONVERT, "TCAM_BIN_CONVERSION_CONVERT", "tcamconvert"},
    { TCAM_BIN_CONVERSION_DUTILS, "TCAM_BIN_CONVERSION_DUTILS", "tcamdutils"},
    { TCAM_BIN_CONVERSION_CUDA, "TCAM_BIN_CONVERSION_CUDA", "tcamdutils-cuda"},
    { 0, nullptr, nullptr}
};

GType tcam_bin_conversion_element_get_type(void)
{
    static GType type = 0;
    if (!type)
    {
        type = g_enum_register_static("TcamBinConversionElement", _tcam_bin_conversion_element_values);
    }
    return type;
}



namespace
{


GstCaps* filter_by_caps_properties(const GstCaps* input, const GstCaps* filter)
{

    GstStructure* filter_struc = gst_caps_get_structure(filter, 0);

    GstCaps* internal_filter = gst_caps_new_empty();

    for (guint i = 0; i < gst_caps_get_size(input); ++i)
    {
        GstStructure* struc = gst_caps_get_structure(input, i);

        if (gst_structure_get_field_type(struc, "format") == G_TYPE_STRING)
        {
            //const char* string = gst_structure_get_string(struc, "format");

            GstStructure* new_struc = gst_structure_new(gst_structure_get_name(struc),
                                                        "format",
                                                        G_TYPE_STRING,
                                                        gst_structure_get_string(struc, "format"),
                                                        nullptr);

            for (gint x = 0; x < gst_structure_n_fields(filter_struc); x++)
            {
                if (g_strcmp0("format", gst_structure_nth_field_name(filter_struc, x)) == 0)
                {
                    continue;
                }

                gst_structure_set_value(new_struc,
                                        gst_structure_nth_field_name(filter_struc, x),
                                        gst_structure_get_value(filter_struc, gst_structure_nth_field_name(filter_struc, x)));
            }
            gst_caps_append_structure(internal_filter, new_struc);

        }
    }

    internal_filter = gst_caps_simplify(internal_filter);


    GstCaps* ret = gst_caps_intersect((GstCaps*)input, (GstCaps*)internal_filter);

    gst_caps_unref(internal_filter);

    return ret;

}




struct conversion_desc
{
    CAPS_TYPE caps_type_in;
    CAPS_TYPE caps_type_out;
    struct input_caps_required_modules modules;
};

// order of required_modules fields

// bool tcamconvert = false;
// bool videoconvert = false;
// bool jpegdec = false;
// bool dutils = false;

// currently the following pipelines are possible

// tcamsrc
// tcamsrc ! tcamconvert
// tcamsrc ! tcamconvert ! videoconvert
// tcamsrc ! jpegdec
// tcamsrc ! videoconvert
// tcamsrc ! tcamdutils

static const struct conversion_desc tcambin_conversion [] =
{
    // non dutils conversions

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {true, false, false, false},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {true, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {true, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {true, true, false, false},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {true, true, false, false},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {true, true, false, false},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {true, true, false, false},},

    {CAPS_TYPE::JPEG, CAPS_TYPE::JPEG, {false, false, false, false},},
    {CAPS_TYPE::JPEG, CAPS_TYPE::RGB_32, {false, false, true, false},},

    {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_24, {false, false, false, false},},
    {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_32, {false, true, false, false},},
    {CAPS_TYPE::YUV, CAPS_TYPE::RGB_32, {false, true, false, false},},

    // the following are dutils specific

    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::RGB_32, {false, false, false, true},},
    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::TIS_POLARIZED, {false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::FLOATING, {false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::RGB_32, {false, false, false, true},},

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {false, false, false, true},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {false, false, false, true},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_64, {false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {false, false, false, true},},<commit_msg>gst/bin: Remove videoconvert from conversion look up<commit_after>/*
 * Copyright 2021 The Imaging Source Europe GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "tcambinconversion.h"

#include "../../logging.h"

using namespace tcam::gst;



static const GEnumValue _tcam_bin_conversion_element_values[] =
{
    { TCAM_BIN_CONVERSION_AUTO, "TCAM_BIN_CONVERSION_AUTO", "auto"},
    { TCAM_BIN_CONVERSION_CONVERT, "TCAM_BIN_CONVERSION_CONVERT", "tcamconvert"},
    { TCAM_BIN_CONVERSION_DUTILS, "TCAM_BIN_CONVERSION_DUTILS", "tcamdutils"},
    { TCAM_BIN_CONVERSION_CUDA, "TCAM_BIN_CONVERSION_CUDA", "tcamdutils-cuda"},
    { 0, nullptr, nullptr}
};

GType tcam_bin_conversion_element_get_type(void)
{
    static GType type = 0;
    if (!type)
    {
        type = g_enum_register_static("TcamBinConversionElement", _tcam_bin_conversion_element_values);
    }
    return type;
}



namespace
{


GstCaps* filter_by_caps_properties(const GstCaps* input, const GstCaps* filter)
{

    GstStructure* filter_struc = gst_caps_get_structure(filter, 0);

    GstCaps* internal_filter = gst_caps_new_empty();

    for (guint i = 0; i < gst_caps_get_size(input); ++i)
    {
        GstStructure* struc = gst_caps_get_structure(input, i);

        if (gst_structure_get_field_type(struc, "format") == G_TYPE_STRING)
        {
            //const char* string = gst_structure_get_string(struc, "format");

            GstStructure* new_struc = gst_structure_new(gst_structure_get_name(struc),
                                                        "format",
                                                        G_TYPE_STRING,
                                                        gst_structure_get_string(struc, "format"),
                                                        nullptr);

            for (gint x = 0; x < gst_structure_n_fields(filter_struc); x++)
            {
                if (g_strcmp0("format", gst_structure_nth_field_name(filter_struc, x)) == 0)
                {
                    continue;
                }

                gst_structure_set_value(new_struc,
                                        gst_structure_nth_field_name(filter_struc, x),
                                        gst_structure_get_value(filter_struc, gst_structure_nth_field_name(filter_struc, x)));
            }
            gst_caps_append_structure(internal_filter, new_struc);

        }
    }

    internal_filter = gst_caps_simplify(internal_filter);


    GstCaps* ret = gst_caps_intersect((GstCaps*)input, (GstCaps*)internal_filter);

    gst_caps_unref(internal_filter);

    return ret;

}




struct conversion_desc
{
    CAPS_TYPE caps_type_in;
    CAPS_TYPE caps_type_out;
    struct input_caps_required_modules modules;
};

// order of required_modules fields

// bool tcamconvert = false;
// bool videoconvert = false;
// bool jpegdec = false;
// bool dutils = false;

// currently the following pipelines are possible

// tcamsrc
// tcamsrc ! tcamconvert
// tcamsrc ! tcamconvert ! videoconvert
// tcamsrc ! jpegdec
// tcamsrc ! videoconvert
// tcamsrc ! tcamdutils

static const struct conversion_desc tcambin_conversion [] =
{
    // non dutils conversions

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_16, {true, false, false, false},},

    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_16, {true, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_12, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_16, {true, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::BAYER_8, {true, false, false, false},},
    {CAPS_TYPE::BAYER_16, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_8, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_10, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_12, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_8, {true, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::MONO_16, {true, false, false, false},},
    {CAPS_TYPE::MONO_16, CAPS_TYPE::RGB_32, {true, false, false, false},},

    {CAPS_TYPE::JPEG, CAPS_TYPE::JPEG, {false, false, false, false},},
    {CAPS_TYPE::JPEG, CAPS_TYPE::RGB_32, {false, false, true, false},},

    // {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_24, {false, false, false, false},},
    // {CAPS_TYPE::RGB_24, CAPS_TYPE::RGB_32, {false, true, false, false},},
    // {CAPS_TYPE::YUV, CAPS_TYPE::RGB_32, {false, true, false, false},},

    // the following are dutils specific

    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::RGB_32, {false, false, false, true},},
    {CAPS_TYPE::TIS_POLARIZED, CAPS_TYPE::TIS_POLARIZED, {false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::FLOATING, {false, false, false, true},},
    {CAPS_TYPE::FLOATING, CAPS_TYPE::RGB_32, {false, false, false, true},},

    {CAPS_TYPE::BAYER_8, CAPS_TYPE::BAYER_8, {false, false, false, true},},
    {CAPS_TYPE::BAYER_8, CAPS_TYPE::RGB_32, {false, false, false, true},},

    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_32, {false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::RGB_64, {false, false, false, true},},
    {CAPS_TYPE::BAYER_10, CAPS_TYPE::BAYER_8, {false, false, false, true},},
{'fraction_non_alphanumeric': 0.13443324167430493, 'fraction_numerical': 0.01924839596700275, 'mean_word_length': 3.5956475956475957, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2363005', 'n_tokens_mistral': 4964, 'n_tokens_neox': 4693, 'n_words': 957}