16acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn/*M///////////////////////////////////////////////////////////////////////////////////////
26acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
36acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
46acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
56acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  By downloading, copying, installing or using the software you agree to this license.
66acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  If you do not agree to this license, do not download, install,
76acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//  copy or use the software.
86acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
96acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//                        Intel License Agreement
116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//                For Open Source Computer Vision Library
126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Copyright (C) 2000, Intel Corporation, all rights reserved.
146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Third party copyrights are property of their respective owners.
156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// Redistribution and use in source and binary forms, with or without modification,
176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// are permitted provided that the following conditions are met:
186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * Redistribution's of source code must retain the above copyright notice,
206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     this list of conditions and the following disclaimer.
216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * Redistribution's in binary form must reproduce the above copyright notice,
236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     this list of conditions and the following disclaimer in the documentation
246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     and/or other materials provided with the distribution.
256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//   * The name of Intel Corporation may not be used to endorse or promote products
276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//     derived from this software without specific prior written permission.
286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// This software is provided by the copyright holders and contributors "as is" and
306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// any express or implied warranties, including, but not limited to, the implied
316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// warranties of merchantability and fitness for a particular purpose are disclaimed.
326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// In no event shall the Intel Corporation or contributors be liable for any direct,
336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// indirect, incidental, special, exemplary, or consequential damages
346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// (including, but not limited to, procurement of substitute goods or services;
356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// loss of use, data, or profits; or business interruption) however caused
366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// and on any theory of liability, whether in contract, strict liability,
376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// or tort (including negligence or otherwise) arising in any way out of
386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn// the use of this software, even if advised of the possibility of such damage.
396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//
406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn//M*/
416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn#include "_highgui.h"
436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn#include "grfmt_base.h"
456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn#include "bitstrm.h"
466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtReader::GrFmtReader( const char* filename )
496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    strncpy( m_filename, filename, sizeof(m_filename) - 1 );
516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_filename[sizeof(m_filename)-1] = '\0';
526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_width = m_height = 0;
536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_iscolor = false;
546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_bit_depth = 8;
556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_native_depth = false;
566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_isfloat = false;
576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtReader::~GrFmtReader()
616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    Close();
636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennvoid GrFmtReader::Close()
676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_width = m_height = 0;
696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_iscolor = false;
706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtWriter::GrFmtWriter( const char* filename )
746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    strncpy( m_filename, filename, sizeof(m_filename) - 1 );
766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_filename[sizeof(m_filename)-1] = '\0';
776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennbool  GrFmtWriter::IsFormatSupported( int depth )
816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return depth == IPL_DEPTH_8U;
836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtFilterFactory::GrFmtFilterFactory()
876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_description = m_signature = 0;
896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_sign_len = 0;
906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennbool  GrFmtFilterFactory::CheckFile( const char* filename )
946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	FILE* f = 0;
966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	char signature[4096];
976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	int sign_len = 0;
986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	int cur_sign_len = GetSignatureLength();
996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	if( !filename ) return false;
1016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	assert( cur_sign_len <= (int)sizeof( signature ) );
1036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	f = fopen( filename, "rb" );
1046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	if( f )
1066acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	{
1076acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		sign_len = (int)fread( signature, 1, cur_sign_len, f );
1086acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		fclose( f );
1096acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		if( cur_sign_len <= sign_len && CheckSignature( signature ) )
1116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            return true;
1126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	}
1136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	return false;
1156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
1166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennbool GrFmtFilterFactory::CheckSignature( const char* signature )
1196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
1206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return m_sign_len > 0 && signature != 0 &&
1216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn           memcmp( signature, m_signature, m_sign_len ) == 0;
1226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
1236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennstatic int GetExtensionLength( const char* buffer )
1266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
1276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int len = 0;
1286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( buffer )
1306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
1316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        const char* ext = strchr( buffer, '.');
1326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( ext++ )
1336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            while( isalnum(ext[len]) && len < _MAX_PATH )
1346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                len++;
1356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
1366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return len;
1386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
1396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennbool GrFmtFilterFactory::CheckExtension( const char* format )
1426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
1436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    const char* descr = 0;
1446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    int len = 0;
1456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( !format || !m_description )
1476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        return false;
1486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    // find the right-most extension of the passed format string
1506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    for(;;)
1516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
1526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        const char* ext = strchr( format + 1, '.' );
1536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( !ext ) break;
1546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        format = ext;
1556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
1566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    len = GetExtensionLength( format );
1586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( format[0] != '.' || len == 0 )
1606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        return false;
1616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    descr = strchr( m_description, '(' );
1636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    while( descr )
1656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
1666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        descr = strchr( descr + 1, '.' );
1676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        int i, len2 = GetExtensionLength( descr );
1686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( len2 == 0 )
1706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            break;
1716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( len2 == len )
1736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
1746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            for( i = 0; i < len; i++ )
1756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            {
1766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                int c1 = tolower(format[i+1]);
1776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                int c2 = tolower(descr[i+1]);
1786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                if( c1 != c2 )
1806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                    break;
1816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            }
1826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            if( i == len )
1836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn                return true;
1846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }
1856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
1866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return false;
1886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
1896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn///////////////////// GrFmtFilterList //////////////////////////
1936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
1946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtFactoriesList::GrFmtFactoriesList()
1956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
1966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_factories = 0;
1976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    RemoveAll();
1986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
1996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtFactoriesList::~GrFmtFactoriesList()
2026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    RemoveAll();
2046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2066acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2076acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennvoid  GrFmtFactoriesList::RemoveAll()
2086acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2096acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( m_factories )
2106acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
2116acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        for( int i = 0; i < m_curFactories; i++ ) delete m_factories[i];
2126acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        delete[] m_factories;
2136acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
2146acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_factories = 0;
2156acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_maxFactories = m_curFactories = 0;
2166acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2176acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2186acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2196acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Rennbool  GrFmtFactoriesList::AddFactory( GrFmtFilterFactory* factory )
2206acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2216acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    assert( factory != 0 );
2226acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( m_curFactories == m_maxFactories )
2236acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
2246acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        // reallocate the factorys pointers storage
2256acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        int newMaxFactories = 2*m_maxFactories;
2266acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( newMaxFactories < 16 ) newMaxFactories = 16;
2276acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2286acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        GrFmtFilterFactory** newFactories = new GrFmtFilterFactory*[newMaxFactories];
2296acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2306acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        for( int i = 0; i < m_curFactories; i++ ) newFactories[i] = m_factories[i];
2316acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2326acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        delete[] m_factories;
2336acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        m_factories = newFactories;
2346acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        m_maxFactories = newMaxFactories;
2356acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
2366acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2376acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    m_factories[m_curFactories++] = factory;
2386acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return true;
2396acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2406acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2416acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2426acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennListPosition  GrFmtFactoriesList::GetFirstFactoryPos()
2436acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2446acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return (ListPosition)m_factories;
2456acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2466acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2476acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2486acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtFilterFactory* GrFmtFactoriesList::GetNextFactory( ListPosition& pos )
2496acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2506acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    GrFmtFilterFactory* factory = 0;
2516acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    GrFmtFilterFactory** temp = (GrFmtFilterFactory**)pos;
2526acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2536acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    assert( temp == 0 || (m_factories <= temp && temp < m_factories + m_curFactories));
2546acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( temp )
2556acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
2566acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        factory = *temp++;
2576acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        pos = (ListPosition)(temp < m_factories + m_curFactories ? temp : 0);
2586acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
2596acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return factory;
2606acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2616acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2626acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2636acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtReader* GrFmtFactoriesList::FindReader( const char* filename )
2646acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2656acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	if( !filename ) return 0;
2666acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2676acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	GrFmtReader* reader = 0;
2686acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	ListPosition pos = GetFirstFactoryPos();
2696acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2706acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	while( pos )
2716acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	{
2726acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		GrFmtFilterFactory* tempFactory = GetNextFactory( pos );
2736acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		if( tempFactory->CheckFile( filename ) )
2746acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		{
2756acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn			reader = tempFactory->NewReader( filename );
2766acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn			break;
2776acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn		}
2786acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn	}
2796acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2806acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return reader;
2816acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
2826acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2836acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2846acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius RennGrFmtWriter* GrFmtFactoriesList::FindWriter( const char* filename )
2856acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn{
2866acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    GrFmtWriter* writer = 0;
2876acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    ListPosition pos = GetFirstFactoryPos();
2886acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2896acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    if( !filename ) return 0;
2906acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
2916acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    while( pos )
2926acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    {
2936acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        GrFmtFilterFactory* tempFactory = GetNextFactory(pos);
2946acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        if( tempFactory->CheckExtension( filename ))
2956acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        {
2966acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            writer = tempFactory->NewWriter( filename );
2976acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn            break;
2986acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn        }
2996acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    }
3006acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3016acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn    return writer;
3026acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn}
3036acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
3046acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn/* End of file. */
3056acb9a7ea3d7564944e12cbc73a857b88c1301eeMarius Renn
306