htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

htrdr_buffer.h (3607B)


      1 /* Copyright (C) 2018-2019, 2022-2025 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2020-2022 Institut Mines Télécom Albi-Carmaux
      3  * Copyright (C) 2022-2025 Institut Pierre-Simon Laplace
      4  * Copyright (C) 2022-2025 Institut de Physique du Globe de Paris
      5  * Copyright (C) 2018-2025 |Méso|Star> (contact@meso-star.com)
      6  * Copyright (C) 2022-2025 Observatoire de Paris
      7  * Copyright (C) 2022-2025 Université de Reims Champagne-Ardenne
      8  * Copyright (C) 2022-2025 Université de Versaille Saint-Quentin
      9  * Copyright (C) 2018-2019, 2022-2025 Université Paul Sabatier
     10  *
     11  * This program is free software: you can redistribute it and/or modify
     12  * it under the terms of the GNU General Public License as published by
     13  * the Free Software Foundation, either version 3 of the License, or
     14  * (at your option) any later version.
     15  *
     16  * This program is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     19  * GNU General Public License for more details.
     20  *
     21  * You should have received a copy of the GNU General Public License
     22  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     23 
     24 #ifndef HTRDR_BUFFER_H
     25 #define HTRDR_BUFFER_H
     26 
     27 #include "core/htrdr.h"
     28 
     29 #include <rsys/math.h>
     30 #include <rsys/rsys.h>
     31 
     32 /*
     33  * Row major ordered 2D buffer
     34  */
     35 
     36 struct htrdr_pixel_format {
     37   size_t size; /* In bytes */
     38   size_t alignment; /* Power of two, in Bytes */
     39 };
     40 #define HTRDR_PIXEL_FORMAT_NULL__ {0, 0}
     41 static const struct htrdr_pixel_format HTRDR_PIXEL_FORMAT_NULL =
     42   HTRDR_PIXEL_FORMAT_NULL__;
     43 
     44 struct htrdr_buffer_layout {
     45   size_t width; /* #elements in X */
     46   size_t height; /* #elements in Y */
     47   size_t pitch; /* #Bytes between 2 consecutive line */
     48   size_t elmt_size; /* Size of an element in the buffer */
     49   size_t alignment; /* Alignement of the memory */
     50 };
     51 #define HTRDR_BUFFER_LAYOUT_NULL__ {0,0,0,0,0}
     52 static const struct htrdr_buffer_layout HTRDR_BUFFER_LAYOUT_NULL =
     53   HTRDR_BUFFER_LAYOUT_NULL__;
     54 
     55 static INLINE int
     56 htrdr_buffer_layout_eq
     57   (const struct htrdr_buffer_layout* a,
     58    const struct htrdr_buffer_layout* b)
     59 {
     60   ASSERT(a && b);
     61   return a->width == b->width
     62       && a->height == b->height
     63       && a->pitch == b->pitch
     64       && a->elmt_size == b->elmt_size
     65       && a->alignment == b->alignment;
     66 }
     67 
     68 static INLINE res_T
     69 htrdr_buffer_layout_check(const struct htrdr_buffer_layout* layout)
     70 {
     71   if(!layout) return RES_BAD_ARG;
     72 
     73   /* Invalid resolution */
     74   if(!layout->width || !layout->height) {
     75     return RES_BAD_ARG;
     76   }
     77 
     78   /* An element cannot be empty */
     79   if(!layout->elmt_size) {
     80     return RES_BAD_ARG;
     81   }
     82 
     83   /* Check pitch consistency */
     84   if(!layout->width*layout->elmt_size > layout->pitch) {
     85     return RES_BAD_ARG;
     86   }
     87 
     88   /* Ensure that the alignement is a power of two */
     89   if(!IS_POW2(layout->alignment)) {
     90     return RES_BAD_ARG;
     91   }
     92 
     93   return RES_OK;
     94 }
     95 
     96 /* Forward declarations */
     97 struct htrdr;
     98 struct htrdr_buffer;
     99 
    100 BEGIN_DECLS
    101 
    102 HTRDR_API res_T
    103 htrdr_buffer_create
    104   (struct htrdr* htrdr,
    105    const struct htrdr_buffer_layout* layout,
    106    struct htrdr_buffer** buf);
    107 
    108 HTRDR_API void
    109 htrdr_buffer_ref_get
    110   (struct htrdr_buffer* buf);
    111 
    112 HTRDR_API void
    113 htrdr_buffer_ref_put
    114   (struct htrdr_buffer* buf);
    115 
    116 HTRDR_API void
    117 htrdr_buffer_get_layout
    118   (const struct htrdr_buffer* buf,
    119    struct htrdr_buffer_layout* layout);
    120 
    121 HTRDR_API void*
    122 htrdr_buffer_get_data
    123   (struct htrdr_buffer* buf);
    124 
    125 HTRDR_API void*
    126 htrdr_buffer_at
    127   (struct htrdr_buffer* buf,
    128    const size_t x,
    129    const size_t y);
    130 
    131 END_DECLS
    132 
    133 #endif /* HTRDR_BUFFER_H */