comparison tools/libgfx.c @ 2154:1c111bfc17d4

Add check to PNG and PPM output as well.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Jun 2019 15:56:10 +0300
parents 7652b3fe8f30
children e6ec7fad9ce2
comparison
equal deleted inserted replaced
2153:7652b3fe8f30 2154:1c111bfc17d4
768 int dmWritePPMImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) 768 int dmWritePPMImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec)
769 { 769 {
770 DMImageConvSpec tmpSpec; 770 DMImageConvSpec tmpSpec;
771 char *tmpFmt; 771 char *tmpFmt;
772 772
773 // Check if we can do this
774 if ((spec->format == DM_COLFMT_PALETTE || spec->format == DM_COLFMT_GRAYSCALE) &&
775 img->format != spec->format)
776 {
777 return dmError(DMERR_NOT_SUPPORTED,
778 "Conversion of non-indexed image to indexed not supported yet.\n");
779 }
780
773 memcpy(&tmpSpec, spec, sizeof(DMImageConvSpec)); 781 memcpy(&tmpSpec, spec, sizeof(DMImageConvSpec));
774 782
775 switch (spec->format) 783 switch (spec->format)
776 { 784 {
777 case DM_COLFMT_RGB: 785 case DM_COLFMT_RGB:
969 int dmWritePNGImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) 977 int dmWritePNGImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec)
970 { 978 {
971 png_structp png_ptr = NULL; 979 png_structp png_ptr = NULL;
972 png_infop info_ptr = NULL; 980 png_infop info_ptr = NULL;
973 int fmt, res; 981 int fmt, res;
982
983 // Check if we can do this
984 if ((spec->format == DM_COLFMT_PALETTE || spec->format == DM_COLFMT_GRAYSCALE) &&
985 img->format != spec->format)
986 {
987 return dmError(DMERR_NOT_SUPPORTED,
988 "Conversion of non-indexed image to indexed not supported yet.\n");
989 }
974 990
975 // Create PNG structures 991 // Create PNG structures
976 png_ptr = png_create_write_struct( 992 png_ptr = png_create_write_struct(
977 PNG_LIBPNG_VER_STRING, 993 PNG_LIBPNG_VER_STRING,
978 NULL, NULL, NULL); 994 NULL, NULL, NULL);