<commit_before>#include "imageviewwidget.h"

ImageViewWidget::ImageViewWidget(QWidget *parent) :
    QGraphicsView(parent)
{
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void ImageViewWidget::displayImage(cv::Mat_<double> image, bool scale)
{
    double inScale = 255.0;

    QImage dest(image.cols, image.rows, QImage::Format_ARGB32);
    for (int y = 0; y < image.rows; ++y) {
            const double *srcrow = image[y];
            QRgb *destrow = (QRgb*)dest.scanLine(y);
            for (int x = 0; x < image.cols; ++x) {
                    unsigned int color = (unsigned int)(srcrow[x] * inScale);
                    if(color<0) color = 0;
                    if(color>0) color = 255-color;
                    destrow[x] = qRgba(color, color, color, 255);
            }
    }

    if(scale){
        dest = dest.scaled(size(),Qt::KeepAspectRatio);
    }

    displayImage(dest);
}

void ImageViewWidget::displayImage(cv::Mat3b image, bool scale)
{

    QImage dest(image.cols, image.rows, QImage::Format_ARGB32);
    for (int y = 0; y < image.rows; ++y) {
            const cv::Vec3b *srcrow = image[y];
            QRgb *destrow = (QRgb*)dest.scanLine(y);
            for (int x = 0; x < image.cols; ++x) {
                    destrow[x] = qRgba(srcrow[x][2], srcrow[x][1], srcrow[x][0], 255);
            }
    }


    if(scale){
        dest = dest.scaled(size(),Qt::KeepAspectRatio);<commit_msg>trying to get ImageViewWidget to properly display 1-channel cv::Mat images ...failure<commit_after>#include "imageviewwidget.h"

ImageViewWidget::ImageViewWidget(QWidget *parent) :
    QGraphicsView(parent)
{
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

void ImageViewWidget::displayImage(cv::Mat_<double> image, bool scale)
{
    double inScale = 1.0;

    QImage dest(image.cols, image.rows, QImage::Format_ARGB32);
    for (int y = 0; y < image.rows; ++y) {
            const double *srcrow = image[y];
            QRgb *destrow = (QRgb*)dest.scanLine(y);
            for (int x = 0; x < image.cols; ++x) {
                    int color = 255u-(unsigned int)(srcrow[x] * inScale);
                    uint ucolor;
                    if(color<0) ucolor = 0;
                    else if(color>255) ucolor = 255;
                    else ucolor = 255-color;
                    destrow[x] = qRgba(ucolor, ucolor, ucolor, 255);
            }
    }

    if(scale){
        dest = dest.scaled(size(),Qt::KeepAspectRatio);
    }

    displayImage(dest);
}

void ImageViewWidget::displayImage(cv::Mat3b image, bool scale)
{

    QImage dest(image.cols, image.rows, QImage::Format_ARGB32);
    for (int y = 0; y < image.rows; ++y) {
            const cv::Vec3b *srcrow = image[y];
            QRgb *destrow = (QRgb*)dest.scanLine(y);
            for (int x = 0; x < image.cols; ++x) {
                    destrow[x] = qRgba(srcrow[x][2], srcrow[x][1], srcrow[x][0], 255);
            }
    }


    if(scale){
        dest = dest.scaled(size(),Qt::KeepAspectRatio);
{'fraction_non_alphanumeric': 0.14524421593830333, 'fraction_numerical': 0.020886889460154243, 'mean_word_length': 2.4059080962800876, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7623757', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1021, 'n_words': 212}