mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Initial Mercurial commit.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
// DevIL
|
||||
#include <IL/il.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace devil
|
||||
{
|
||||
Image::Image()
|
||||
{
|
||||
ilInit();
|
||||
}
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
ilShutDown();
|
||||
}
|
||||
|
||||
const char * Image::getName() const
|
||||
{
|
||||
return "love.image.devil";
|
||||
}
|
||||
|
||||
love::image::ImageData * Image::newImageData(love::filesystem::File * file)
|
||||
{
|
||||
return new ImageData(file);
|
||||
}
|
||||
|
||||
love::image::ImageData * Image::newImageData(int width, int height)
|
||||
{
|
||||
return new ImageData(width, height);
|
||||
}
|
||||
|
||||
} // devil
|
||||
} // image
|
||||
} // love
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_IMAGE_DEVIL_IMAGE_H
|
||||
#define LOVE_IMAGE_DEVIL_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include <image/Image.h>
|
||||
#include "ImageData.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace devil
|
||||
{
|
||||
class Image : public love::image::Image
|
||||
{
|
||||
public:
|
||||
|
||||
Image();
|
||||
~Image();
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
love::image::ImageData * newImageData(love::filesystem::File * file);
|
||||
love::image::ImageData * newImageData(int width, int height);
|
||||
|
||||
}; // Image
|
||||
|
||||
} // devil
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_IMAGE_DEVIL_IMAGE_H
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "ImageData.h"
|
||||
|
||||
// STD
|
||||
#include <iostream>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace devil
|
||||
{
|
||||
ImageData::ImageData(filesystem::File * file)
|
||||
{
|
||||
// Read the data.
|
||||
Data * data = file->read();
|
||||
|
||||
// Generate DevIL image.
|
||||
ilGenImages(1, &image);
|
||||
|
||||
// Bind the image.
|
||||
ilBindImage(image);
|
||||
|
||||
// Try to load the image.
|
||||
ILboolean success = ilLoadL(IL_TYPE_UNKNOWN, (void*)data->getData(), data->getSize());
|
||||
|
||||
// Free local image data.
|
||||
data->release();
|
||||
|
||||
// Check for errors
|
||||
if(!success)
|
||||
{
|
||||
std::cerr << "Could not decode image." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
width = ilGetInteger(IL_IMAGE_WIDTH);
|
||||
height = ilGetInteger(IL_IMAGE_HEIGHT);
|
||||
origin = ilGetInteger(IL_IMAGE_ORIGIN);
|
||||
|
||||
// Make sure the image is in RGBA format.
|
||||
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
|
||||
|
||||
// This should always be four.
|
||||
bpp = ilGetInteger(IL_IMAGE_BPP);
|
||||
|
||||
if(bpp != 4)
|
||||
{
|
||||
std::cerr << "Bits per pixel != 4" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ImageData::ImageData(int width, int height)
|
||||
: width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4)
|
||||
{
|
||||
// Generate DevIL image.
|
||||
ilGenImages(1, &image);
|
||||
|
||||
// Bind the image.
|
||||
ilBindImage(image);
|
||||
|
||||
ilTexImage(width, height, 0, bpp, IL_RGBA, IL_UNSIGNED_BYTE, 0);
|
||||
}
|
||||
|
||||
ImageData::~ImageData()
|
||||
{
|
||||
ilDeleteImages(1, &image);
|
||||
}
|
||||
|
||||
int ImageData::getWidth() const
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
int ImageData::getHeight() const
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
void * ImageData::getData() const
|
||||
{
|
||||
ilBindImage(image);
|
||||
return ilGetData();
|
||||
}
|
||||
|
||||
int ImageData::getSize() const
|
||||
{
|
||||
return width*height*bpp;
|
||||
}
|
||||
|
||||
void ImageData::setPixel(int x, int y, pixel c)
|
||||
{
|
||||
int tx = x > width-1 ? width-1 : x;
|
||||
int ty = y > height-1 ? height-1 : y;
|
||||
pixel * pixels = (pixel *)getData();
|
||||
pixels[y*width+x] = c;
|
||||
}
|
||||
|
||||
pixel ImageData::getPixel(int x, int y) const
|
||||
{
|
||||
int tx = x > width-1 ? width-1 : x;
|
||||
int ty = y > height-1 ? height-1 : y;
|
||||
pixel * pixels = (pixel *)getData();
|
||||
return pixels[y*width+x];
|
||||
}
|
||||
|
||||
} // devil
|
||||
} // image
|
||||
} // love
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_DEVIL_IMAGE_DATA_H
|
||||
#define LOVE_DEVIL_IMAGE_DATA_H
|
||||
|
||||
// LOVE
|
||||
#include <filesystem/File.h>
|
||||
#include <image/ImageData.h>
|
||||
|
||||
// DevIL
|
||||
#include <IL/il.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
namespace devil
|
||||
{
|
||||
class ImageData : public love::image::ImageData
|
||||
{
|
||||
private:
|
||||
|
||||
// The width of the image data.
|
||||
int width;
|
||||
|
||||
// The height of the image data.
|
||||
int height;
|
||||
|
||||
// The origin of the image.
|
||||
int origin;
|
||||
|
||||
// The bits per pixel.
|
||||
int bpp;
|
||||
|
||||
// DevIL image identifier.
|
||||
ILuint image;
|
||||
|
||||
public:
|
||||
|
||||
ImageData(love::filesystem::File * file);
|
||||
ImageData(int width, int height);
|
||||
virtual ~ImageData();
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
// Implements ImageData.
|
||||
int getWidth() const ;
|
||||
int getHeight() const ;
|
||||
void setPixel(int x, int y, pixel c);
|
||||
pixel getPixel(int x, int y) const;
|
||||
|
||||
}; // ImageData
|
||||
|
||||
} // devil
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_DEVIL_IMAGE_DATA_H
|
||||
Reference in New Issue
Block a user