|
| 1 | +#include "color/icc.h" |
| 2 | + |
| 3 | +#include <stdbool.h> |
| 4 | +#include <stdint.h> |
| 5 | + |
| 6 | +#include "arena/arena.h" |
| 7 | +#include "arena/common.h" |
| 8 | +#include "color/icc_color.h" |
| 9 | +#include "err/error.h" |
| 10 | +#include "logger/log.h" |
| 11 | +#include "parse_ctx/ctx.h" |
| 12 | + |
| 13 | +int main(void) { |
| 14 | + Arena* arena = arena_new(128); |
| 15 | + |
| 16 | + size_t swop_buffer_len; |
| 17 | + const uint8_t* swop_buffer = load_file_to_buffer( |
| 18 | + arena, |
| 19 | + "assets/icc-profiles/CGATS001Compat-v2-micro.icc", |
| 20 | + &swop_buffer_len |
| 21 | + ); |
| 22 | + |
| 23 | + size_t srgb_buffer_len; |
| 24 | + const uint8_t* srgb_buffer = load_file_to_buffer( |
| 25 | + arena, |
| 26 | + "assets/icc-profiles/sRGB_v4_ICC_preference.icc", |
| 27 | + &srgb_buffer_len |
| 28 | + ); |
| 29 | + |
| 30 | + ParseCtx swop_ctx = parse_ctx_new(swop_buffer, swop_buffer_len); |
| 31 | + IccProfile swop_profile; |
| 32 | + REQUIRE(icc_parse_profile(swop_ctx, arena, &swop_profile)); |
| 33 | + |
| 34 | + ParseCtx srgb_ctx = parse_ctx_new(srgb_buffer, srgb_buffer_len); |
| 35 | + IccProfile srgb_profile; |
| 36 | + REQUIRE(icc_parse_profile(srgb_ctx, arena, &srgb_profile)); |
| 37 | + |
| 38 | + IccColor input = { |
| 39 | + .channels = {0.4, 0.5, 0.6, 0.2}, |
| 40 | + .color_space = ICC_COLOR_SPACE_CMYK |
| 41 | + }; |
| 42 | + |
| 43 | + LOG_DIAG( |
| 44 | + INFO, |
| 45 | + EXAMPLE, |
| 46 | + "Naive conversion: %f, %f, %f", |
| 47 | + (1.0 - input.channels[0]) * (1.0 - input.channels[3]), |
| 48 | + (1.0 - input.channels[1]) * (1.0 - input.channels[3]), |
| 49 | + (1.0 - input.channels[2]) * (1.0 - input.channels[3]) |
| 50 | + ); |
| 51 | + |
| 52 | + IccRenderingIntent intent = ICC_INTENT_PERCEPTUAL; |
| 53 | + |
| 54 | + IccPcsColor src_pcs, dst_pcs; |
| 55 | + REQUIRE(icc_device_to_pcs(swop_profile, intent, input, &src_pcs)); |
| 56 | + REQUIRE(icc_pcs_to_pcs( |
| 57 | + swop_profile, |
| 58 | + srgb_profile, |
| 59 | + false, |
| 60 | + intent, |
| 61 | + src_pcs, |
| 62 | + &dst_pcs |
| 63 | + )); |
| 64 | + |
| 65 | + IccColor mapped_color; |
| 66 | + REQUIRE(icc_pcs_to_device(&srgb_profile, intent, dst_pcs, &mapped_color)); |
| 67 | + RELEASE_ASSERT(mapped_color.color_space == ICC_COLOR_SPACE_RGB); |
| 68 | + |
| 69 | + LOG_DIAG( |
| 70 | + INFO, |
| 71 | + EXAMPLE, |
| 72 | + "Output sRGB: r=%f, g=%f, b=%f", |
| 73 | + mapped_color.channels[0], |
| 74 | + mapped_color.channels[1], |
| 75 | + mapped_color.channels[2] |
| 76 | + ); |
| 77 | + |
| 78 | + arena_free(arena); |
| 79 | + return 0; |
| 80 | +} |
0 commit comments