1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 #ifndef VOGLEDITOR_QTEXTUREVIEWER_H
27 #define VOGLEDITOR_QTEXTUREVIEWER_H
40 #include "vogl_core.h"
42 #include "vogl_mipmapped_texture.h"
43 #include "vogl_ktx_texture.h"
45 typedef enum ChannelSelectionOptions
53 VOGL_CSO_ONE_MINUS_RGBA,
54 VOGL_CSO_ONE_MINUS_RGB,
59 VOGL_CSO_ONE_OVER_RGBA,
60 VOGL_CSO_ONE_OVER_RGB,
65 } ChannelSelectionOption;
67 class QTextureViewer : public QWidget
71 explicit QTextureViewer(QWidget *parent = 0);
72 void paint(QPainter *painter, QPaintEvent *event);
74 void setTexture(const vogl::ktx_texture* pTexture, uint baseMipLevel, uint maxMipLevel);
76 void setChannelSelectionOption(ChannelSelectionOption channels)
78 if (m_channelSelection != channels)
81 m_channelSelection = channels;
88 m_draw_enabled = false;
90 m_mipmappedTexture.clear();
93 inline QColor getBackgroundColor() const { return m_background.color(); }
95 inline void setBackgroundColor(QBrush color)
97 m_draw_enabled = true;
103 double getZoomFactor() const { return m_zoomFactor; }
104 void setZoomFactor(double zoomFactor)
106 if (m_zoomFactor != zoomFactor)
108 m_zoomFactor = zoomFactor;
113 bool getInverted() const { return m_bInvert; }
114 void setInverted(bool bInvert)
116 if (m_bInvert != bInvert)
123 uint get_preferred_height() const
126 if (m_pKtxTexture != NULL)
128 height += (m_pKtxTexture->get_height() * m_zoomFactor);
137 ChannelSelectionOption m_channelSelection;
141 vogl::map<uint,QPixmap> m_pixmaps;
142 vogl::map<uint, vogl::color_quad_u8*> m_pixmapData;
144 const vogl::ktx_texture* m_pKtxTexture;
145 vogl::mipmapped_texture m_mipmappedTexture;
149 void delete_pixmaps()
152 for (vogl::map<uint, vogl::color_quad_u8*>::iterator iter = m_pixmapData.begin(); iter != m_pixmapData.end(); iter++)
154 delete [] iter->second;
157 m_pixmapData.clear();
160 void adjustChannels(ChannelSelectionOption selection, unsigned char& r, unsigned char& g, unsigned char& b, unsigned char& a);
163 void paintEvent(QPaintEvent *event);
171 #endif // VOGLEDITOR_QTEXTUREVIEWER_H