<commit_before>/*
 * Copyright 2018 GoPro Inc.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 "format.h"
#include "glcontext.h"
#include "nodes.h"

#define FORMAT_SIZE_CASE(format, size, name, doc) case format: return size;
int ngli_format_get_bytes_per_pixel(int format)
{
    switch (format) {
        NGLI_FORMATS(FORMAT_SIZE_CASE);
    }
    return 0;
}

static int get_gl_format_type(struct glcontext *gl, int data_format,
                              GLint *formatp, GLint *internal_formatp, GLenum *typep)
{
    static const struct entry {
        GLint format;
        GLint internal_format;
        GLenum type;
    } format_map[] = {
        [NGLI_FORMAT_UNDEFINED]            = {0,                  0,                     0},
        [NGLI_FORMAT_R8_UNORM]             = {GL_RED,             GL_R8,                 GL_UNSIGNED_BYTE},
        [NGLI_FORMAT_R8_SNORM]             = {GL_RED,             GL_R8_SNORM,           GL_BYTE},
        [NGLI_FORMAT_R8_UINT]              = {GL_RED_INTEGER,     GL_R8UI,               GL_UNSIGNED_BYTE},
        [NGLI_FORMAT_R8_SINT]              = {GL_RED_INTEGER,     GL_R8I,                GL_BYTE},
        [NGLI_FORMAT_R8G8_UNORM]           = {GL_RG,              GL_RG8,                GL_UNSIGNED_BYTE},<commit_msg>format: rely on a declarative comp size array to obtain BPP<commit_after>/*
 * Copyright 2018 GoPro Inc.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 "format.h"
#include "glcontext.h"
#include "nodes.h"

static const struct {
    int nb_comp;
    int size;
} format_comp_sizes[NGLI_FORMAT_NB] = {
    [NGLI_FORMAT_R8_UNORM]            = {1, 1},
    [NGLI_FORMAT_R8_SNORM]            = {1, 1},
    [NGLI_FORMAT_R8_UINT]             = {1, 1},
    [NGLI_FORMAT_R8_SINT]             = {1, 1},
    [NGLI_FORMAT_R8G8_UNORM]          = {2, 1 + 1},
    [NGLI_FORMAT_R8G8_SNORM]          = {2, 1 + 1},
    [NGLI_FORMAT_R8G8_UINT]           = {2, 1 + 1},
    [NGLI_FORMAT_R8G8_SINT]           = {2, 1 + 1},
    [NGLI_FORMAT_R8G8B8_UNORM]        = {3, 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8_SNORM]        = {3, 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8_UINT]         = {3, 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8_SINT]         = {3, 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8_SRGB]         = {3, 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8A8_UNORM]      = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8A8_SNORM]      = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8A8_UINT]       = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8A8_SINT]       = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_R8G8B8A8_SRGB]       = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_B8G8R8A8_UNORM]      = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_B8G8R8A8_SNORM]      = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_B8G8R8A8_UINT]       = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_B8G8R8A8_SINT]       = {4, 1 + 1 + 1 + 1},
    [NGLI_FORMAT_R16_UNORM]           = {1, 2},
    [NGLI_FORMAT_R16_SNORM]           = {1, 2},
    [NGLI_FORMAT_R16_UINT]            = {1, 2},
    [NGLI_FORMAT_R16_SINT]            = {1, 2},
    [NGLI_FORMAT_R16_SFLOAT]          = {1, 2},
    [NGLI_FORMAT_R16G16_UNORM]        = {2, 2 + 2},
    [NGLI_FORMAT_R16G16_SNORM]        = {2, 2 + 2},
    [NGLI_FORMAT_R16G16_UINT]         = {2, 2 + 2},
    [NGLI_FORMAT_R16G16_SINT]         = {2, 2 + 2},
    [NGLI_FORMAT_R16G16_SFLOAT]       = {2, 2 + 2},
    [NGLI_FORMAT_R16G16B16_UNORM]     = {3, 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16_SNORM]     = {3, 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16_UINT]      = {3, 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16_SINT]      = {3, 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16_SFLOAT]    = {3, 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16A16_UNORM]  = {4, 2 + 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16A16_SNORM]  = {4, 2 + 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16A16_UINT]   = {4, 2 + 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16A16_SINT]   = {4, 2 + 2 + 2 + 2},
    [NGLI_FORMAT_R16G16B16A16_SFLOAT] = {4, 2 + 2 + 2 + 2},
    [NGLI_FORMAT_R32_UINT]            = {1, 4},
    [NGLI_FORMAT_R32_SINT]            = {1, 4},
    [NGLI_FORMAT_R32_SFLOAT]          = {1, 4},
    [NGLI_FORMAT_R32G32_UINT]         = {2, 4 + 4},
    [NGLI_FORMAT_R32G32_SINT]         = {2, 4 + 4},
    [NGLI_FORMAT_R32G32_SFLOAT]       = {2, 4 + 4},
    [NGLI_FORMAT_R32G32B32_UINT]      = {3, 4 + 4 + 4},
    [NGLI_FORMAT_R32G32B32_SINT]      = {3, 4 + 4 + 4},
    [NGLI_FORMAT_R32G32B32_SFLOAT]    = {3, 4 + 4 + 4},
    [NGLI_FORMAT_R32G32B32A32_UINT]   = {4, 4 + 4 + 4 + 4},
    [NGLI_FORMAT_R32G32B32A32_SINT]   = {4, 4 + 4 + 4 + 4},
    [NGLI_FORMAT_R32G32B32A32_SFLOAT] = {4, 4 + 4 + 4 + 4},
    [NGLI_FORMAT_D16_UNORM]           = {1, 2},
    [NGLI_FORMAT_X8_D24_UNORM_PACK32] = {2, 3 + 1},
    [NGLI_FORMAT_D32_SFLOAT]          = {1, 4},
    [NGLI_FORMAT_D24_UNORM_S8_UINT]   = {2, 3 + 1},
    [NGLI_FORMAT_D32_SFLOAT_S8_UINT]  = {3, 4 + 1 + 3},
    [NGLI_FORMAT_S8_UINT]             = {1, 1},
};

int ngli_format_get_bytes_per_pixel(int format)
{
    return format_comp_sizes[format].size;
}

static int get_gl_format_type(struct glcontext *gl, int data_format,
                              GLint *formatp, GLint *internal_formatp, GLenum *typep)
{
    static const struct entry {
        GLint format;
        GLint internal_format;
        GLenum type;
    } format_map[] = {
        [NGLI_FORMAT_UNDEFINED]            = {0,                  0,                     0},
        [NGLI_FORMAT_R8_UNORM]             = {GL_RED,             GL_R8,                 GL_UNSIGNED_BYTE},
        [NGLI_FORMAT_R8_SNORM]             = {GL_RED,             GL_R8_SNORM,           GL_BYTE},
        [NGLI_FORMAT_R8_UINT]              = {GL_RED_INTEGER,     GL_R8UI,               GL_UNSIGNED_BYTE},
        [NGLI_FORMAT_R8_SINT]              = {GL_RED_INTEGER,     GL_R8I,                GL_BYTE},
        [NGLI_FORMAT_R8G8_UNORM]           = {GL_RG,              GL_RG8,                GL_UNSIGNED_BYTE},
{'fraction_non_alphanumeric': 0.11135252580119501, 'fraction_numerical': 0.06749049429657794, 'mean_word_length': 2.1966145833333335, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '612175', 'n_tokens_mistral': 3166, 'n_tokens_neox': 2904, 'n_words': 654}