Esempio n. 1
0
void Widget::initializeGL()
{
    timer.setInterval (10);
    timer.setSingleShot(false);
    timer.start();
    connect(&timer, SIGNAL(timeout()), this, SLOT(onTimer()));

    initializeGLFunctions();

    printf("\n%s\n", glGetString(GL_VERSION));
    printf("%s\n", glGetString(GL_VENDOR));
    printf("%s\n", glGetString(GL_RENDERER));
    fflush (stdout);
    QImage part_img (":/match.png");
    for (int line = 0; line < part_img.height(); line++)
    {
        QRgb *pixel = (QRgb *)part_img.scanLine (line);
        for (int b = 0; b < part_img.width(); b++)
            if( 0 == qRed(pixel[b]) &&
                0 == qGreen(pixel[b]) &&
                0 == qBlue(pixel[b])
            ) {
                pixel[b] = 0x00ffffff;
            }
    }

    partTexture = bindTexture (part_img,
                         GL_TEXTURE_2D,
                         GL_RGBA,
                         QGLContext::DefaultBindOption);

    myShader.addShaderFromSourceFile(QGLShader::Vertex, ":/ground.vert");
    myShader.addShaderFromSourceFile(QGLShader::Fragment, ":/ground.frag");
    myShader.link();
    particle.addShaderFromSourceFile(QGLShader::Vertex,":/particle.vert");
    particle.addShaderFromSourceFile(QGLShader::Fragment,":/particle.frag");
    particle.link();

    terrainMesh.loadRawTriangles(":/terrain.raw");

    terrainTexture =bindTexture(QImage(":/terrain.jpg"));
}
Esempio n. 2
0
// Add random noise to the image
void MainWindow::AddNoise(QImage *image, double mag, bool colorNoise)
{
    int r, c;
    QRgb pixel;
    int noiseMag = mag;
    noiseMag *= 2;

    for(r=0;r<image->height();r++)
    {
        for(c=0;c<image->width();c++)
        {
            pixel = image->pixel(c, r);
            int red = qRed(pixel);
            int green = qGreen(pixel);
            int blue = qBlue(pixel);

            // If colorNoise, add color independently to each channel
            if(colorNoise)
            {
                red += rand()%noiseMag - noiseMag/2;
                green += rand()%noiseMag - noiseMag/2;
                blue += rand()%noiseMag - noiseMag/2;
            }
            // otherwise add the same amount of noise to each channel
            else
            {
                int noise = rand()%noiseMag - noiseMag/2;

                red += noise;
                green += noise;
                blue += noise;
            }

            // Make sure we don't over or under saturate
            red = min(255, max(0, red));
            green = min(255, max(0, green));
            blue = min(255, max(0, blue));

            image->setPixel(c, r, qRgb( red, green, blue));
        }
    }
}
Esempio n. 3
0
void Histogram::generate(QImage* image)
{
    int width  = image->width();
    int height = image->height();

    if (image->format() == QImage::Format_Indexed8)
    {
        for (int x=0; x<width; x++)
        {	for (int y=0; y<height; y++)
            {
                QRgb pixel = image->pixel(x, y);

                int l = qGray(pixel);
                int value = L-> value(l)+1;
                L -> insert(l, value);

            }
        }
    }
    else
    {
        for (int x=0; x<width; x++)
        {	for (int y=0; y<height; y++)
            {
                QRgb pixel = image->pixel(x, y);

                int r = qRed(pixel);
                int g = qGreen(pixel);
                int b = qBlue(pixel);

                int valueR = R-> value(r)+1;
                int valueG = G-> value(g)+1;
                int valueB = B-> value(b)+1;

                R -> insert(r, valueR);
                G -> insert(g, valueG);
                B -> insert(b, valueB);

            }
        }
    }
}
Esempio n. 4
0
RGB24Buffer *QTFileLoader::RGB24BufferFromQImage(QImage *image)
{
    if (image == NULL)
        return NULL;

    RGB24Buffer *result = new RGB24Buffer(image->height(), image->width(), false);

    if (image->format() == QImage::Format_ARGB32 || image->format() == QImage::Format_RGB32 )
    {
        for (int i = 0; i < image->height(); i++)
        {
            uint8_t *in = (uint8_t *)image->scanLine(i);
            RGBColor *out = &result->element(i, 0);
            for (int j = 0; j < image->width(); j++)
            {
                uint8_t r = *(in++);
                uint8_t g = *(in++);
                uint8_t b = *(in++);
                *out = RGBColor(b,g,r);
                in++;
                out++;
            }
        }
    } else {
        /**
         * TODO: Make this faster using .bits() method.
         * So far don't want to mess with possible image formats
         *
         */
        qDebug("QTFileLoader::RGB24BufferFromQImage():Slow conversion.");
        for (int i = 0; i < image->height(); i++)
        {
            for (int j = 0; j < image->width(); j++)
            {
                QRgb pixel = image->pixel(j,i);
                result->element(i,j) = RGBColor(qRed(pixel), qGreen(pixel), qBlue(pixel));
            }
        }
    }

    return result;
}
Esempio n. 5
0
void paintShadow(QPainter *p, const QRect &r, const ShadowSettings &settings, const QImage &shadowImage)
{
    const int s = -settings.size;
    QRect rect = r.adjusted(s - 32, s - 32, 32 - s, 32 - s);
    rect.adjust(settings.offsetX, settings.offsetY, settings.offsetX, settings.offsetY);
    int radius = shadowImage.width() / 2;

    // corners
    for (int i = 0; i < 4; ++i) {
        const int x = i & 1 ? rect.x() : rect.x() + rect.width() - radius;
        const int y = i & 2 ? rect.y() : rect.y() + rect.height() - radius;
        p->drawImage(x, y, shadowImage,
            i & 1 ? 0 : radius + 1, i & 2 ? 0 : radius + 1, radius, radius);
    }

    // sides
    for (int i = 0; i < 2; ++i) {
        const int x = rect.x() + radius;
        const int y = i & 1 ? rect.y() : rect.y() + rect.height() - radius;
        p->drawTiledPixmap(x, y, rect.width() - 2 * radius, radius,
            QPixmap::fromImage(shadowImage.copy(radius, i & 1 ? 0 : radius + 1, 1, radius)));
    }
    for (int i = 0; i < 2; ++i) {
        const int x = i & 1 ? rect.x() : rect.x() + rect.width() - radius;
        const int y = rect.y() + radius;
        p->drawTiledPixmap(x, y, radius, rect.height() - 2 * radius,
            QPixmap::fromImage(shadowImage.copy(i & 1 ? 0 : radius + 1, radius, radius, 1)));
    }

    // center
    QRgb pixel = shadowImage.pixel(radius, radius);
    if (shadowImage.format() == QImage::Format_ARGB32_Premultiplied) {
        const int alpha = qAlpha(pixel);
        if (alpha != 0 && alpha != 255) {
            pixel = qRgba(qBound(0, qRed(pixel) * 255 / alpha, 255),
                qBound(0, qGreen(pixel) * 255 / alpha, 255),
                qBound(0, qBlue(pixel) * 255 / alpha, 255),
                alpha);
        }
    }
    p->fillRect(rect.adjusted(radius, radius, -radius, -radius), QColor::fromRgba(pixel));
}
Esempio n. 6
0
/**
 * Changes the transparency (alpha component) of an image.
 * @param image Image to be manipulated. Must be true color (8 bit per channel).
 * @param factor > 1.0 == more transparency, < 1.0 == less transparency.
 */
void PlaylistItem::imageTransparency( QImage& image, float factor ) //static
{
    uint *data = reinterpret_cast<unsigned int *>( image.bits() );
    const int pixels = image.width() * image.height();
    uint table[256];
    register int c;

    // Precalculate lookup table
    for( int i = 0; i < 256; ++i ) {
        c = int( double( i ) * factor );
        if( c > 255 ) c = 255;
        table[i] = c;
    }

    // Process all pixels. Highly optimized.
    for( int i = 0; i < pixels; ++i ) {
        c = data[i]; // Memory access is slow, so do it only once
        data[i] = qRgba( qRed( c ), qGreen( c ), qBlue( c ), table[qAlpha( c )] );
    }
}
Esempio n. 7
0
/*!
  Used to convert RGB Jpg files to grayscale.

  \param image a QImage with original image data points
  \return a grayscale Matrix from QImage
*/
Matrix ImageB::convertRGB2Gray( QImage image )
{
   QRgb pix;
   Matrix mat = Matrix(image.height(),image.width());

   for (long i=1; i <= image.width();i++)
       {
          for(long j=1; j <= image.height();j++) 
            {
              int h =0;
              pix = image.pixel(i,j); //pega valor do pixel
              
              //média dos pixels
              h = int((qRed(pix) + qGreen(pix) + qBlue(pix))/3);            
              mat(j,i) = h; //seta dado na matriz
            } 
       }
  
  return mat;
}
Esempio n. 8
0
//==============================================================================
void GameServer::LoadLevelFromImage_(const QString filename)
{
  QFile levelImage(filename);
  if (levelImage.exists())
  {
    QImage map;
    map.load(filename, "png");
    levelMap_.Resize(map.width(), map.height());
    for (int i = 0; i < map.height(); i++)
    {
      for (int j = 0; j < map.width(); j++)
      {
        auto color = map.pixel(j, i);
        int summ = qRed(color) + qGreen(color) + qBlue(color);
        int value = summ > (255 * 3 / 2) ? '.' : '#';
        levelMap_.SetCell(j, i, value);
      }
    }
  }
}
Esempio n. 9
0
static void _binarize(QString sourceFile, QString destFile)
{
    QImage image(sourceFile);
    int width = image.width();
    int height = image.height();
    QRgb color;
    QRgb avg;
    QRgb black = qRgb(0, 0, 0);
    QRgb white = qRgb(255, 255, 255);
    for(int i = 0; i < width; i++)
    {
        for(int j= 0; j < height; j++)
        {
            color = image.pixel(i, j);
            avg = (qRed(color) + qGreen(color) + qBlue(color))/3;
            image.setPixel(i, j, avg >= 128 ? white : black);
        }
    }
    image.save(destFile);
}
Esempio n. 10
0
void ImageHandler::ghostImage(QImage *img)
{
       
	int w = img->width(),
		h = img->height(),
		x, y;

	for (y=0; y<h; y++)
	{
		uint *line = (uint*)img->scanLine(y);
		for (x=0; x<w; x++)
		{
			//if ((x%2 && !(y%2)) || (!(x%2) && y%2))
			{
				line[x] = qRgba(qRed(line[x]), qGreen(line[x]), qBlue(line[x]), (line[x] ? 125 : 0));
			}
		}
	}

}
static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1)
{
    static int maxFuzz = 1;
    static bool maxFuzzSet = false;

    // On 16 bpp systems, we need to allow for more fuzz:
    if (!maxFuzzSet) {
        maxFuzzSet = true;
        if (QGuiApplication::primaryScreen()->depth() < 24)
            maxFuzz = 32;
    }

    int redFuzz = qAbs(qRed(testPixel) - qRed(refPixel));
    int greenFuzz = qAbs(qGreen(testPixel) - qGreen(refPixel));
    int blueFuzz = qAbs(qBlue(testPixel) - qBlue(refPixel));
    int alphaFuzz = qAbs(qAlpha(testPixel) - qAlpha(refPixel));

    if (refPixel != 0 && testPixel == 0) {
        QString msg;
        if (x >= 0) {
            msg = QString("Test pixel [%1, %2] is null (black) when it should be (%3,%4,%5,%6)")
                            .arg(x).arg(y)
                            .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel));
        } else {
            msg = QString("Test pixel is null (black) when it should be (%2,%3,%4,%5)")
                            .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel));
        }

        QTest::qFail(msg.toLatin1(), file, line);
        return false;
    }

    if (redFuzz > maxFuzz || greenFuzz > maxFuzz || blueFuzz > maxFuzz || alphaFuzz > maxFuzz) {
        QString msg;

        if (x >= 0)
            msg = QString("Pixel [%1,%2]: ").arg(x).arg(y);
        else
            msg = QString("Pixel ");

        msg += QString("Max fuzz (%1) exceeded: (%2,%3,%4,%5) vs (%6,%7,%8,%9)")
                      .arg(maxFuzz)
                      .arg(qRed(testPixel)).arg(qGreen(testPixel)).arg(qBlue(testPixel)).arg(qAlpha(testPixel))
                      .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel));
        QTest::qFail(msg.toLatin1(), file, line);
        return false;
    }
    return true;
}
Esempio n. 12
0
QPixmap Cell::fadedPixmap(const QPixmap & pixmap)
{
    QImage image = pixmap.toImage();
    for(int y = 0; y < image.height(); y++)
    {
	QRgb * line = (QRgb *)image.scanLine(y);
	for(int x = 0; x < image.width(); x++)
	{
	    QRgb pix = line[x];
	    if(qAlpha(pix) == 255)
	    {
		int g = (255 + 3 * qGreen(pix)) / 4;
		int b = (255 + 3 * qBlue(pix)) / 4;
		int r = (255 + 3 * qRed(pix)) / 4;
		line[x] = qRgb(r, g, b);
	    }
	}
    }
    return QPixmap::fromImage(image);
}
Esempio n. 13
0
void CloudsBlending::blend( QImage * const bottom, TextureTile const * const top ) const
{
    QImage const * const topImage = top->image();
    Q_ASSERT( topImage );
    Q_ASSERT( bottom->size() == topImage->size() );
    int const width = bottom->width();
    int const height = bottom->height();
    for ( int y = 0; y < height; ++y ) {
        for ( int x = 0; x < width; ++x ) {
            qreal const c = qRed( topImage->pixel( x, y )) / 255.0;
            QRgb const bottomPixel = bottom->pixel( x, y );
            int const bottomRed = qRed( bottomPixel );
            int const bottomGreen = qGreen( bottomPixel );
            int const bottomBlue = qBlue( bottomPixel );
            bottom->setPixel( x, y, qRgb(( int )( bottomRed + ( 255 - bottomRed ) * c ),
                                         ( int )( bottomGreen + ( 255 - bottomGreen ) * c ),
                                         ( int )( bottomBlue + ( 255 - bottomBlue ) * c )));
        }
    }
}
Esempio n. 14
0
void QImageWidget::setImage(const char *filename)
{
  image.load(filename);
//#ifdef USE_MAEMO 
//  unlink(filename);
//#endif  
  clearMask();
  if(w > 0 && h > 0 && ( w < image.width() || h < image.height() ) )
  {
    //printf("set1: setImage %s xy=%d,%d w=%d h=%d width=%d height=%d\n", filename, 
    //x(), y(), w, h, 
    //                                  image.width(),image.height());
    image = image.scaled(w, h, Qt::KeepAspectRatio);
  }
  else if(w > image.width() || h > image.height())
  {
    //printf("set2: setImage %s xy=%d,%d w=%d h=%d width=%d height=%d\n", filename, 
    //x(),y(),w, h, 
    //                                  image.width(),image.height());
    //qt3 image = image.smoothScale(w,h,Qt::KeepAspectRatio);
    image.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  }

  if(strstr(filename,".bmp") != NULL || strstr(filename,".BMP") != NULL)
  { // it may be a bmp with transparent background
    int n = image.numColors();
    for(int icol=0; icol<n; icol++)
    {
      QRgb qcol = image.color(icol);
      if(qRed(qcol) == 1 && qGreen(qcol) == 1 && qBlue(qcol) == 1)
      { // image has transparent background
        //image.setAlphaBuffer(true);
        image.setColor(icol,qRgba(1,1,1,0));
        image.createAlphaMask();
      }
    }
  }
  perhapsSetMask();
  original_image = image.copy();
  repaint();
}
Esempio n. 15
0
static QImage prepareSurface(QImage img, int w, int h)
{
  img = scaleImage(img, w, h);

  // slightly larger, to accomodate for the reflection
  int hs = h * 2;
  int hofs = h / 3;

  // offscreen buffer: black is sweet
  QImage result(hs, w, QImage::Format_RGB32);  
  result.fill(0);

  // transpose the image, this is to speed-up the rendering
  // because we process one column at a time
  // (and much better and faster to work row-wise, i.e in one scanline)
  for(int x = 0; x < w; x++)
    for(int y = 0; y < h; y++)
      result.setPixel(hofs + y, x, img.pixel(x, y));

  // create the reflection
  int ht = hs - h - hofs;
  int hte = ht;
  for(int x = 0; x < w; x++)
    for(int y = 0; y < ht; y++)
    {
      QRgb color = img.pixel(x, img.height()-y-1);
      int a = qAlpha(color);
      int r = qRed(color)   * a / 256 * (hte - y) / hte * 3/5;
      int g = qGreen(color) * a / 256 * (hte - y) / hte * 3/5;
      int b = qBlue(color)  * a / 256 * (hte - y) / hte * 3/5;
      result.setPixel(h+hofs+y, x, qRgb(r, g, b));
    }

#ifdef PICTUREFLOW_BILINEAR_FILTER
  int hh = BILINEAR_STRETCH_VER*hs;
  int ww = BILINEAR_STRETCH_HOR*w;
  result = scaleImage(result, hh, ww);
#endif

  return result;
}
PNM* ConversionGrayscale::transform()
{
   // qDebug() << Q_FUNC_INFO << "Not implemented yet!";

    int width = image->width();
    int height = image->height();

    PNM* newImage = new PNM(width, height, QImage::Format_Indexed8);

    if (image->format() == QImage::Format_Mono)
    {
		for (int x = 0; x<width; x++)
			for (int y = 0; y<height; y++)
			{
			QColor color = QColor::fromRgb(image->pixel(x, y)); // Getting the pixel(x,y) value

			newImage->setPixel(x, y, color == Qt::white ? Qt::color1 : Qt::color0);
			}

    }
    else // if (image->format() == QImage::Format_RGB32)
    {
		for (int x = 0; x<width; x++)
			for (int y = 0; y<height; y++)
			{
			QRgb pixel = image->pixel(x, y); // Getting the pixel(x,y) value

			int r = qRed(pixel);    // Get the 0-255 value of the R channel
			int g = qGreen(pixel);  // Get the 0-255 value of the G channel
			int b = qBlue(pixel);   // Get the 0-255 value of the B channel
			r = (int) floor(r*0.3);
			g = (int) floor(g*0.6);
			b = (int) floor(b*0.1);
			//QColor newPixel = QColor(r, g, b);
			newImage->setPixel(x, y, r + g + b);
			}

    }

    return newImage;
}
Esempio n. 17
0
QDBusArgument& operator<< (QDBusArgument &arg, const QImage &image)
{
    if (image.isNull()) {
        // Sometimes this gets called with a null QImage for no obvious reason.
        arg.beginStructure();
        arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
        arg.endStructure();
        return arg;
    }
    QImage scaled = image.scaledToHeight(128, Qt::SmoothTransformation).convertToFormat(QImage::Format_ARGB32);

    #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
    // ABGR -> ARGB
    QImage i = scaled.rgbSwapped();
    #else
    // ABGR -> GBAR
    QImage i(scaled.size(), scaled.format());
    for (int y = 0; y < i.height(); ++y) {
        QRgb *p = (QRgb*) scaled.scanLine(y);
        QRgb *q = (QRgb*) i.scanLine(y);
        QRgb *end = p + scaled.width();
        while (p < end) {
            *q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
            p++;
            q++;
        }
    }
    #endif

    arg.beginStructure();
    arg << i.width();
    arg << i.height();
    arg << i.bytesPerLine();
    arg << i.hasAlphaChannel();
    int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
    arg << i.depth() / channels;
    arg << channels;
    arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount());
    arg.endStructure();
    return arg;
}
Esempio n. 18
0
static void _negative(QString sourceFile, QString destFile)
{
    QImage image(sourceFile);
    int width = image.width();
    int height = image.height();
    QRgb color;
    QRgb negative;
    for(int i = 0; i < width; i++)
    {
        for(int j= 0; j < height; j++)
        {
            color = image.pixel(i, j);
            negative = qRgba(255 - qRed(color),
                             255 - qGreen(color),
                             255 - qBlue(color),
                             qAlpha(color));
            image.setPixel(i, j, negative);
        }
    }
    image.save(destFile);
}
Esempio n. 19
0
bb::ImageData AbstractLoader::fromQImage(const QImage &qImage)
{
	bb::ImageData imageData(bb::PixelFormat::RGBA_Premultiplied, qImage.width(), qImage.height());

	unsigned char *dstLine = imageData.pixels();
	for (int y = 0; y < imageData.height(); y++)
	{
		unsigned char * dst = dstLine;
		for (int x = 0; x < imageData.width(); x++)
		{
			QRgb srcPixel = qImage.pixel(x, y);
			*dst++ = qRed(srcPixel);
			*dst++ = qGreen(srcPixel);
			*dst++ = qBlue(srcPixel);
			*dst++ = qAlpha(srcPixel);
		}
		dstLine += imageData.bytesPerLine();
	}

	return imageData;
}
Esempio n. 20
0
// Convert an image to grey-scale
void MainWindow::BlackWhiteImage(QImage *image)
{
    int r, c;
    QRgb pixel;

    for(r=0;r<image->height();r++)
    {
        for(c=0;c<image->width();c++)
        {
            pixel = image->pixel(c, r);
            double red = (double) qRed(pixel);
            double green = (double) qGreen(pixel);
            double blue = (double) qBlue(pixel);

            // Compute intensity from colors - these are common weights
            double intensity = 0.3*red + 0.6*green + 0.1*blue;

            image->setPixel(c, r, qRgb( (int) intensity, (int) intensity, (int) intensity));
        }
    }
}
Esempio n. 21
0
void applyImageTransparancy(QImage& img, const Numpy2DObj& data)
{
  const int xw = min(data.dims[1], img.width());
  const int yw = min(data.dims[0], img.height());
  
  for(int y=0; y<yw; ++y)
    {
      // direction of images is different for qt and numpy image
      QRgb* scanline = reinterpret_cast<QRgb*>(img.scanLine(yw-y-1));
      for(int x=0; x<xw; ++x)
	{
	  const double val = clipval(data(x, y), 0., 1.);
	  const QRgb col = *(scanline+x);

	  // update pixel alpha component
	  QRgb newcol = qRgba( qRed(col), qGreen(col), qBlue(col),
			       int(qAlpha(col)*val) );
	  *(scanline+x) = newcol;
	}
    }
}
Esempio n. 22
0
static void setColor(enum ColorNums num, const QRgb &rgb){
  R_ASSERT_RETURN_IF_FALSE(num<END_CONFIG_COLOR_NUM);

  GL_lock();{

#if USE_GTK_VISUAL
    GTK_SetColor(num,qRed(rgb),qGreen(rgb),qBlue(rgb));
#endif

    if (g_config_colors[num]==NULL)
      get_config_qcolor(num);

    g_config_colors[num]->setRgb(rgb);
    
    if(num==LOW_BACKGROUND_COLOR_NUM)
      system_color->setRgb(rgb);
    else if(num==HIGH_BACKGROUND_COLOR_NUM)
      button_color->setRgb(rgb);
    
  }GL_unlock();
}
Esempio n. 23
0
void MainWindow::on_actionContrast_activated()
{
    ui->statusBar->showMessage("Contrast image");
    QImage image = ui->imageLabel->pixmap()->toImage();
    bool ok;
    int delta = QInputDialog::getInt(this, tr("Contrast Image"), tr("Enter delta for contrast:"),64 ,0, 255, 1, &ok);

    if(ok)
    {
        for(int x = 0; x < image.width(); x++)
        {
            for(int y = 0; y < image.height(); y++)
            {
                QRgb pixel = image.pixel(x,y);
                int rPixel = ( qRed(pixel) - delta ) * 2;
                if(rPixel > 255)
                {
                    rPixel = 255;
                }

                int gPixel = ( qGreen(pixel) - delta ) * 2;
                if(gPixel > 255)
                {
                    gPixel = 255;
                }

                int bPixel = ( qBlue(pixel) - delta ) * 2;
                if(bPixel > 255)
                {
                    bPixel = 255;
                }

                image.setPixel(x,y,qRgb(rPixel, gPixel, bPixel));
            }

        }
        ui->imageLabel->setPixmap(QPixmap::fromImage(image));
        saveCurrentImage();
    }
}
Esempio n. 24
0
bool RGBFile::convertTo(const QString & srcFile, const QString & dstFile) {
    QImage img;
    if (!img.load(srcFile)) {
        qDebug() << "can't open source file" << srcFile;
        return false;
    }

    QFile out(dstFile);
    if (!out.open(QIODevice::WriteOnly)) {
        qDebug() << "cant' open dest file" << dstFile;
        return false;
    }

    // write header

    int t = 0;
    t = RGB_FILE_SIGNATURE;
    out.write((char*)&t, 4);
    t = img.width();
    out.write((char*)&t, 2);
    t = img.height();
    out.write((char*)&t, 2);

    // process and write pixels

    QByteArray data;
    data.resize(img.height() * img.width() * 2);
    uchar* p = (uchar*) data.data();
    for (int y = 0; y < img.height(); ++y) {
        for (int x = 0; x < img.width(); ++x, p += 2) {
            const QRgb & c = img.pixel(x, y);
            p[0] = (qAlpha(c) / 16) | (((qBlue(c)) / 16) << 4);
            p[1] = (qGreen(c) / 16) | (((qRed(c))  / 16) << 4);
        }
    }
    out.write(data);
    out.close();

    return true;
}
Esempio n. 25
0
void Encoder::convertRGBToYUV(VideoFramePointer frame, VideoFrameData *data)
{
    unsigned int Y_step = data->width * data->height;
    unsigned int UV_step = Y_step / 4;

    data->header.content_length = Y_step + UV_step * 2;
    data->data = new unsigned char[data->header.content_length];

    unsigned int i = 0, jy = 0, j = 0, yK = (data->width / 2);
    float L;
    unsigned char Y, U, V;
    unsigned char r, g, b;

    for (int y = 0; y < data->height; ++y) {
        jy = ((y - y % 2) / 2) * yK;
        for (int x = 0; x < data->width; ++x) {
            QRgb rgb = frame->asQImage().pixel(x, y);
            r = qRed(rgb);
            g = qGreen(rgb);
            b = qBlue(rgb);

            L = YUV_KR * r + YUV_KB * b + (1.0 - YUV_KR - YUV_KB) * g;

            Y = (219.0 * L / 255.0) + 16;

            data->data[i] = Y;

            if (x % 2 == 0 && y % 2 == 0) {
                U = (224.0 * 0.5 * (1.0 * b - L) / ((1.0 - YUV_KB) * 255.0)) + 128;
                V = (224.0 * 0.5 * (1.0 * r - L) / ((1.0 - YUV_KR) * 255.0)) + 128;

                j = jy + ((x - x % 2) / 2);

                data->data[Y_step + j] = U;
                data->data[Y_step + UV_step + j] = V;
            }
            ++i;
        }
    }
}
Esempio n. 26
0
QRgb Median::calcPixel ( const Convolution::Kernel& in_Kernel ) const
{
	//TODO найти более эффективный алгоритм

	/*std::vector <pixelLightSort> sort;
	sort.reserve(in_Kernel.size*in_Kernel.size);

	for ( int y = 0; y< in_Kernel.size; ++y ) {
		for ( int x = 0; x< in_Kernel.size; ++x ) {
			sort.push_back (in_Kernel(x,y));
		}
	}
	std::sort ( sort.begin(), sort.end());

	return sort[in_Kernel.size*in_Kernel.size/2].rgb; */
	std::vector <short> sortR;
	std::vector <short> sortG;
	std::vector <short> sortB;

	sortR.reserve(in_Kernel.size*in_Kernel.size);
	sortG.reserve(in_Kernel.size*in_Kernel.size);
	sortB.reserve(in_Kernel.size*in_Kernel.size);
	//sort.reserve(in_Kernel.size*in_Kernel.size);

	for ( int y = 0; y< in_Kernel.size; ++y ) {
		for ( int x = 0; x< in_Kernel.size; ++x ) {
			QRgb rgb = in_Kernel(x,y);
			sortR.push_back (qRed(rgb));
			sortG.push_back (qGreen(rgb));
			sortB.push_back (qBlue(rgb));
		}
	}
	std::sort ( sortR.begin(), sortR.end());
	std::sort ( sortG.begin(), sortG.end());
	std::sort ( sortB.begin(), sortB.end());

	return qRgb ( sortR[in_Kernel.size*in_Kernel.size/2],
		      sortG[in_Kernel.size*in_Kernel.size/2],
		      sortB[in_Kernel.size*in_Kernel.size/2] );
}
Esempio n. 27
0
void EmfPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &)
{
	setClipping();

	QMatrix m = painter()->worldMatrix();
	QPointF p = m.map(r.topLeft());
	int x = qRound(p.x());
	int y = qRound(p.y());
	int width = qRound(r.width());
	int height = qRound(r.height());

#ifdef Q_WS_WIN
	HBITMAP hbtmp = NULL;
	DWORD op = SRCCOPY;
	if (pm.hasAlpha()){
		QImage image = pm.scaled(width, height).toImage();
		image.invertPixels();
		hbtmp = QPixmap::fromImage (image).toWinHBITMAP();
		op = SRCINVERT;
	} else
		hbtmp = pm.scaled(width, height).toWinHBITMAP();

	HDC hDC = CreateCompatibleDC(metaDC);
    SelectObject(hDC, hbtmp);

    BitBlt(metaDC, x, y, width, height, hDC, 0, 0, op);
    DeleteObject(hbtmp);
    DeleteDC(hDC);
#else
	QImage image = pm.scaled(width, height).toImage();
	for (int i = 0; i < width; i++){
		for (int j = 0; j < height; j++){
			QRgb rgb = image.pixel(i, j);
			if (qAlpha(rgb) == 255)
				SetPixel(metaDC, x + i, y + j, RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
		}
	}
#endif
	resetClipping();
}
Esempio n. 28
0
void RecSkinColorPalette::getColor(const QColor &averageColor)
{
    isDrawEllipse = true;
    emit sigMousePressRGB(averageColor.rgb());
    hsvValue = averageColor.value();
    int width = 359;
    int height = 255;
    QImage temp(QSize(width, height), QImage::Format_ARGB32);
    for(int w = 0; w < width; ++w)
    {
        for(int h = 0; h < height; ++h)
        {
            QRgb rgb = QColor::fromHsv(w,h,hsvValue,255).rgb();
            QRgb r = qRgba(qRed(rgb), qGreen(rgb), qBlue(rgb), 255);
            temp.setPixel(w, h, r);
        }
    }

    drawImage = temp;
    QImage tempImage = drawImage.scaled(this->width(),this->height());

    bool isTrue = false;
    for(int i = 0; i < tempImage.width(); ++i)
    {
        for(int j = 0; j < tempImage.height(); ++j)
        {
            if(QColor::fromRgb(tempImage.pixel(i,j)) == averageColor)
            {
                mousePoint.setX(i);
                mousePoint.setY(j);
                isTrue = true;
                break;
            }

        }
        if(isTrue)
            break;
    }
    update();
}
Esempio n. 29
0
void RecSkinPushButton::mousePressEvent(QMouseEvent */*e*/)
{
    if(isSkin)
    {
        if(!isColorTrue)
        {
            QImage skinImage(originalPixmap.toImage());
            int num = 0;
            int red = 0;
            int green = 0;
            int blue = 0;
            for(int ii = 0; ii < skinImage.width(); ++ii)
            {
                for(int j = 0; j < skinImage.height(); ++j)
                {
                    ++num;
                    QRgb rgbValue(skinImage.pixel(ii, j));
                    red += qRed(rgbValue);
                    green += qGreen(rgbValue);
                    blue += qBlue(rgbValue);
                }
            }
            if(num != 0)
            {
                red = red/num;
                green = green/num;
                blue = blue/num;
            }
            averageColor = QColor(red,green,blue,255);
        }

        emit currentPixmap(fileName,originalPixmap,averageColor);
        emit clickNum(m_num);
    }
    else
    {
        emit clickResult();
    }

}
Esempio n. 30
0
QByteArray FieldModelLoaderPC::save() const
{
	quint16 nbHRC = this->model_nameHRC.size(), nbAnim, nameSize, i, j;
	QByteArray HRCs;
	QString modelName;
	QRgb color;

	for(i=0 ; i<nbHRC ; ++i) {
		modelName = this->model_nameChar.at(i);
		nameSize = modelName.size();
		HRCs.append((char *)&nameSize, 2); //model name size
		HRCs.append(modelName.toLocal8Bit()); //model Name (fieldnamename_of_char.char)
		HRCs.append((char *)&this->model_unknown.at(i), 2); //Unknown
		HRCs.append(this->model_nameHRC.at(i).leftJustified(8, '\x00', true)); //HRC name (AAAA.HRC)
		HRCs.append(QString::number(this->model_typeHRC.at(i)).leftJustified(4, '\x00', true)); //scale (512 )
		nbAnim = this->model_anims.at(i).size();
		HRCs.append((char *)&nbAnim, 2); //Nb Anims

		for(j=0 ; j<10 ; ++j) { //Colors
			color = this->colors.at(i).at(j);
			HRCs.append((char)qRed(color));
			HRCs.append((char)qGreen(color));
			HRCs.append((char)qBlue(color));
		}

		for(j=0 ; j<nbAnim ; ++j) { //Animations
			nameSize = this->model_anims.at(i).at(j).size();
			HRCs.append((char *)&nameSize, 2); //Animation name size
			HRCs.append(this->model_anims.at(i).at(j)); //Animation name
			HRCs.append((char *)&model_anims_unknown.at(i).at(j), 2); //Animation unknown
		}
	}

	quint16 fieldScale = field()->scriptsAndTexts()->scale();

	return QByteArray("\x00\x00", 2)
			.append((char *)&nbHRC, 2)
			.append((char *)&fieldScale, 2)
			.append(HRCs);
}