/***************************************************************************
                            QImageDecoder.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QImageDecoder.h>
#include <qtobjc/QImageDecoder.h>

@implementation  QImageDecoder

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- initWithImageConsumer: (QImageConsumer*)c
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QImageDecoder((qt_QImageConsumer*) [c qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QImageDecoder((qt_QImageDecoder *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (QImage*) image
{
	return (QImage*) [QtSupport objectForQtKey: qt_QImageDecoder_image((qt_QImageDecoder *)[self qt]) withClass: [QImage class] allocatedInObjcWorld: YES];
}

- (int) decode: (unsigned char*)buffer length: (int)length
{
	return (int) qt_QImageDecoder_decode((qt_QImageDecoder *)[self qt], (unsigned char*)buffer, (int)length);
}

+ (NSString *) formatName: (unsigned char*)buffer length: (int)length
{
	return (NSString *) [NSString stringWithCString: qt_QImageDecoder_formatName((unsigned char*)buffer, (int)length)];
}

+ (QImageFormatType*) format: (NSString *)name
{
	return (QImageFormatType*) [QtSupport objectForQtKey: qt_QImageDecoder_format((char*) [name cString]) withClass: [QImageFormatType class] allocatedInObjcWorld: YES];
}

+ (NSArray *) inputFormats
{
static qt_QStrList * _qlist = 0L;
	_qlist = qt_QImageDecoder_inputFormats();
	return (NSArray *) [NSMutableArray arrayWithQStrList: _qlist];
}

+ registerDecoderFactory: (QImageFormatType*)arg1
{
	qt_QImageDecoder_registerDecoderFactory((qt_QImageFormatType*) [arg1 qt]);
	return self;
}

+ unregisterDecoderFactory: (QImageFormatType*)arg1
{
	qt_QImageDecoder_unregisterDecoderFactory((qt_QImageFormatType*) [arg1 qt]);
	return self;
}

@end
