Skip to content

Commit

Permalink
PNM: Added pnm-ascii special property
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Nov 16, 2023
1 parent 32a87a9 commit 24beca8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion FORMATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@
<b>Indexed:</b> 1-bit, 8-bit.
<b>RGB:</b> 24-bit, 48-bit.
<br/><br/>
<b>Content:</b> Static.
<b>Content:</b> Static, Meta data.
<br/><br/>
<b>Special properties:</b> Key: <i>"pnm-ascii"</i>. Description: True if the image pixels are encoded in ASCII mode.
Possible values: bool.
</td>
<td>-</td>
<td>Unsupported</td>
Expand Down
23 changes: 23 additions & 0 deletions src/sail-codecs/pnm/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,26 @@ enum SailPixelFormat pnm_private_rgb_sail_pixel_format(enum SailPnmVersion pnm_v
}
}

sail_status_t pnm_private_store_ascii(enum SailPnmVersion pnm_version, struct sail_hash_map *special_properties) {

struct sail_variant *variant;
SAIL_TRY(sail_alloc_variant(&variant));

switch (pnm_version) {
case SAIL_PNM_VERSION_P1:
case SAIL_PNM_VERSION_P2:
case SAIL_PNM_VERSION_P3: {
sail_set_variant_bool(variant, true);
}

default: {
sail_set_variant_bool(variant, false);
}
}

sail_put_hash_map(special_properties, "pnm-ascii", variant);

sail_destroy_variant(variant);

return SAIL_OK;
}
2 changes: 2 additions & 0 deletions src/sail-codecs/pnm/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ SAIL_HIDDEN sail_status_t pnm_private_read_pixels(struct sail_io *io, struct sai

SAIL_HIDDEN enum SailPixelFormat pnm_private_rgb_sail_pixel_format(enum SailPnmVersion pnm_version, unsigned bpc);

SAIL_HIDDEN sail_status_t pnm_private_store_ascii(enum SailPnmVersion pnm_version, struct sail_hash_map *special_properties);

#endif
8 changes: 8 additions & 0 deletions src/sail-codecs/pnm/pnm.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ SAIL_EXPORT sail_status_t sail_codec_load_seek_next_frame_v8_pnm(void *state, st

image_local->source_image->pixel_format = pixel_format;
image_local->source_image->compression = SAIL_COMPRESSION_NONE;

if (pnm_state->load_options->options & SAIL_OPTION_META_DATA) {
SAIL_TRY_OR_CLEANUP(sail_alloc_hash_map(&image_local->source_image->special_properties),
/* cleanup */ sail_destroy_image(image_local));
SAIL_TRY_OR_CLEANUP(pnm_private_store_ascii(pnm_state->version,
image_local->source_image->special_properties),
/* cleanup */ sail_destroy_image(image_local));
}
}

image_local->width = w;
Expand Down
2 changes: 1 addition & 1 deletion src/sail-codecs/pnm/pnm.codec.info.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extensions=pbm;pgm;ppm;pnm
mime-types=image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-portable-anymap

[load-features]
features=STATIC;SOURCE-IMAGE
features=STATIC;META-DATA;SOURCE-IMAGE
tuning=

[save-features]
Expand Down

0 comments on commit 24beca8

Please sign in to comment.