color type

Help
2007-06-19
2013-04-23
  • hello,
    I get the message "warning: input file is of unsupported type (bad color type).
    when using readfromfile().

    I printed the color type, and got 6.  Can you tell me what color types are supported, and if there's a way I can change the file's color type? 

    Pngwriter is Great Stuff by the way.

    -Bryan

     
    • Paul Blackburn
      Paul Blackburn
      2007-06-19

      Hi,

      As the manual states, PNGwriter works with images of bit depth 8 or 16, with no alpha channel. Try processing your image with Imagemagick or Photoshop to ensure this is the case.

      I should note that, according to a PNGwriter user, there is a bug in the way images are loaded. See:

      https://sourceforge.net/forum/message.php?msg_id=4259199

      I should mention that I have had no problems loading image files of the required type, though. This will probably be changed in the next version. To be honest, I am not sure what effects this bug has.

      Cheers,

      Paul

       
    • Hello
      I had the same problem with greyscale images. After looking at the post from Sven I made the following change to the code. All the code that makes input transformations need to be before the read_png_image and the header information needs to read again if any transformation has been done.

      Thanks PNGwritter is great

      Mikkel

      if(!read_png_info(fp, &png_ptr, &info_ptr))
           {
          std::cerr << " PNGwriter::readfromfile - ERROR **: Error opening file " << name << ". read_png_info() failed." << std::endl;
          // fp has been closed already if read_png_info() fails.
          return;
           }

          //Input transformations
          png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
          bit_depth_ = bit_depth;
          colortype_ = color_type;

         
         if(color_type == PNG_COLOR_TYPE_PALETTE /*&& bit_depth<8*/)
           {
          png_set_expand(png_ptr);
          transformation_ = 1;
           }

         if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth<8)
           {
          png_set_expand(png_ptr);
          transformation_ = 1;
           }

         if(color_type & PNG_COLOR_MASK_ALPHA)
           {
          png_set_strip_alpha(png_ptr);
          transformation_ = 1;
           }

         if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_RGB_ALPHA)
           {
          png_set_gray_to_rgb(png_ptr);
          transformation_ = 1;
           }
         if(transformation_)
          {
          png_set_gray_to_rgb(png_ptr);
          png_read_update_info(png_ptr, info_ptr);
          png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type,    NULL, NULL);
          bit_depth_ = bit_depth;
          colortype_ = color_type;
          }
        
          
         if(!read_png_image(fp, png_ptr, info_ptr, &image, &width, &height))
           {
          std::cerr << " PNGwriter::readfromfile - ERROR **: Error opening file " << name << ". read_png_image() failed." << std::endl;
          // fp has been closed already if read_png_image() fails.
          return;
           }

         //stuff should now be in image[][].