Buffer.tcc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <iostream>
  2. namespace NICE {
  3. template<class BUFFER>
  4. BUFFER* createResultBuffer(const int width, const int height, BUFFER* buffer)
  5. {
  6. BUFFER* result;
  7. if(buffer == NULL)
  8. {
  9. result = new BUFFER(width, height);
  10. }
  11. else if(buffer->width()==0 && buffer->height()==0)
  12. {
  13. result = buffer;
  14. result->resize(width,height);
  15. }
  16. else
  17. {
  18. result = buffer;
  19. if (result->width() != width || result->height() != height)
  20. {
  21. fthrow(ImageException, "DeprecatedConverter: size of image is not equal to (width, height).");
  22. }
  23. }
  24. return result;
  25. }
  26. template<class IMG, class BUFFER>
  27. BUFFER* createResultBuffer(const IMG& image, BUFFER* buffer)
  28. {
  29. BUFFER* result;
  30. if (buffer == NULL)
  31. {
  32. result = new BUFFER(image.width(), image.height());
  33. }
  34. else if(buffer->width()==0 && buffer->height()==0)
  35. {
  36. result = buffer;
  37. result->resize(image.width(),image.height());
  38. }
  39. else
  40. {
  41. result = buffer;
  42. if (result->width() != image.width()
  43. || result->height() != image.height())
  44. {
  45. fthrow(ImageException, "DeprecatedConverter: size of image and buffer are not equal.");
  46. }
  47. }
  48. return result;
  49. }
  50. }