solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 0b379ec5b9d30d20aaf65e941cab2a93f468b9ac
parent 35e7b4640be7bf532116fb2963bbe77eafc1697b
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 29 Jun 2016 16:56:23 +0200

First try to images.

Diffstat:
Mcmake/CMakeLists.txt | 3+++
Asrc/ssol_image.c | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ssol_image_c.h | 31+++++++++++++++++++++++++++++++
Asrc/test_ssol_image.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 223 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -48,6 +48,7 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(SSOL_FILES_SRC ssol_device.c + ssol_image.c ssol_material.c ssol_object.c ssol_shape.c) @@ -57,6 +58,7 @@ set(SSOL_FILES_INC_API set(SSOL_FILES_INC ssol_device_c.h + ssol_image_c.h ssol_material_c.h ssol_object_c.h ssol_shape_c.h) @@ -109,6 +111,7 @@ if(NOT NO_TEST) endfunction() new_test(test_ssol_device) + new_test(test_ssol_image) new_test(test_ssol_material) new_test(test_ssol_object) new_test(test_ssol_shape) diff --git a/src/ssol_image.c b/src/ssol_image.c @@ -0,0 +1,121 @@ +/* Copyright (C) CNRS 2016 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "ssol.h" +#include "ssol_image_c.h" +#include "ssol_device_c.h" + +#include <rsys\rsys.h> +#include <rsys\mem_allocator.h> +#include <rsys\ref_count.h> + +/******************************************************************************* +* Helper functions +******************************************************************************/ + +static void +image_release(ref_T* ref) +{ + struct ssol_image* image; + ASSERT(ref); + image = CONTAINER_OF(ref, struct ssol_image, ref); + + ASSERT(image->dev && image->dev->allocator); + + SSOL(device_ref_put(image->dev)); + MEM_RM(image->dev->allocator, image); +} + +/******************************************************************************* +* Local functions +******************************************************************************/ + +/******************************************************************************* +* Exported ssol_image functions +******************************************************************************/ + +res_T +ssol_image_create +(struct ssol_device* dev, + struct ssol_image** out_image) +{ + struct ssol_image* image = NULL; + res_T res = RES_OK; + if (!dev || !out_image) { + return RES_BAD_ARG; + } + + image = (struct ssol_image*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct ssol_image)); + if (!image) { + res = RES_MEM_ERR; + goto error; + } + + SSOL(device_ref_get(dev)); + image->dev = dev; + ref_init(&image->ref); + +exit: + if (out_image) *out_image = image; + return res; +error: + if (image) { + SSOL(image_ref_put(image)); + image = NULL; + } + goto exit; +} + +res_T +ssol_image_ref_get +(struct ssol_image* image) +{ + if (!image) + return RES_BAD_ARG; + ref_get(&image->ref); + return RES_OK; +} + +res_T +ssol_image_ref_put +(struct ssol_image* image) +{ + if (!image) + return RES_BAD_ARG; + ref_put(&image->ref, image_release); + return RES_OK; +} + +res_T +ssol_image_setup + (struct ssol_image* image, + const size_t width, + const size_t height, + const enum ssol_pixel_format format) +{ + if (!image + || width <= 0 + || height <= 0 + || format < 0 + || format >= SSOL_PIXEL_FORMAT_COUNT__) + return RES_BAD_ARG; + + image->width = width; + image->height = height; + image->format = format; + + return RES_OK; +} +\ No newline at end of file diff --git a/src/ssol_image_c.h b/src/ssol_image_c.h @@ -0,0 +1,31 @@ +/* Copyright (C) CNRS 2016 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SSOL_IMAGE_C_H +#define SSOL_IMAGE_C_H + +#include <rsys/ref_count.h> + +struct ssol_image { + + size_t width; + size_t height; + enum ssol_pixel_format format; + + struct ssol_device* dev; + ref_T ref; +}; + +#endif /* SSOL_IMAGE_C_H */ diff --git a/src/test_ssol_image.c b/src/test_ssol_image.c @@ -0,0 +1,66 @@ +/* Copyright (C) CNRS 2016 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "ssol.h" +#include "test_ssol_utils.h" + +#include <rsys/logger.h> + +/******************************************************************************* +* test main program +******************************************************************************/ +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + struct ssol_image* image; + (void) argc, (void) argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(logger_init(&allocator, &logger), RES_OK); + logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); + logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); + logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); + + CHECK(ssol_device_create(&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + + CHECK(ssol_image_create(dev, &image), RES_OK); + + CHECK(ssol_image_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_image_ref_get(image), RES_OK); + + CHECK(ssol_image_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_image_ref_put(image), RES_OK); + + CHECK(ssol_image_setup(NULL, 128, 128, SSOL_PIXEL_DOUBLE3), RES_BAD_ARG); + CHECK(ssol_image_setup(image, 0, 128, SSOL_PIXEL_DOUBLE3), RES_BAD_ARG); + CHECK(ssol_image_setup(image, 128, 0, (enum ssol_pixel_format)999), RES_BAD_ARG); + CHECK(ssol_image_setup(image, 128, 128, SSOL_PIXEL_DOUBLE3), RES_OK); + + CHECK(ssol_image_ref_put(image), RES_OK); + + CHECK(ssol_device_ref_put(dev), RES_OK); + + logger_release(&logger); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + + return 0; +} +\ No newline at end of file