Skip to content

Commit

Permalink
COMMON: Added more float formats
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Oct 1, 2023
1 parent 44b3c0f commit dbe4423
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/libsail-common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ enum SailPixelFormat {
SAIL_PIXEL_FORMAT_BPP64_ABGR,

/*
* Float formats.
* 32-bit single-precision floating point formats.
*/
SAIL_PIXEL_FORMAT_BPP16_FLOAT,
SAIL_PIXEL_FORMAT_BPP32_FLOAT,
SAIL_PIXEL_FORMAT_BPP64_FLOAT,
SAIL_PIXEL_FORMAT_BPP96_FLOAT,
SAIL_PIXEL_FORMAT_BPP128_FLOAT,

/*
* CMYK formats.
Expand Down
8 changes: 6 additions & 2 deletions src/libsail-common/common_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ const char* sail_pixel_format_to_string(enum SailPixelFormat pixel_format) {
case SAIL_PIXEL_FORMAT_BPP64_ARGB: return "BPP64-ARGB";
case SAIL_PIXEL_FORMAT_BPP64_ABGR: return "BPP64-ABGR";

case SAIL_PIXEL_FORMAT_BPP16_FLOAT: return "BPP16-FLOAT";
case SAIL_PIXEL_FORMAT_BPP32_FLOAT: return "BPP32-FLOAT";
case SAIL_PIXEL_FORMAT_BPP64_FLOAT: return "BPP64-FLOAT";
case SAIL_PIXEL_FORMAT_BPP96_FLOAT: return "BPP96-FLOAT";
case SAIL_PIXEL_FORMAT_BPP128_FLOAT: return "BPP128-FLOAT";

case SAIL_PIXEL_FORMAT_BPP32_CMYK: return "BPP32-CMYK";
case SAIL_PIXEL_FORMAT_BPP64_CMYK: return "BPP64-CMYK";
Expand Down Expand Up @@ -208,8 +210,10 @@ enum SailPixelFormat sail_pixel_format_from_string(const char *str) {
case UINT64_C(8244605671673531226): return SAIL_PIXEL_FORMAT_BPP64_ARGB;
case UINT64_C(8244605671673513818): return SAIL_PIXEL_FORMAT_BPP64_ABGR;

case UINT64_C(13817569922789251633): return SAIL_PIXEL_FORMAT_BPP16_FLOAT;
case UINT64_C(13817570002860265711): return SAIL_PIXEL_FORMAT_BPP32_FLOAT;
case UINT64_C(13817570133298530580): return SAIL_PIXEL_FORMAT_BPP64_FLOAT;
case UINT64_C(13817570263736795449): return SAIL_PIXEL_FORMAT_BPP96_FLOAT;
case UINT64_C(13257949525762847397): return SAIL_PIXEL_FORMAT_BPP128_FLOAT;

case UINT64_C(8244605667720923565): return SAIL_PIXEL_FORMAT_BPP32_CMYK;
case UINT64_C(8244605671673598258): return SAIL_PIXEL_FORMAT_BPP64_CMYK;
Expand Down
6 changes: 4 additions & 2 deletions src/libsail-common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ unsigned sail_bits_per_pixel(enum SailPixelFormat pixel_format) {
case SAIL_PIXEL_FORMAT_BPP64_ARGB:
case SAIL_PIXEL_FORMAT_BPP64_ABGR: return 64;

case SAIL_PIXEL_FORMAT_BPP16_FLOAT: return 16;
case SAIL_PIXEL_FORMAT_BPP32_FLOAT: return 32;
case SAIL_PIXEL_FORMAT_BPP32_FLOAT: return 32;
case SAIL_PIXEL_FORMAT_BPP64_FLOAT: return 64;
case SAIL_PIXEL_FORMAT_BPP96_FLOAT: return 96;
case SAIL_PIXEL_FORMAT_BPP128_FLOAT: return 128;

case SAIL_PIXEL_FORMAT_BPP32_CMYK: return 32;
case SAIL_PIXEL_FORMAT_BPP64_CMYK: return 64;
Expand Down
16 changes: 12 additions & 4 deletions tests/sail-common/bytes_per_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,22 @@ static MunitResult test_float(const MunitParameter params[], void *user_data) {
(void)params;
(void)user_data;

/* 16-bit FLOAT. */
munit_assert(sail_bytes_per_line(10, SAIL_PIXEL_FORMAT_BPP16_FLOAT) == 20);
munit_assert(sail_bytes_per_line(11, SAIL_PIXEL_FORMAT_BPP16_FLOAT) == 22);

/* 32-bit FLOAT. */
munit_assert(sail_bytes_per_line(10, SAIL_PIXEL_FORMAT_BPP32_FLOAT) == 40);
munit_assert(sail_bytes_per_line(11, SAIL_PIXEL_FORMAT_BPP32_FLOAT) == 44);

/* 64-bit FLOAT. */
munit_assert(sail_bytes_per_line(10, SAIL_PIXEL_FORMAT_BPP64_FLOAT) == 80);
munit_assert(sail_bytes_per_line(11, SAIL_PIXEL_FORMAT_BPP64_FLOAT) == 88);

/* 96-bit FLOAT. */
munit_assert(sail_bytes_per_line(10, SAIL_PIXEL_FORMAT_BPP96_FLOAT) == 120);
munit_assert(sail_bytes_per_line(11, SAIL_PIXEL_FORMAT_BPP96_FLOAT) == 132);

/* 128-bit FLOAT. */
munit_assert(sail_bytes_per_line(10, SAIL_PIXEL_FORMAT_BPP128_FLOAT) == 160);
munit_assert(sail_bytes_per_line(11, SAIL_PIXEL_FORMAT_BPP128_FLOAT) == 176);

return MUNIT_OK;
}

Expand Down
12 changes: 8 additions & 4 deletions tests/sail-common/integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ static MunitResult test_pixel_format_to_string(const MunitParameter params[], vo
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP64_ARGB), "BPP64-ARGB");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP64_ABGR), "BPP64-ABGR");

munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP16_FLOAT), "BPP16-FLOAT");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP32_FLOAT), "BPP32-FLOAT");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP32_FLOAT), "BPP32-FLOAT");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP64_FLOAT), "BPP64-FLOAT");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP96_FLOAT), "BPP96-FLOAT");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP128_FLOAT), "BPP128-FLOAT");

munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP32_CMYK), "BPP32-CMYK");
munit_assert_string_equal(sail_pixel_format_to_string(SAIL_PIXEL_FORMAT_BPP64_CMYK), "BPP64-CMYK");
Expand Down Expand Up @@ -230,8 +232,10 @@ static MunitResult test_pixel_format_from_string(const MunitParameter params[],
munit_assert(sail_pixel_format_from_string("BPP64-ARGB") == SAIL_PIXEL_FORMAT_BPP64_ARGB);
munit_assert(sail_pixel_format_from_string("BPP64-ABGR") == SAIL_PIXEL_FORMAT_BPP64_ABGR);

munit_assert(sail_pixel_format_from_string("BPP16-FLOAT") == SAIL_PIXEL_FORMAT_BPP16_FLOAT);
munit_assert(sail_pixel_format_from_string("BPP32-FLOAT") == SAIL_PIXEL_FORMAT_BPP32_FLOAT);
munit_assert(sail_pixel_format_from_string("BPP32-FLOAT") == SAIL_PIXEL_FORMAT_BPP32_FLOAT);
munit_assert(sail_pixel_format_from_string("BPP64-FLOAT") == SAIL_PIXEL_FORMAT_BPP64_FLOAT);
munit_assert(sail_pixel_format_from_string("BPP96-FLOAT") == SAIL_PIXEL_FORMAT_BPP96_FLOAT);
munit_assert(sail_pixel_format_from_string("BPP128-FLOAT") == SAIL_PIXEL_FORMAT_BPP128_FLOAT);

munit_assert(sail_pixel_format_from_string("BPP32-CMYK") == SAIL_PIXEL_FORMAT_BPP32_CMYK);
munit_assert(sail_pixel_format_from_string("BPP64-CMYK") == SAIL_PIXEL_FORMAT_BPP64_CMYK);
Expand Down

0 comments on commit dbe4423

Please sign in to comment.