/***************************************************************************
                            QImageIO.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_QImageIO.h>
#include <qtobjc/QImageIO.h>
#include <qtobjc/QImage.h>

@implementation  QImageIO

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QImageIO()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithIODevice: (QIODevice *)ioDevice format: (NSString *)format
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QImageIO1((qt_QIODevice *) [ioDevice qt], (char*) [format cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)fileName format: (NSString *)format
{
static qt_QString * _qstring_fileName = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QImageIO2((qt_QString *) [fileName toQString: &_qstring_fileName], (char*) [format cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

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

- (int) status
{
	return (int) qt_QImageIO_status((qt_QImageIO *)[self qt]);
}

- (NSString *) format
{
	return (NSString *) [NSString stringWithCString: qt_QImageIO_format((qt_QImageIO *)[self qt])];
}

- (QIODevice*) ioDevice
{
	return (QIODevice*) [QtSupport objectForQtKey: qt_QImageIO_ioDevice((qt_QImageIO *)[self qt]) withClass: [QIODevice class] allocatedInObjcWorld: YES];
}

- (NSString *) fileName
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QImageIO_fileName((qt_QImageIO *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (int) quality
{
	return (int) qt_QImageIO_quality((qt_QImageIO *)[self qt]);
}

- (NSString *) description
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QImageIO_description((qt_QImageIO *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) parameters
{
	return (NSString *) [NSString stringWithCString: qt_QImageIO_parameters((qt_QImageIO *)[self qt])];
}

- (float) gamma
{
	return (float) qt_QImageIO_gamma((qt_QImageIO *)[self qt]);
}

- setImage: (QImage *)arg1
{
	qt_QImageIO_setImage((qt_QImageIO *)[self qt], (qt_QImage *) [arg1 qt]);
	return self;
}

- setStatus: (int)arg1
{
	qt_QImageIO_setStatus((qt_QImageIO *)[self qt], (int)arg1);
	return self;
}

- setFormat: (NSString *)arg1
{
	qt_QImageIO_setFormat((qt_QImageIO *)[self qt], (char*) [arg1 cString]);
	return self;
}

- setIODevice: (QIODevice *)arg1
{
	qt_QImageIO_setIODevice((qt_QImageIO *)[self qt], (qt_QIODevice *) [arg1 qt]);
	return self;
}

- setFileName: (NSString *)arg1
{
static qt_QString * _qstring_arg1 = 0L;
	qt_QImageIO_setFileName((qt_QImageIO *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1]);
	return self;
}

- setQuality: (int)arg1
{
	qt_QImageIO_setQuality((qt_QImageIO *)[self qt], (int)arg1);
	return self;
}

- setDescription: (NSString *)arg1
{
static qt_QString * _qstring_arg1 = 0L;
	qt_QImageIO_setDescription((qt_QImageIO *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1]);
	return self;
}

- setParameters: (NSString *)arg1
{
	qt_QImageIO_setParameters((qt_QImageIO *)[self qt], (char*) [arg1 cString]);
	return self;
}

- setGamma: (float)arg1
{
	qt_QImageIO_setGamma((qt_QImageIO *)[self qt], (float)arg1);
	return self;
}

- (BOOL) read
{
	return (BOOL) qt_QImageIO_read((qt_QImageIO *)[self qt]);
}

- (BOOL) write
{
	return (BOOL) qt_QImageIO_write((qt_QImageIO *)[self qt]);
}

+ (NSString *) imageFormatForFile: (NSString *)fileName
{
static qt_QString * _qstring_fileName = 0L;
	return (NSString *) [NSString stringWithCString: qt_QImageIO_imageFormat((qt_QString *) [fileName toQString: &_qstring_fileName])];
}

+ (NSString *) imageFormat: (QIODevice *)arg1
{
	return (NSString *) [NSString stringWithCString: qt_QImageIO_imageFormat1((qt_QIODevice *) [arg1 qt])];
}

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

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

+ defineIOHandler: (NSString *)format header: (NSString *)header flags: (NSString *)flags read_image: (int)read_image write_image: (int)write_image
{
	qt_QImageIO_defineIOHandler((char*) [format cString], (char*) [header cString], (char*) [flags cString], (int)read_image, (int)write_image);
	return self;
}

@end
