Click here to Skip to main content
15,895,777 members
Articles / Desktop Programming / MFC

ImageStone - A Powerful C++ Class Library for Image Manipulation

Rate me:
Please Sign up or sign in to vote.
4.81/5 (250 votes)
6 Dec 2011Zlib3 min read 120.6K   51.5K   405  
An article on a library for image manipulation
//-------------------------------------------------------------------------------------
/**
    Interface to create image codec.
*/
class FCImageCodecFactory
{
public:
    virtual ~FCImageCodecFactory() {}

    /**
        Get image's format by file's <b>ext name</b> default \n
        you can override this function to determine format from file's header.
    */
    virtual IMAGE_TYPE QueryImageFileType (const wchar_t* szFileName)
    {
        return GetTypeByFileExt(szFileName) ;
    }

    /// Get image's format by file's ext name.
    static IMAGE_TYPE GetTypeByFileExt (const wchar_t* szFileName)
    {
        if (!szFileName)
            return IMG_UNKNOW ;

        // get ext name of image file
        std::wstring   strExt ;
        {
            std::wstring   s (szFileName) ;
            size_t         nPos = s.find_last_of (L".") ;
            if (nPos != std::wstring::npos)
                strExt = s.substr (nPos + 1) ;
        }

        // convert to lowercase
        for (size_t i=0 ; i < strExt.length() ; i++)
        {
            if ((strExt[i] >= 'A') && (strExt[i] <= 'Z'))
                strExt[i] = (wchar_t)tolower(strExt[i]) ;
        }

        if (strExt == L"jpg")  return IMG_JPG ;
        if (strExt == L"jpeg") return IMG_JPG ;
        if (strExt == L"jpe")  return IMG_JPG ;
        if (strExt == L"jfif") return IMG_JPG ;
        if (strExt == L"gif")  return IMG_GIF ;
        if (strExt == L"bmp")  return IMG_BMP ;
        if (strExt == L"png")  return IMG_PNG ;
        if (strExt == L"tga")  return IMG_TGA ;
        if (strExt == L"tif")  return IMG_TIF ;
        if (strExt == L"tiff") return IMG_TIF ;
        if (strExt == L"ico")  return IMG_ICO ;
        if (strExt == L"psd")  return IMG_PSD ;
        if (strExt == L"pcx")  return IMG_PCX ;
        if (strExt == L"xpm")  return IMG_XPM ;
        if (strExt == L"oxo")  return IMG_PHOXO ;

        return IMG_UNKNOW ;
    }

    /**
        Create image codec by image type \n
        derived class must use <B>new</B> to create codec and return it \n
        user must use <B>delete</B> to delete returned codec.
    */
    virtual FCImageCodec* CreateImageCodec (IMAGE_TYPE imgType) =0 ;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Team Leader PhoXo
China China
graduate from University of Science and Technology of China at 2002.

Now I work at www.phoxo.com.

Comments and Discussions