1 /* 2 * This file Copyright (C) 2010 Christopher Stamm 3 * Fachhochschule Nordwestschweiz 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE 7 * as published by the Free Software Foundation; either version 2.1 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 20 #pragma once 21 22 #include "PGFimage.h" 23 #include <iostream> 24 25 /////////////////////////////////////////////////////////////////////////////////// 26 // CPNM: PNM image document class. Supports PBM, PGM, and PPM images. 27 class CPNM { 28 // attributes 29 UINT8 *m_buffer; // uncompressed image buffer 30 int m_pitch; // number of bytes per row 31 int m_w, m_h; // width and height in pixel 32 int m_mode; // image type 33 int m_bpp; // bits per pixel 34 int m_maxValue; // maximum value in image data 35 36 protected: 37 // operations 38 bool ReadP1(std::istream& in); 39 bool ReadP2(std::istream& in); 40 bool ReadP3(std::istream& in); 41 bool ReadP4(std::istream& in); 42 bool ReadP5(std::istream& in); 43 bool ReadP6(std::istream& in); 44 45 bool WriteP1(std::ostream& out); 46 bool WriteP2(std::ostream& out); 47 bool WriteP3(std::ostream& out); 48 bool WriteP4(std::ostream& out); 49 bool WriteP5(std::ostream& out); 50 bool WriteP6(std::ostream& out); 51 52 public: 53 CPNM(); 54 virtual ~CPNM(); 55 56 bool ReadPNM(CPGFImage& pgf, int quality, int levels, bool roi, bool alpha); 57 bool WritePNM(CPGFImage& pgf, bool roi, PGFRect& rect, bool binary = true); 58 59 // class methods 60 static bool ReadMagic(std::istream& in, int& type); 61 static bool ReadSize(std::istream& in, int& width, int& height); 62 static bool ReadMaxValue(std::istream& in, int& maxValue); 63 static bool ImportIsSupported(BYTE mode); 64 static void FillInColorTable(RGBQUAD* table, int size); 65 static void SkipComments(std::istream& in); 66 }; 67 68