9 #include <GL/freeglut.h>
68 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
69 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
71 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
72 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
74 glEnable(GL_TEXTURE_2D);
77 void loadNewTexture(
const char* data, GLint internalFormat,
size_t width,
size_t height, GLenum format, GLenum type)
79 _imageProperties.
data = data;
81 _imageProperties.
width = width;
82 _imageProperties.
height = height;
83 _imageProperties.
format = format;
84 _imageProperties.
type = type;
86 switch(_imageProperties.
format)
108 char* argv[2] = {(
char*)
"", NULL};
110 glutInit(&argc, argv);
111 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_RGBA | GLUT_MULTISAMPLE);
113 glutInitWindowPosition(0, 0);
114 #ifdef GLUT_ACTION_ON_WINDOW_CLOSE
115 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
118 _windowId = glutCreateWindow(
"AV Player Viewer");
119 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
120 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
125 glutMouseFunc(
mouse);
138 if(glutGetWindow() == 0)
140 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
141 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
182 if(glutGetModifiers() == GLUT_ACTIVE_SHIFT)
277 if(state == 0 && button == 0)
283 if(iX < 0 || iY < 0 || iX >= (
int)_imageProperties.
width || iY >= (
int)_imageProperties.
height)
286 std::cout <<
"at " << std::setw(4) << iX <<
"," << std::setw(4) << (int)_imageProperties.
height - iY <<
": ";
288 for(
size_t i = 0; i < _imageProperties.
component; i++)
290 size_t idx = (iX + iY * _imageProperties.
width) * _imageProperties.
component + i;
291 switch(_imageProperties.
type)
293 case GL_UNSIGNED_BYTE:
295 const unsigned char* d = (
const unsigned char*)_imageProperties.
data;
296 std::cout << std::setw(5) << (
unsigned int)d[idx];
299 case GL_UNSIGNED_SHORT:
301 const unsigned short* d = (
const unsigned short*)_imageProperties.
data;
302 std::cout << std::setw(7) << d[idx];
307 const float* d = (
const float*)_imageProperties.
data;
308 std::cout << std::setw(10) << d[idx];
313 std::cout << std::endl;
315 if(state == 0 && (button == 3 || button == 4))
317 int iX, iY, iX2, iY2;
346 float x_diff, y_diff;
371 float w, h, xPos, yPos;
378 yPos = 0.5f * (height - h);
384 xPos = 0.5f * (width - w);
393 glViewport((GLsizei)xPos, (GLsizei)yPos, (GLsizei)w, (GLsizei)h);
394 glutReshapeWindow(width, height);
399 static const std::string kViewerHelp =
400 "Av Player Viewer Help\n"
401 "i : information about image (dimensions, bit depth, channels) + video stream\n"
402 "z : zoom view to 1:1\n"
403 "h, F1 : print help\n"
406 "clic on image : print RGBA values\n"
407 "ESC, Return, Space : quit and continue process";
408 std::cout << kViewerHelp << std::endl;
413 std::string textureType;
414 switch(_imageProperties.
format)
417 textureType =
"Gray ";
420 textureType =
"RGB ";
423 textureType =
"RGBA ";
426 switch(_imageProperties.
type)
428 case GL_UNSIGNED_BYTE:
429 textureType +=
"8 bits";
431 case GL_UNSIGNED_SHORT:
432 textureType +=
"16 bits";
435 textureType +=
"32 float";
438 std::cout << textureType <<
" " <<
_width <<
"x" <<
_height << std::endl;
442 if(properties != NULL)
443 std::cout << *properties << std::endl;
472 mapY = _imageProperties.
height - mapY;
477 mapX = _imageProperties.
width - mapX;
480 mx = (float)mapX / (
float)_imageProperties.
width * 2.0 - 1.0;
483 my = (float)mapY / (
float)_imageProperties.
height * 2.0 - 1.0;
489 switch(_imageProperties.
format)
494 glPixelTransferf(GL_RED_SCALE, red);
495 glPixelTransferf(GL_GREEN_SCALE, green);
496 glPixelTransferf(GL_BLUE_SCALE, blue);
499 glPixelTransferf(GL_RED_SCALE, red);
500 glPixelTransferf(GL_GREEN_SCALE, green);
501 glPixelTransferf(GL_BLUE_SCALE, blue);
502 glPixelTransferf(GL_ALPHA_SCALE, alpha);
static void displayFirstFrame()
ImgProperties _imageProperties
static float _currentZoom
static bool _showBlueChannel
static void specialKeyboard(int k, int x, int y)
static bool _showAlphaChannel
static void displayInformations()
static void motion(int x, int y)
Window(avtranscoder::VideoReader &reader)
static void displayChannelTexture(bool &channel, const float red, const float green, const float blue)
static avtranscoder::VideoReader * _reader
static void mouse(int button, int state, int x, int y)
static void loopPlaying(int value)
size_t getOutputHeight() const
static void mapToImage(int x, int y, int &iX, int &iY)
static void reshape(int width, int height)
unsigned char ** getData()
Get all the data of the frame.
static void showAlphaChannelTexture()
static void displayPrevFrame()
static void setTransfert(float red, float green, float blue, float alpha=1.f)
static bool _showRedChannel
const VideoProperties * getSourceVideoProperties() const
static bool _showGreenChannel
Frame * readFrameAt(const size_t frame)
static void displayHelp()
static void showRedChannelTexture()
static void move(float x, float y)
void loadNewTexture(const ImgProperties &properties)
static void keyboard(unsigned char k, int x, int y)
static void displayAtFrame(const size_t frame)
static void showBlueChannelTexture()
size_t getOutputNbComponents() const
static void showGreenChannelTexture()
static void zoom(float factor)
static void displayNextFrame()
size_t getOutputWidth() const