Skip to content

Add pixel_format to libisyntax api. libisyntax_tile_read() now takes an external buffer.#24

Merged
Falcury merged 2 commits intomainfrom
pixel-format-in-api
Apr 28, 2023
Merged

Add pixel_format to libisyntax api. libisyntax_tile_read() now takes an external buffer.#24
Falcury merged 2 commits intomainfrom
pixel-format-in-api

Conversation

@alex-virodov
Copy link
Copy Markdown
Collaborator

The buffer allocation is now on the caller, as discussed in #4 (comment)

I tested with the other (wrong) format in isyntax_example, it worked with colors properly switched (from quick visual examination).

Note: isyntax_streamer.c is not adjusted for the changes.

…an external buffer.

isyntax_streamer.c is not adjusted for the changes.
Comment thread src/isyntax_example.c Outdated
@@ -70,18 +66,16 @@ int main(int argc, char** argv) {
assert(libisyntax_cache_create("example cache", 2000, &isyntax_cache) == LIBISYNTAX_OK);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets optimized out in Release builds (we should place the call outside the assert).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, with CHECK_LIBISYNTAX_OK() macro that calls assert separately.

FYI the code was failing tests in release, thank you for catching this, I will test with release too.

Comment thread src/isyntax_example.c Outdated
assert(libisyntax_tile_read(isyntax, isyntax_cache, level, tile_x, tile_y, &pixels) == LIBISYNTAX_OK);
// RGBA is what stbi expects.
uint32_t *pixels_rgba = malloc(tile_width * tile_height * 4);
assert(libisyntax_tile_read(isyntax, isyntax_cache, level, tile_x, tile_y,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gets optimized out in Release builds.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, with CHECK_LIBISYNTAX_OK().

Comment thread src/isyntax/isyntax.c

*/


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already is ASSERT() from common.h, should we use that instead or should we replace all ASSERT() with assert()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to use common.h ASSERT().

(I have slight preference to standard solutions, but it is best being consistent with the existing codebase. This file uses ASSERT(), so I'll do the same).

} isyntax_cache_t;

uint32_t* isyntax_read_tile_bgra(isyntax_t* isyntax, isyntax_cache_t* cache, int scale, int tile_x, int tile_y);
// TODO(avirodov): can this ever fail?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so, e.g. if the decompression of the codeblocks fails (for example, if trying to decompress corrupt
or garbage codeblock). I guess we should probably detect that and escalate that up the call chain?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. I prefer to defer this problem to when we need to virtualize the filesystem access (see openslide/openslide#437 (comment), maybe will be needed soon). Then we can figure out what errors the virtual FS can return, how to propogate them, and how to expose them here.

So for now I'll leave it as a todo.

@alex-virodov
Copy link
Copy Markdown
Collaborator Author

PTAL again, thank you.

@Falcury Falcury merged commit 1e750aa into main Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants