You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "Raster.h"
#include "FreeImage.h"
namespace CELL { Image* Image::loadFromFile(const char* fileName) { //1 ��ȡͼƬ��ʽ
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(fileName, 0); if (fifmt == FIF_UNKNOWN) { return 0; } //2 ����ͼƬ
FIBITMAP *dib = FreeImage_Load(fifmt, fileName,0);
FREE_IMAGE_COLOR_TYPE type = FreeImage_GetColorType(dib);
//! ��ȡ����ָ��
FIBITMAP* temp = dib; dib = FreeImage_ConvertTo32Bits(dib); FreeImage_Unload(temp);
BYTE* pixels = (BYTE*)FreeImage_GetBits(dib); int width = FreeImage_GetWidth(dib); int height = FreeImage_GetHeight(dib);
int pitch = width*4; BYTE* row = new BYTE[width*4]; for(int j = 0; j < height / 2; j++) { memcpy(row,pixels + j * pitch,pitch );
memcpy(pixels + j * pitch,pixels + (height - j - 1) * pitch,pitch );
memcpy(pixels + (height - j - 1) * pitch,row,pitch );
} delete []row;
Image* image = new Image(width,height,pixels); FreeImage_Unload(dib);
return image; }
Raster::Raster( int w,int h,void* buffer ) { _width = w; _height = h; _buffer = (uint*)buffer; memset(&_poitionPointer,0, sizeof(_poitionPointer)); memset(&_colorPointer, 0, sizeof(_colorPointer)); memset(&_uvPointer, 0, sizeof(_uvPointer)); }
Raster::~Raster( void ) { }
void Raster::clear() { memset(_buffer,0,_width * _height * sizeof(Rgba)); } }
|