/*
 * ImageInfo.cpp
 *
 * (c) 2002 by Thorsten Scheuermann <tscheuermann@gmx.net>
 *
 * 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.
 */

#include "ImageInfo.h"
#include "ImageReader.h"
#include "ImageReaderFactory.h"

ImageInfo::ImageInfo(const char *fileName, bool createThumbnail)
: width(0), height(0), theRotation(ROTATION_NONE)
{
  int pos;
  ImageReader *reader;

  thePathName = fileName;
  pos = thePathName.findRev('/');
  if(pos == -1)
  {
    theFileName = thePathName;
    thePathName = "";
  }
  else
  {
    theFileName = thePathName.mid(pos+1);
    thePathName = thePathName.left(pos);
  }

  // read image information
  reader = ImageReaderFactory::getReader(fileName);
  if(!reader)
    return;
  width = reader->imageWidth();
  height = reader->imageHeight();
  
  if(createThumbnail)
  {
  }
  delete reader;

  // we might want to read the file size and date too

}

ImageInfo::~ImageInfo()
{
}

QString ImageInfo::fullFileName()
{
  return thePathName + '/' + theFileName;
}

QString ImageInfo::fileName()
{
  return theFileName;
}

QString ImageInfo::pathName()
{
  return thePathName;
}

void ImageInfo::rotateCW()
{
  switch(theRotation)
  {
  case ROTATION_NONE:
    theRotation = ROTATION_90;
    break;

  case ROTATION_90:
    theRotation = ROTATION_180;
    break;

  case ROTATION_180:
    theRotation = ROTATION_270;
    break;

  case ROTATION_270:
    theRotation = ROTATION_NONE;
    break;
  }
}

void ImageInfo::rotateCCW()
{
  switch(theRotation)
  {
  case ROTATION_NONE:
    theRotation = ROTATION_270;
    break;

  case ROTATION_90:
    theRotation = ROTATION_NONE;
    break;

  case ROTATION_180:
    theRotation = ROTATION_90;
    break;

  case ROTATION_270:
    theRotation = ROTATION_180;
    break;
  }
}
