/* * Image.cpp * * Copyright (C) 1999 Stephen F. White * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file "COPYING" for details); if * not, write to the Free Software Foundation, Inc., 675 Mass Ave, * Cambridge, MA 02139, USA. */ #include "stdafx.h" #include "Image.h" #include "gif.h" #include "jpegLoad.h" #include "pngLoad.h" #include #include Image::Image() { } Image::~Image() { } char* Image::file_extension(const char *filename) { /* identify file extension by '.' */ int i; for (i=strlen(filename);(i>=0) && (filename[i]!='.');i--) {} return (char*)filename+i; } int Image::test_file_extension(char *extension) { /* copy extension and convert to lowercase */ char case_extension[5]; mystrncpy_secure(case_extension,extension+1,5); for (int i=0;i<=strlen(case_extension);i++) case_extension[i]=tolower(case_extension[i]); if (strcmp(case_extension,"jpeg")==0) return((int)JPEG); else if (strcmp(case_extension,"jfif")==0) return((int)JPEG); else if (strcmp(case_extension,"jpg")==0) return((int)JPEG); else if (strcmp(case_extension,"gif")==0) return((int)GIF); else if (strcmp(case_extension,"png")==0) return((int)PNG); else return(-1); } bool Image::Open(const char *filename) { _type=(Type)test_file_extension(file_extension(filename)); switch (_type) { default: /* no known fileextension, test all imagetypes */ case GIF: if (gifOpen(filename, &_width, &_height)) { _type = GIF; _components = 3; return true; } case JPEG: if (jpegOpen(filename, &_width, &_height, &_components)) { _type = JPEG; return true; } case PNG: if (pngOpen(filename, &_width, &_height, &_components)) { _type = PNG; return true; } } return false; } void Image::Read(unsigned char *data) { switch (_type) { case GIF: gifRead(data); break; case JPEG: jpegRead(data); break; case PNG: pngRead(data); break; // default: // assert(false); } }