XPlor/app/imagepreviewwidget.h
njohnson be3ff9303b Add image preview widget with Xbox 360 texture support (WIP)
Add ImagePreviewWidget class for previewing texture assets:
- TGA image loading (uncompressed and RLE)
- Xbox 360 XBTX2D texture format support (work in progress)
- DXT1/DXT5 block decompression
- Xbox 360 texture untiling using SDK algorithms
- Scroll-to-zoom and drag-to-pan functionality
- Debug export to PNG for development

The Xbox 360 texture decoding is still a work in progress and
needs further research for proper implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 16:35:49 -05:00

64 lines
1.5 KiB
C++

#ifndef IMAGEPREVIEWWIDGET_H
#define IMAGEPREVIEWWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QPixmap>
#include <QImage>
#include <QMouseEvent>
class ImagePreviewWidget : public QWidget
{
Q_OBJECT
public:
explicit ImagePreviewWidget(QWidget *parent = nullptr);
~ImagePreviewWidget() = default;
// Load image from raw bytes (TGA, PNG, etc.)
bool loadFromData(const QByteArray &data, const QString &format = QString());
// Load image from file path
bool loadFromFile(const QString &path);
// Set the filename for display
void setFilename(const QString &filename);
// Get current image size
QSize imageSize() const;
// Export current displayed image as PNG for debugging
bool exportDebugImage(const QString &suffix = QString());
protected:
// Mouse events for drag-to-pan
bool eventFilter(QObject *obj, QEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
private:
QLabel *mImageLabel;
QLabel *mInfoLabel;
QScrollArea *mScrollArea;
QString mFilename;
QSize mImageSize;
// Drag-to-pan state
bool mDragging;
QPoint mLastDragPos;
// Zoom state
double mZoomFactor;
QPixmap mOriginalPixmap;
void updateZoom();
// Try to load TGA manually if Qt can't handle it
QImage loadTGA(const QByteArray &data);
// Load Xbox 360 XBTX2D texture format
QImage loadXBTX2D(const QByteArray &data);
};
#endif // IMAGEPREVIEWWIDGET_H