Пример #1
0
void diff_images(QImage *image1, QImage *image2, QString fileName)
{
    // TODO: Check images size

    QImage* image3 = new QImage(image1->size(), QImage::Format_RGB32);

    for (int i = 0; i < image1->size().width(); i++) {
        for (int j = 0; j < image1->size().height(); j++) {
            int p1 = qGray(image1->pixel(i,j));
            int p2 = qGray(image2->pixel(i,j));
            int p3 = p1-p2;
            double fSigma = 0.4 * 25.0;
            double diff = (static_cast<double>(p3)+ fSigma) * 255.0 / (2.0 * fSigma);
            if (diff < 0.0) diff = 0;
            if (diff > 255.5) diff = 255;
            p3 = diff;
            image3->setPixel(i,j,qRgb(p3,p3,p3));
        }
    }

    QImageWriter* imageDiff = new QImageWriter();
    imageDiff->setFileName(fileName);
    imageDiff->write(*image3);

    delete image3;
    delete imageDiff;
}
Пример #2
0
void KIconEffect::toGray(QImage &img, float value)
{
    if (value == 0.0) {
        return;
    }

    KIEImgEdit ii(img);
    QRgb *data = ii.data;
    QRgb *end = data + ii.pixels;

    unsigned char gray;
    if (value == 1.0) {
        while (data != end) {
            gray = qGray(*data);
            *data = qRgba(gray, gray, gray, qAlpha(*data));
            ++data;
        }
    } else {
        unsigned char val = (unsigned char)(255.0 * value);
        while (data != end) {
            gray = qGray(*data);
            *data = qRgba((val * gray + (0xFF - val) * qRed(*data)) >> 8,
                          (val * gray + (0xFF - val) * qGreen(*data)) >> 8,
                          (val * gray + (0xFF - val) * qBlue(*data)) >> 8,
                          qAlpha(*data));
            ++data;
        }
    }
}
Пример #3
0
void UIMachineView::dimImage(QImage &img)
{
    for (int y = 0; y < img.height(); ++ y)
    {
        if (y % 2)
        {
            if (img.depth() == 32)
            {
                for (int x = 0; x < img.width(); ++ x)
                {
                    int gray = qGray(img.pixel (x, y)) / 2;
                    img.setPixel(x, y, qRgb (gray, gray, gray));
                }
            }
            else
            {
                ::memset(img.scanLine (y), 0, img.bytesPerLine());
            }
        }
        else
        {
            if (img.depth() == 32)
            {
                for (int x = 0; x < img.width(); ++ x)
                {
                    int gray = (2 * qGray (img.pixel (x, y))) / 3;
                    img.setPixel(x, y, qRgb (gray, gray, gray));
                }
            }
        }
    }
}
Пример #4
0
void sliders_group::update_img() {

   // slider->setValue(value);
    int i, j ;
   // this->setTitle(QString::number(value));

    QImage threshold_img(*img);
    for (i = 0; i < img->width(); i++) {
        for (j = 0; j < img->height(); j++) {
            int pixel_intensity = qGray(img->pixel(i,j));
            threshold_img.setPixel(i,j,qRgb(0,0,0));

            if (pixel_intensity > slider1_value) {
                threshold_img.setPixel(i,j,qRgb(255/2,0,0));
            }
            if (pixel_intensity > slider2_value) {
                int th_pixel_intensity = qGray(img->pixel(i,j));
                threshold_img.setPixel(i,j,qRgb(th_pixel_intensity,th_pixel_intensity,255/2));
            }
        }
    }

    threshold_img_label->setPixmap(QPixmap::fromImage(threshold_img));


}
Пример #5
0
bool WBMPReader::writeImage(QImage image)
{
    if (image.format() != QImage::Format_Mono)
        image = image.convertToFormat(QImage::Format_Mono);

    if (image.colorTable().at(0) == image.colorTable().at(1)) {
        // degenerate image: actually blank.
        image.fill((qGray(image.colorTable().at(0)) < 128) ? 0 : 1);
    } else if (qGray(image.colorTable().at(0)) > qGray(image.colorTable().at(1))) {
        // Conform to WBMP's convention about black and white
        image.invertPixels();
    }

    hdr.type = 0;
    hdr.format = 0;
    hdr.width = image.width();
    hdr.height = image.height();

    if (!writeWBMPHeader(iodev, hdr))
        return false;

    if (!writeWBMPData(iodev, image))
        return false;

    return true;
}
Пример #6
0
int Widget::getConnectedComponentLabeling()
{
    int i, j;
    int currlabel = 1;
    int label;
    int a[4];
    for(j=1; j<rsltImg.height()-1; j++){
        for(i=1; i<rsltImg.width()-1; i++){
            // 8 connected
            if( qGray(rsltImg.pixel(i,j)) != 0 )
            {
                a[0] = qGray(rsltImg.pixel(i-1,j-1));
                a[1] = qGray(rsltImg.pixel(i,j-1));
                a[2] = qGray(rsltImg.pixel(i+1,j-1));
                a[3] = qGray(rsltImg.pixel(i-1,j));

                label = MyMin(a);

                if(label != 0 && label != 255){
                    rsltImg.setPixel(i, j, qRgb(label, label, label));
                }
                else{
                    rsltImg.setPixel(i, j, qRgb(currlabel, currlabel, currlabel));
                    currlabel++;
                }
            }
        }
    }
    return (currlabel-1);
}
void CustomizeThemeDialog::toggleCustomColors(bool b)
{
	qDebug() << Q_FUNC_INFO << b;
	SettingsPrivate *settings = SettingsPrivate::instance();
	settings->setCustomColors(b);
	for (int i = 0; i < customColorsGridLayout->rowCount(); i++) {
		for (int j = 0; j < customColorsGridLayout->columnCount(); j++) {
			QLayoutItem *item = customColorsGridLayout->itemAtPosition(i, j);
			if (item->widget()) {
				item->widget()->setEnabled(b);
			}
		}
	}
	if (b) {
		qDebug() << Q_FUNC_INFO << settings->customColors(QPalette::Base) << settings->customColors(QPalette::Highlight);

		bgPrimaryColorWidget->setColor(settings->customColors(QPalette::Base));
		selectedItemColorWidget->setColor(settings->customColors(QPalette::Highlight));
	} else {
		QColor base = style()->standardPalette().base().color();
		QColor highlight = style()->standardPalette().highlight().color();
		int gray = qGray(base.rgb());
		bgPrimaryColorWidget->setColor(QColor(gray, gray, gray));
		gray = qGray(highlight.rgb());
		selectedItemColorWidget->setColor(QColor(gray, gray, gray));
		QApplication::setPalette(style()->standardPalette());
	}
}
Пример #8
0
//-----------------------------------------------------------------------------
QVariant ctkVTKColorTransferFunction::maxValue()const
{
  Q_D(const ctkVTKColorTransferFunction);
  if (d->ColorTransferFunction.GetPointer() == 0)
    {
    //Q_ASSERT(d->ColorTransferFunction.GetPointer());
    logger.warn("no ColorTransferFunction");
    return -1;
    }
  double rgb[3];
  QColor minValue = QColor::fromRgbF(0.,0.,0.);
  for (int i = 0; i < this->count(); ++i)
    {
    d->ColorTransferFunction->GetColor(i, rgb);
    Q_ASSERT(rgb[0] >= 0. && rgb[0] <= 1. &&
             rgb[1] >= 0. && rgb[1] <= 1. &&
             rgb[2] >= 0. && rgb[2] <= 1.);
    QColor color = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
    if ( qGray(color.red(), color.green(), color.blue()) >
         qGray(minValue.red(), minValue.green(), minValue.blue()))
      {
      minValue = color;
      }
    }
  return minValue;
}
Пример #9
0
void dimImage(QImage& image)
{
    /* Todo: factor out the < 32bit case, cause this can be done a lot faster
     * by just processing every second line. */
    for (int y = 0; y < image.height(); ++y)
    {
        QRgb *sl = (QRgb*)image.scanLine(y);
        if (y % 2)
        {
            if (image.depth() == 32)
            {
                for (int x = 0; x < image.width(); ++x)
                {
                    const int gray = qGray(sl[x]) / 2;
                    sl[x] = qRgba(gray, gray, gray, qAlpha(sl[x]));
                }
            }
            else
                ::memset(sl, 0, image.bytesPerLine());
        }
        else
        {
            if (image.depth() == 32)
            {
                for (int x = 0; x < image.width(); ++x)
                {
                    const int gray = (2 * qGray(sl[x])) / 3;
                    sl[x] = qRgba(gray, gray, gray, qAlpha(sl[x]));
                }
            }
        }
    }
}
Пример #10
0
int Etude::verifierToleranceNiveauxDeGris(const QRgb& couleurCourante, const QRgb& couleurReference,
        const int& seuilToleranceNiveauxDeGris) const
{
    if (qGray(couleurCourante) < (qGray(couleurReference) - seuilToleranceNiveauxDeGris))
        return NIVEAU_DE_GRIS_INFERIEUR;
    else if (qGray(couleurCourante) > (qGray(couleurReference) + seuilToleranceNiveauxDeGris))
        return NIVEAU_DE_GRIS_SUPERIEUR;
    return NIVEAU_DE_GRIS_COMPATIBLE;
}
/** Returns a size x size part of the image centered around (x,y) */
math::matrix<double> Transformation::getWindow(int x, int y, int size,
                                               Channel channel,
                                               Mode mode = RepeatEdge)
{
    math::matrix<double> window(size, size);

    int columnCount = floor(size/2);

    int a = 0;
    int b = 0;

    if(size % 2 == 0)
    {
        for (int i = -columnCount; i < columnCount; i++)
        {
            for (int j = -columnCount; j < columnCount; j++)
            {
                if(channel == RChannel)
                    window(a, b) = qRed(getPixel(x + i, y + j, mode));
                else if(channel == GChannel)
                    window(a, b) = qGreen(getPixel(x + i, y + j, mode));
                else if(channel == BChannel)
                    window(a, b) = qBlue(getPixel(x + i, y + j, mode));
                else if(channel == LChannel)
                    window(a, b) = qGray(getPixel(x + i, y + j, mode));
                b++;
            }
            a++;
            b = 0;
        }
    }
    else
    {
        for (int i = -columnCount; i <= columnCount; i++)
        {
            for (int j = -columnCount; j <= columnCount; j++)
            {
                if(channel == RChannel)
                    window(a, b) = qRed(getPixel(x + i, y + j, mode));
                else if(channel == GChannel)
                    window(a, b) = qGreen(getPixel(x + i, y + j, mode));
                else if(channel == BChannel)
                    window(a, b) = qBlue(getPixel(x + i, y + j, mode));
                else if(channel == LChannel)
                    window(a, b) = qGray(getPixel(x + i, y + j, mode));
                b++;
            }
            a++;
            b = 0;
        }
    }

    return window;
}
Пример #12
0
QImage Pdf::binarization(QImage image){
      QImage bw = QImage(image.width(), image.height(), QImage::Format_MonoLSB);
      QVector<QRgb> ct(2);
      ct[0] = qRgb(255, 255, 255);
      ct[1] = qRgb(0, 0, 0);
      bw.setColorTable(ct);
      bw.fill(0);
      float thresh = 128;
      float new_thresh = 0;
      
      while (thresh != new_thresh) {
            float sum_black = 0;
            float sum_white = 0;
            int num_black = 0;
            int num_white = 0;
            new_thresh = thresh;
            for (int x = 0; x < image.width(); x++){
                  for (int y = 0; y < image.height(); y++) {
                        QRgb c = image.pixel(x, y);
                        float g = qGray(c);
                        if (g < thresh) {
                              sum_black += g;
                              num_black++;
                              }
                        else {
                              sum_white += g;
                              num_white++;
                              }
                        
                        }
                  }
            thresh = (sum_black/num_black + sum_white/num_white)/2.0;
            }
      
      int stride  = (bw.width() + 7) / 8;
      uchar* p    = bw.bits();
        
      for (int y = 0; y < bw.height(); ++y) {
            p = bw.scanLine(y);
            for (int x = 0; x < stride; ++x) {
                  int temp = 0;
                  for (int i = 0; i < 8; i++) {
                        if (x*8 + i >= bw.width()) continue;
                        QRgb c = image.pixel(x*8 + i, y);
                        float g = qGray(c);
                        temp += ((g<thresh) ? 1:0)<<i;
                        }
                  *p++ = temp;
                  }
            }
      return bw;
}
Пример #13
0
int Sobel::calculateSobel(ushort x, ushort y)
{
    int pixels[9]; //Pixels around the scoped pixel
    //get the pixel values
    // 0 1 2
    // 3 4 5
    // 6 7 8
    pixels[0] = qGray(image->pixel(x - 1, y - 1));
    pixels[1] = qGray(image->pixel(x, y - 1));
    pixels[2] = qGray(image->pixel(x + 1, y - 1));
    pixels[3] = qGray(image->pixel(x - 1, y));
    //pixels[4] is not needed
    pixels[5] = qGray(image->pixel(x + 1, y));
    pixels[6] = qGray(image->pixel(x - 1, y + 1));
    pixels[7] = qGray(image->pixel(x, y + 1));
    pixels[8] = qGray(image->pixel(x + 1, y + 1));

    //TODO Check if optimization is needed
    int hsobel = pixels[0] + (pixels[3] * 2) + pixels[6]
            - pixels[2] - (pixels[5] * 2) - pixels[8];
    int vsobel = pixels[0] + (pixels[1] * 2) + pixels[3]
             - pixels[6] - (pixels[7] * 2) - pixels[8];

    int res = vsobel + hsobel;
    if(res < 0) {res *= -1;}
    return res;
}
Пример #14
0
int Widget::countLabelNm()
{
    int i, j, k;
    int buffer[255];
    int cnt = 0;

    // find how many labels.
    for(j=0; j<rsltImg.height()-1; j++){
        for(i=0; i<rsltImg.width()-1; i++){
            if(qGray(rsltImg.pixel(i,j)) != 0){
                if(cnt == 0){
                    buffer[cnt++] = qGray(rsltImg.pixel(i,j));
                }
                else{
                    for(k=0; k<cnt; k++){
                        if(buffer[k] == qGray(rsltImg.pixel(i,j))){
                            break;
                        }
                    }
                    if(k == cnt){
                        buffer[cnt++] = qGray(rsltImg.pixel(i,j));
                    }
                }
            }
        }
    }

    // draw all labels.
    unsigned char red, green, blue;

    for(k=0; k<cnt; k++)
    {
        red = rand()%256; // 0~255
        green = rand()%256;
        blue = rand()%256;

        for(j=0; j<rsltImg.height()-1; j++)
        {
            for(i=0; i<rsltImg.width()-1; i++)
            {
                if(qGray(rsltImg.pixel(i,j)) == buffer[k])
                {
                    rsltImg.setPixel(i, j, qRgb(red, green, blue));
                }
            }
        }
    }

    return cnt;
}
Пример #15
0
/*
    Code from http://www.dewtell.com/code/cpp/sobel.htm
    Given image in source place Sobel edges in dest.
    Grayscale sort of, with (255,255,255) as brightest edge.
    sobelDestination should be same size and depth as source.
*/
QImage BlurDetect::sobelEdgeDetect(const QImage& source) {
    QImage sobelEdges(source.size(), source.format());
    int GX[3][3];
    int GY[3][3];

    /* 3x3 GX Sobel mask.  Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
    GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
    GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
    GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;

    /* 3x3 GY Sobel mask.  Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
    GY[0][0] =  1; GY[0][1] =  2; GY[0][2] =  1;
    GY[1][0] =  0; GY[1][1] =  0; GY[1][2] =  0;
    GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1;

    int width = source.width();
    int height = source.height();
    int I, J;
    long sumX, sumY;
    int SUM;
    QRgb color;

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if ( y == 0 || y >= height-1 || x == 0 || x >= width-1 ) {
                SUM = 0;
            }
            else {
                sumX = 0;
                sumY = 0;
                /*-------X and Y GRADIENT APPROXIMATION------*/
                for(I=-1; I<=1; I++) {
                    for(J=-1; J<=1; J++) {
                        color = source.pixel(x+I, y+J);
                        sumX += qGray(color) * GX[I+1][J+1];
                        sumY += qGray(color) * GY[I+1][J+1];
                    }
                }
                SUM = abs(sumX) + abs(sumY); /*---GRADIENT MAGNITUDE APPROXIMATION (Myler p.218)----*/
                if (SUM > 255) {
                    SUM = 255;
                }

            }
            sobelEdges.setPixel(x,y,qRgb(SUM, SUM, SUM));
        }
    }
    return sobelEdges;
}
Пример #16
0
void calcMsePsnr(double* mse, double* psnr, QImage *image1, QImage *image2, QSize size) {
    double P = 0;
    for (int i = 0; i < size.width(); i++) {
        for (int j = 0; j < size.height(); j++) {
            int pixel1 = qGray(image1->pixel(i,j));
            int pixel2 = qGray(image2->pixel(i,j));
            double SQ = pixel1-pixel2;
            P += SQ*SQ;
        }
    }
    P /= size.width()*size.height();
    *mse = sqrt(P);
    *psnr = 10 * log10(65025./((*mse) * (*mse)));

}
Пример #17
0
QVector<Line> Converter::convert(const QImage &image, Modes mode/*, int left, int top, int right, int bottom*/){
    QVector<Line> result;
    int left = 0,top = 0,right = image.width(),bottom = image.height();
    for( int i = left; i < right; ++i){
        for( int j = top; j < bottom; ++j){
            Line p;
            p.x1 = p.x2 = i;
            p.y1 = p.y2 = j;
            p.z1 = qGray(image.pixel(i,j));
            p.c = p.z1;
            QVector<int> v;
            if(i!=left) v.push_back(qGray(image.pixel(i-1,j)));
            if(i < right-1) v.push_back(qGray(image.pixel(i+1,j)));
            if(j!=top) v.push_back(qGray(image.pixel(i,j-1)));
            if(j < bottom-1) v.push_back(qGray(image.pixel(i,j+1)));
            if(i!=left && j!= top) v.push_back(qGray(image.pixel(i-1,j-1)));
            if(i < right-1 && j!=top) v.push_back(qGray(image.pixel(i+1,j-1)));
            if(j < bottom-1 && i!=left) v.push_back(qGray(image.pixel(i-1,j+1)));
            if(i < right-1 && j < bottom-1) v.push_back(qGray(image.pixel(i+1,j+1)));
            int min = *(std::min_element(v.begin(),v.end()));
            if(min < qGray(image.pixel(i,j))){
                p.z2 = p.z1 - min;
            }else{
                p.z2 = p.z1;
            }
            result.push_back(p);
        }
    }
    switch (mode) {
    case ISO:
        rotate(result, 3.1415/180*35.2,3.1415/4,-3.1415/4);
        break;
    case BOTTOM:
        rotate(result, 3.1415/180*90,0,0);
        break;
    case LEFT:
        rotate(result, 3.1415/180*90,0,0);
        rotate(result, 0, 3.1415/180*90,0);
        break;
    case RIGHT:
        rotate(result, 3.1415/180*90,0,0);
        rotate(result, 0, -3.1415/180*90,0);
        break;
    default:
        break;
    }
    return result;
}
Пример #18
0
void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter *painter, struct dive *dive, QPointer<ProfileWidget2> profile)
{
	int x = profilePlaceholder.x() - viewPort.x();
	int y = profilePlaceholder.y() - viewPort.y();
	// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
	QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
	profile->plotDive(dive, true);

	if (!printOptions->color_selected) {
		QImage image(pos.width(), pos.height(), QImage::Format_ARGB32);
		QPainter imgPainter(&image);
		imgPainter.setRenderHint(QPainter::Antialiasing);
		imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
		profile->render(&imgPainter, QRect(0, 0, pos.width(), pos.height()));
		imgPainter.end();

		// convert QImage to grayscale before rendering
		for (int i = 0; i < image.height(); i++) {
			QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i));
			QRgb *end = pixel + image.width();
			for (; pixel != end; pixel++) {
				int gray_val = qGray(*pixel);
				*pixel = QColor(gray_val, gray_val, gray_val).rgb();
			}
		}

		painter->drawImage(pos, image);
	} else {
		profile->render(painter, pos);
	}
}
Пример #19
0
void ColorDisplay::paintEvent(QPaintEvent *)
{
	QPainter painter(this);

	int gray;
	int size = colors.size(), x;
	// Colors
	painter.setPen(QColor(0, 0, 0));
	const int cellFullWidth = COLOR_DISPLAY_CELL_SIZE + COLOR_DISPLAY_BORDER_WIDTH;
	for(int i=0 ; i<size ; ++i) {
		x = i * cellFullWidth;
		painter.drawRect(x, 0, cellFullWidth, cellFullWidth);
		gray = qGray(colors.at(i));
		painter.fillRect(x+COLOR_DISPLAY_BORDER_WIDTH,
						 COLOR_DISPLAY_BORDER_WIDTH,
						 COLOR_DISPLAY_CELL_SIZE,
						 COLOR_DISPLAY_CELL_SIZE,
						 isEnabled() ? QColor(colors.at(i)) : QColor(gray, gray, gray));
	}
	// Red frame
	if(isEnabled()) {
		painter.setPen(QColor(0xFF, 0, 0));
		QPoint cursor_position = this->mapFromGlobal(this->cursor().pos());
		x = colorId(cursor_position) * cellFullWidth;
		painter.drawRect(x, 0, cellFullWidth, cellFullWidth);
	}
	painter.end();
}
Пример #20
0
QImage colouriseImage(const QString& imagePath, std::function<QRgb(int)> function)
{
    QImage originalImage(imagePath);

    QImage colourisedImage = originalImage.convertToFormat(QImage::Format_ARGB32);

    for (int y = 0; y < originalImage.width(); ++y)
    {
        for (int x = 0; x < originalImage.height(); ++x)
        {
            QRgb oldColour = originalImage.pixel(x, y);

            QRgb newColour = function(qGray(oldColour));

            // Preserve transparency
            newColour = qRgba(
                qRed(newColour),
                qGreen(newColour),
                qBlue(newColour),
                qAlpha(oldColour)
            );

            colourisedImage.setPixel(x, y, newColour);
        }
    }

    return colourisedImage;
}
MatrixWorkspace_sptr
ImggFormatsConvertViewQtWidget::loadImg(const std::string &inputName,
                                        const std::string &inFormat) const {

  QImage img = loadImgFile(inputName, inFormat);
  int width = img.width();
  int height = img.height();

  MatrixWorkspace_sptr imgWks = boost::dynamic_pointer_cast<MatrixWorkspace>(
      WorkspaceFactory::Instance().create("Workspace2D", height, width + 1,
                                          width));
  imgWks->setTitle(inputName);
  const double scaleFactor = std::numeric_limits<unsigned char>::max();
  for (int yi = 0; yi < static_cast<int>(width); ++yi) {
    auto &row = imgWks->getSpectrum(yi);
    auto &dataY = row.dataY();
    auto &dataX = row.dataX();
    std::fill(dataX.begin(), dataX.end(), static_cast<double>(yi));
    for (int xi = 0; xi < static_cast<int>(width); ++xi) {
      QRgb vRgb = img.pixel(xi, yi);
      dataY[xi] = scaleFactor * qGray(vRgb);
    }
  }

  return imgWks;
}
Пример #22
0
/*!
  Returns the QImage called \a name. You should avoid including
  any filename type extension (e.g. .png, .xpm).
*/
QImage Resource::loadImage( const QString &name)
{
#ifndef QT_NO_DEPTH_32	// have alpha-blended pixmaps
    static QImage last_enabled;
    static QString last_enabled_name;
    if ( name == last_enabled_name )
	return last_enabled;
#endif
    QImage img = load_image(name);
#ifndef QT_NO_DEPTH_32	// have alpha-blended pixmaps
    if ( img.isNull() ) {
	// No file, try generating
	if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
	    last_enabled_name = name.left(name.length()-9);
	    last_enabled = load_image(last_enabled_name);
	    if ( last_enabled.isNull() ) {
		last_enabled_name = QString::null;
	    } else {
		img.detach();
		img.create( last_enabled.width(), last_enabled.height(), 32 );
		for ( int y = 0; y < img.height(); y++ ) {
		    for ( int x = 0; x < img.width(); x++ ) {
			QRgb p = last_enabled.pixel( x, y );
			int a = qAlpha(p)/3;
			int g = qGray(qRed(p),qGreen(p),qBlue(p));
			img.setPixel( x, y, qRgba(g,g,g,a) );
		    }
		}
		img.setAlphaBuffer( TRUE );
	    }
	}
    }
#endif
    return img;
}
void KoDocumentSectionDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    const QRect r = thumbnailRect(option, index).translated(option.rect.topLeft());

    p->save();
    {
        p->setClipRect(r);
        const qreal myratio = qreal(r.width()) / r.height();
        const qreal thumbratio = index.data(Model::AspectRatioRole).toDouble();
        const int s = (myratio > thumbratio) ? r.height() : r.width();

        QImage img = index.data(int(Model::BeginThumbnailRole) + s).value<QImage>();
        if (!(option.state & QStyle::State_Enabled)) {
            // Make the image grayscale
            // TODO: if someone feel bored a more optimized version of this would be welcome
            for(int i = 0; i < img.width(); ++i) {
                for(int j = 0; j < img.width(); ++j) {
                    img.setPixel(i, j, qGray(img.pixel(i,j)));
                }
            }
        }
        QPoint offset;
        offset.setX(r.width()/2 - img.width()/2);
        offset.setY(r.height()/2 - img.height()/2);

        p->drawImage(r.topLeft() + offset, img);
    }
    p->restore();
}
Пример #24
0
static void _emboss(QString sourceFile, QString destFile)
{
    QImage image(sourceFile);
    if(image.isNull())
    {
        qDebug() << "load " << sourceFile << " failed! ";
        return;
    }
    int width = image.width();
    int height = image.height();
    QRgb color;
    QRgb preColor = 0;
    QRgb newColor;
    int gray, r, g, b, a;
    for(int i = 0; i < width; i++)
    {
        for(int j= 0; j < height; j++)
        {
            color = image.pixel(i, j);
            r = qRed(color) - qRed(preColor) + 128;
            g = qGreen(color) - qGreen(preColor) + 128;
            b = qBlue(color) - qBlue(preColor) + 128;
            a = qAlpha(color);
            gray = qGray(r, g, b);
            newColor = qRgba(gray, gray, gray, a);
            image.setPixel(i, j, newColor);
            preColor = newColor;
        }
    }
    image.save(destFile);
}
Пример #25
0
void KermitScreen::solidFill(const QColor &color, const QRegion &region)
{
    //qDebug("KermitScreen::solidFill  ");
    if (depth() != 8)
    {
        qWarning("Fallback to QScreen as the depth is not 8 %d", depth());
        QScreen::solidFill(color, region);
        return;
    }

    unsigned char *base = QScreen::data;
    if (base == 0)
    {
        qWarning("Framebuffer is empty.");
        return;
    }

    unsigned char gray = (qGray(color.rgba()) & 0xff);
    const QVector<QRect> rects = region.rects();
    for (int i = 0; i < rects.size(); ++i)
    {
        const QRect r = rects.at(i);

        for(int y = r.top(); y < r.top() + r.height(); ++y)
        {
            unsigned char *p = base + y * QScreen::w + r.left();
            memset(p, r.width(), gray);
        }
    }
    // qDebug("KermitScreen::solidFill done");
}
Пример #26
0
QVariant ImageTableModel::data(const QModelIndex &index, int role) const
{
    if(role == Qt::DisplayRole)
    {
        return m_provider->valueInfoString(QPoint(index.column(), index.row()));
    }
    else if(role == Qt::BackgroundColorRole)
    {
        if(m_pixelbackground)
            return QColor(m_provider->image().pixel(QPoint(index.column(), index.row())));
        else
            return QVariant();
    }
    else if(role == Qt::TextColorRole)
    {
        if(m_pixelbackground)
        {
            int back = qGray(m_provider->image().pixel(QPoint(index.column(), index.row())));
            int textc = back > 128 ? 0 : 255;
            return QColor(qRgb(textc,textc, textc));
        }
        else
            return QVariant();
    }
    else
        return QVariant();
}
Пример #27
0
static void _gray(QString sourceFile, QString destFile)
{
    QImage image(sourceFile);
    if(image.isNull())
    {
        qDebug() << "load " << sourceFile << " failed! ";
        return;
    }
    qDebug() << "depth - " << image.depth();

    int width = image.width();
    int height = image.height();
    QRgb color;
    int gray;
    for(int i = 0; i < width; i++)
    {
        for(int j= 0; j < height; j++)
        {
            color = image.pixel(i, j);
            gray = qGray(color);
            image.setPixel(i, j, qRgba(gray, gray, gray, qAlpha(color)));
        }
    }

    image.save(destFile);
}
Пример #28
0
void KColorCombo::slotActivated( int index )
{
	if ( index == 0 )
	{
	    if ( KColorDialog::getColor( customColor, this ) == QDialog::Accepted )
		{
			QPainter painter;
			QPen pen;
			QRect rect( 0, 0, width(), QFontMetrics(painter.font()).height()+4);
			QPixmap pixmap( rect.width(), rect.height() );

			if ( qGray( customColor.rgb() ) < 128 )
				pen.setColor( white );
			else
				pen.setColor( black );

			painter.begin( &pixmap );
			QBrush brush( customColor );
			painter.fillRect( rect, brush );
			painter.setPen( pen );
			painter.drawText( 2, QFontMetrics(painter.font()).ascent()+2, i18n("Custom...") );
			painter.end();

			changeItem( pixmap, 0 );
			pixmap.detach();
		}

		internalcolor = customColor;
	}
	else
		internalcolor = standardPalette[ index - 1 ];

	emit activated( internalcolor );
}
Пример #29
0
void Widget::CalcHis(QImage *Img, QImage *drawImg, unsigned int* hisMtx, QToolButton *button)
{
    int i, j;
    int tmpPix;
    unsigned int max = 0;
    int top;
    memset((void*)hisMtx,0,sizeof(int)*256);

    for(j=0; j<Img->height(); j++){
        for(i=0; i<Img->width(); i++){

            tmpPix = qGray(Img->pixel(i, j));
            hisMtx[tmpPix]++;
        }
    }

    for (max=0,i=0;i<hisSize;i++){
        if(hisMtx[i]>max)
            max = hisMtx[i];
    }

    painter.begin(drawImg);
    for (i=0;i<hisSize;i++){
        top=H-(hisMtx[i]*H)/max;
        painter.setPen(Qt::red);
        painter.drawLine(i,top,i,H);
    }
    painter.end();

    button->setIcon(QPixmap::fromImage(*drawImg));
}
Пример #30
0
sumMap* Contrast::makeGraySumMap(VImage* vim) {
    QImage* qimage = vim->getQImage();
    int width = qimage->width();
    int height = qimage->height();

    sumMap* densityMap = new sumMap();

    for(int y=0; y<height; ++y) {
        vector<unsigned long int> row(width);
        densityMap->push_back(row);
        for(int x=0; x<width; ++x) {
            unsigned long int currSum =
                  qGray(qimage->pixel(x, y));
            if(y > 0) {
                currSum +=
                  (*densityMap)[y][max(x-1, 0)]
                + (*densityMap)[max(y-1, 0)][x]
                - (*densityMap)[max(y-1, 0)][max(x-1, 0)];
            }

            (*densityMap)[y][x] = currSum;
        }
    }

    return densityMap;
}