ImageOptions 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGDB_IMAGEOPTIONS
  14. #define OSGDB_IMAGEOPTIONS 1
  15. #include <osgDB/Options>
  16. namespace osgDB {
  17. class OSGDB_EXPORT ImageOptions : public osgDB::Options
  18. {
  19. public:
  20. ImageOptions();
  21. ImageOptions(const std::string& str);
  22. ImageOptions(const ImageOptions& options,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
  23. osgDB::Options(options,copyop),
  24. _sourceImageSamplingMode(options._sourceImageSamplingMode),
  25. _sourceImageWindowMode(options._sourceImageWindowMode),
  26. _sourceRatioWindow(options._sourceRatioWindow),
  27. _sourcePixelWindow(options._sourcePixelWindow),
  28. _destinationImage(options._destinationImage),
  29. _destinationImageWindowMode(options._destinationImageWindowMode),
  30. _destinationRatioWindow(options._destinationRatioWindow),
  31. _destinationPixelWindow(options._destinationPixelWindow),
  32. _destinationDataType(options._destinationDataType),
  33. _destinationPixelFormat(options._destinationPixelFormat) {}
  34. META_Object(osgDB,ImageOptions);
  35. /** RatioWindow stores the window (as ratios of 0.0 to 1.0) from the overall imagery from which to extract the osg::Image*/
  36. struct RatioWindow
  37. {
  38. RatioWindow():
  39. windowX(0.0),
  40. windowY(0.0),
  41. windowWidth(1.0),
  42. windowHeight(1.0) {}
  43. void set(double x, double y, double w, double h)
  44. {
  45. windowX = x;
  46. windowY = y;
  47. windowWidth = w;
  48. windowHeight = h;
  49. }
  50. double windowX;
  51. double windowY;
  52. double windowWidth;
  53. double windowHeight;
  54. };
  55. /** PixelWindow stores the window (in exact pixels) from the overall imagery from which to extract the osg::Image*/
  56. struct PixelWindow
  57. {
  58. PixelWindow():
  59. windowX(0),
  60. windowY(0),
  61. windowWidth(0),
  62. windowHeight(0) {}
  63. void set(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
  64. {
  65. windowX = x;
  66. windowY = y;
  67. windowWidth = w;
  68. windowHeight = h;
  69. }
  70. unsigned int windowX;
  71. unsigned int windowY;
  72. unsigned int windowWidth;
  73. unsigned int windowHeight;
  74. };
  75. enum ImageWindowMode
  76. {
  77. ALL_IMAGE,
  78. RATIO_WINDOW,
  79. PIXEL_WINDOW
  80. };
  81. enum ImageSamplingMode
  82. {
  83. NEAREST,
  84. LINEAR,
  85. CUBIC
  86. };
  87. /** Used as UserData attached to generated osg::Image's*/
  88. struct TexCoordRange : public osg::Referenced
  89. {
  90. TexCoordRange():
  91. _x(0.0),
  92. _y(0.0),
  93. _w(1.0),
  94. _h(1.0) {}
  95. void set(double x,double y, double w, double h)
  96. {
  97. _x = x;
  98. _y = y;
  99. _w = w;
  100. _h = h;
  101. }
  102. double _x,_y,_w,_h;
  103. protected:
  104. virtual ~TexCoordRange() {}
  105. };
  106. // source
  107. ImageSamplingMode _sourceImageSamplingMode;
  108. ImageWindowMode _sourceImageWindowMode;
  109. RatioWindow _sourceRatioWindow;
  110. PixelWindow _sourcePixelWindow;
  111. // destination
  112. osg::ref_ptr<osg::Image> _destinationImage;
  113. ImageWindowMode _destinationImageWindowMode;
  114. RatioWindow _destinationRatioWindow;
  115. PixelWindow _destinationPixelWindow;
  116. GLenum _destinationDataType;
  117. GLenum _destinationPixelFormat;
  118. void init();
  119. };
  120. }
  121. #endif // OSGDB_IMAGEOPTIONS