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.

78 lines
2.3 KiB

5 years ago
  1. #include "Raster.h"
  2. #include "FreeImage.h"
  3. namespace CELL
  4. {
  5. Image* Image::loadFromFile(const char* fileName)
  6. {
  7. //1 ��ȡͼƬ��ʽ
  8. FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(fileName, 0);
  9. if (fifmt == FIF_UNKNOWN)
  10. {
  11. return 0;
  12. }
  13. //2 ����ͼƬ
  14. FIBITMAP *dib = FreeImage_Load(fifmt, fileName,0);
  15. FREE_IMAGE_COLOR_TYPE type = FreeImage_GetColorType(dib);
  16. //! ��ȡ����ָ��
  17. FIBITMAP* temp = dib;
  18. dib = FreeImage_ConvertTo32Bits(dib);
  19. FreeImage_Unload(temp);
  20. BYTE* pixels = (BYTE*)FreeImage_GetBits(dib);
  21. int width = FreeImage_GetWidth(dib);
  22. int height = FreeImage_GetHeight(dib);
  23. int pitch = width*4;
  24. BYTE* row = new BYTE[width*4];
  25. for(int j = 0; j < height / 2; j++)
  26. {
  27. memcpy(row,pixels + j * pitch,pitch );
  28. memcpy(pixels + j * pitch,pixels + (height - j - 1) * pitch,pitch );
  29. memcpy(pixels + (height - j - 1) * pitch,row,pitch );
  30. }
  31. delete []row;
  32. Image* image = new Image(width,height,pixels);
  33. FreeImage_Unload(dib);
  34. return image;
  35. }
  36. Raster::Raster( int w,int h,void* buffer )
  37. {
  38. _texture = 0;
  39. _width = w;
  40. _height = h;
  41. _buffer = (uint*)buffer;
  42. memset(&_poitionPointer,0, sizeof(_poitionPointer));
  43. memset(&_colorPointer, 0, sizeof(_colorPointer));
  44. memset(&_uvPointer, 0, sizeof(_uvPointer));
  45. _defaultColorPointer._size = 4;
  46. _defaultColorPointer._type = DT_BYTE;
  47. _defaultColorPointer._stride= sizeof(Rgba);
  48. _defaultColorPointer._data = _defaultColorArray;
  49. _defaultUVPointer._size = 2;
  50. _defaultUVPointer._type = DT_FLOAT;
  51. _defaultUVPointer._stride = sizeof(float2);
  52. _defaultUVPointer._data = _detaultUVArray;
  53. _matModel = CELL::matrix4(1);
  54. }
  55. Raster::~Raster( void )
  56. {
  57. }
  58. void Raster::clear()
  59. {
  60. memset(_buffer,0,_width * _height * sizeof(Rgba));
  61. }
  62. }