QTPainter.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: QTPainter.cpp
37 // Author: Pedram Azad, Moritz Ritter
38 // Date: 08.05.2008
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include "QTPainter.h"
47 #include "Image/ByteImage.h"
48 
49 #include <stdio.h>
50 #include <qimage.h>
51 
52 
53 
54 // ****************************************************************************
55 // Constructor / Destructor
56 // ****************************************************************************
57 
58 CQTPainter::CQTPainter(QPaintDevice *pd) : QPainter(pd)
59 {
60  m_pBuffer = 0;
61 
62  m_nImageWidth = -1;
63  m_nImageHeight = -1;
64 }
65 
67 {
68  if (m_pBuffer)
69  delete [] m_pBuffer;
70 }
71 
72 
73 // ****************************************************************************
74 // Methods
75 // ****************************************************************************
76 
77 void CQTPainter::DrawImage(const CByteImage *pImage, int x, int y)
78 {
79  WriteToBuffer(pImage);
80 
81  #if QT_VERSION >= 0x040000
82  QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, QImage::Format_RGB32);
83  #else
84  QImage image(m_pBuffer, m_nImageWidth, m_nImageHeight, 32, 0, 0, QImage::BigEndian);
85  #endif
86 
87  drawImage(x, y, image);
88 }
89 
91 {
92  if (m_nImageWidth != pImage->width || m_nImageHeight != pImage->height)
93  {
94  m_nImageWidth = pImage->width;
95  m_nImageHeight = pImage->height;
96 
97  if (m_pBuffer)
98  delete [] m_pBuffer;
99 
100  m_pBuffer = new unsigned char[m_nImageWidth * m_nImageHeight * sizeof(int)];
101  }
102 
103  if (pImage->type == CByteImage::eGrayScale)
104  {
105  const int nPixels = m_nImageWidth * m_nImageHeight;
106  unsigned char *pixels = pImage->pixels;
107  int *output = (int *) m_pBuffer;
108 
109  for (int i = 0; i < nPixels; i++)
110  output[i] = 255 << 24 | pixels[i] << 16 | pixels[i] << 8 | pixels[i];
111  }
112  else if (pImage->type == CByteImage::eRGB24)
113  {
114  const int nPixels = m_nImageWidth * m_nImageHeight;
115  unsigned char *pixels = pImage->pixels;
116  int *output = (int *) m_pBuffer;
117 
118  for (int offset = 0, i = 0; i < nPixels; i++)
119  {
120  output[i] = 255 << 24 | pixels[offset] << 16 | pixels[offset + 1] << 8 | pixels[offset + 2];
121  offset += 3;
122  }
123  }
124 }
int width
The width of the image in pixels.
Definition: ByteImage.h:257
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3131
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
GLintptr offset
Definition: glext.h:3389
unsigned char * pixels
The pointer to the the pixels.
Definition: ByteImage.h:283
int m_nImageHeight
Definition: QTPainter.h:88
GLenum GLint x
Definition: glext.h:3125
CQTPainter(QPaintDevice *pd)
Definition: QTPainter.cpp:58
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glext.h:3154
int height
The height of the image in pixels.
Definition: ByteImage.h:264
int m_nImageWidth
Definition: QTPainter.h:87
ImageType type
The type of the image.
Definition: ByteImage.h:292
GLenum GLint GLint y
Definition: glext.h:3125
void WriteToBuffer(const CByteImage *pImage)
Definition: QTPainter.cpp:90
void DrawImage(const CByteImage *pImage, int x=0, int y=0)
Definition: QTPainter.cpp:77
unsigned char * m_pBuffer
Definition: QTPainter.h:85


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28