Skip to content

Commit

Permalink
Add Blur cpp example and improve image error handling (#72)
Browse files Browse the repository at this point in the history
* Add Blur cpp example and improve image error handling

* Use clang formatting and include math.h

* update submodule , fix event passing and minor comment fix

---------

Co-authored-by: PRZEMYSLAW_WISNIEWSKI <przemyslaw.wisniewski@mobica.com>
  • Loading branch information
Mikolaj-Filar-Mobica and pwisniewskimobica authored May 16, 2023
1 parent c98aa82 commit f510201
Show file tree
Hide file tree
Showing 6 changed files with 1,040 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/include/CL/SDK/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace cl {
namespace sdk {
struct Image
{
int width, height, pixel_size;
int width = 0, height = 0, pixel_size = 1;
cl::vector<unsigned char> pixels;
};

Expand Down
14 changes: 13 additions & 1 deletion lib/src/SDK/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ namespace sdk {
Image im;
unsigned char* data =
stbi_load(file_name, &im.width, &im.height, &im.pixel_size, 0);

if (data == nullptr)
{
std::string err_msg{ "Not possible to read file" };
const char* load_msg = stbi_failure_reason();

if (load_msg) err_msg += std::string(": ") + load_msg;

cl::util::detail::errHandler(CL_INVALID_ARG_VALUE, &err,
err_msg.c_str());
}

im.pixels.insert(im.pixels.end(), data,
data + im.width * im.height * im.pixel_size);

Expand All @@ -42,7 +54,7 @@ namespace sdk {
cl::util::detail::errHandler(CL_INVALID_ARG_VALUE, &err,
"File read error!");

if (error != NULL) *error = err;
if (error != nullptr) *error = err;
return im;
}

Expand Down
7 changes: 7 additions & 0 deletions samples/core/blur/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ add_sample(
VERSION 300
SOURCES main.c
KERNELS blur.cl)

add_sample(
TEST
TARGET blurcpp
VERSION 300
SOURCES main.cpp blur.cpp blur.hpp
KERNELS blur.cl)
Loading

0 comments on commit f510201

Please sign in to comment.