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; }
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); } } } }
void SegmentListVIIRSDNB::printData(SegmentVIIRSDNB *segm, int linesfrom, int viewsfrom) { int yaaa = 0; int xaaa = 0; fprintf(stderr, "projectionCoordX \n"); for( int i = linesfrom + 0; i < linesfrom + 32; i++) //this->NbrOfLines - 1; i++) { for( int j = viewsfrom + 0; j < viewsfrom + 16; j++) //this->earth_views_per_scanline - 1 ; j++ ) { fprintf(stderr, "%u, ", segm->getProjectionX(i,j)); } fprintf(stderr, "\n"); } fprintf(stderr, "projectionCoordY \n"); for( int i = linesfrom + 0; i < linesfrom + 32; i++) //this->NbrOfLines - 1; i++) { for( int j = viewsfrom + 0; j < viewsfrom + 16; j++) //this->earth_views_per_scanline - 1 ; j++ ) { fprintf(stderr, "%u, ", segm->getProjectionY(i,j)); } fprintf(stderr, "\n"); } fprintf(stderr, "projectionCoordValues \n"); for( int i = linesfrom + 0; i < linesfrom + 32; i++) //this->NbrOfLines - 1; i++) { for( int j = viewsfrom + 0; j < viewsfrom + 16; j++) //this->earth_views_per_scanline - 1 ; j++ ) { fprintf(stderr, "%u, ", qRed(segm->getProjectionValue(i,j))); } fprintf(stderr, "\n"); } }
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; }
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); }
/** * 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 )] ); } }
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); }
/*! 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; }
//============================================================================== 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); } } } }
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)); } } } }
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; }
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; }
//This function makes a pixmap which is based on icon, but has a number painted on it. QPixmap BoxContainerItem::calcComplexPixmap(const QPixmap &icon, const QColor &fgColour, const QFont *font, const int count) { QPixmap result(icon); QPixmap numberPixmap(icon.size()); QImage iconImage(icon.convertToImage()); QImage numberImage; QRgb *rgbline; QPainter p; //Make a transparent number; first make a white number on a black background. //This pixmap also is the base alpha-channel, the foreground colour is added later. numberPixmap.fill(Qt::black); p.begin(&numberPixmap, false); p.setPen(Qt::white); if(font) p.setFont(*font); p.drawText(icon.rect(), Qt::AlignCenter, QString::number(count)); p.end(); //Convert to image and add the alpha channel. numberImage = numberPixmap.convertToImage(); if(numberImage.depth() != 32) //Make sure depth is 32 (and thus can have an alpha channel) numberImage = numberImage.convertDepth(32); numberImage.setAlphaBuffer(true); //Enable alpha channel for(int xx = 0; xx < numberImage.height(); ++xx) { rgbline = (QRgb *)numberImage.scanLine(xx); for(int yy = 0; yy < numberImage.width(); ++yy) { //Set colour and alpha channel rgbline[ yy ] = qRgba(fgColour.red(), fgColour.green(), fgColour.blue(), qRed(rgbline[ yy ])); } } //Merge icon and number and convert to result. KIconEffect::overlay(iconImage, numberImage); result.convertFromImage(iconImage); return result; }
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(); }
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; }
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; }
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(); }
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); }
// 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)); } } }
void VolumeOperations::shrinkwrapSlice(uchar *swvr, int mx, int my) { memset(swvr, 0, my*mx); MorphSlice ms; QList<QPolygonF> poly = ms.boundaryCurves(swvr, mx, my, true); QImage pimg = QImage(mx, my, QImage::Format_RGB32); pimg.fill(0); QPainter p(&pimg); p.setPen(QPen(Qt::white, 1)); p.setBrush(Qt::white); for (int npc=0; npc<poly.count(); npc++) p.drawPolygon(poly[npc]); QRgb *rgb = (QRgb*)(pimg.bits()); for(int i=0; i<my*mx; i++) swvr[i] = (swvr[i]>0 || qRed(rgb[i])>0 ? 255 : 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; } } }
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; } } }
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; }
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] ); }
QImage ImageProcessor::spreadHistogram(QImage input) { //Really, this is normalization, http://en.wikipedia.org/wiki/Normalization_(image_processing) QImage returnMe(input.width(),input.height(),QImage::Format_ARGB32); QPainter painter(&returnMe); QVector<float> occ = ImageProcessor::findOccurrences(input); int lowest =0; bool goOn = true; for(int i=0;(i<occ.size()) && goOn;i++) { if(occ.at(i) == 0.0) { lowest = i; } else { goOn = false; } } int highest = 255; goOn =true; for(int i=occ.size()-1;(i>0) && goOn;i--) { if(occ.at(i) == 0.0) { highest = i; } else { goOn = false; } } int diff = highest - lowest; for(int x=0;x<input.width();x++) { for(int y=0;y<input.height();y++) { int value = qRed(input.pixel(x,y)); int newValue =(int) ((value - lowest) * (255.0 / diff)); //TODO: faster way to fill those pixels painter.fillRect(x,y,1,1,QColor(newValue,newValue,newValue)); } } return returnMe; }
bool DistanceFieldWriter::Export(QFile& file) { QImage pixmap = buildImage(); DistanceField * field = new DistanceField(pixmap.width(), pixmap.height()); for(int y = 0; y < pixmap.height(); y++) { const QRgb * scanline = (QRgb*)pixmap.scanLine(y); for(int x = 0; x < pixmap.width(); x++) { field->SetPixel(x, y, qAlpha(scanline[x]) <= 0); } } field->Generate(); QImage largePixmap(pixmap.width(),pixmap.height(),QImage::Format_Indexed8); largePixmap.setColorCount(256); for(int i = 0; i < 256; i++) largePixmap.setColor(i, qRgb(i,i,i)); for(int y = 0; y < pixmap.height(); y++) { for(int x = 0; x < pixmap.width(); x++) { int dist = field->GetDistance(x, y) + 128; if(dist < 0) dist = 0; if(dist > 255) dist = 255; largePixmap.setPixel(x, y, dist); } } delete field; /* Scale the large distance field down */ QImage smallPixmap = largePixmap.scaled(pixmap.width() / 16, pixmap.height() / 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); /* Convert the small pixmap to indexed format */ QImage small8BitPixmap(smallPixmap.width(), smallPixmap.height(), QImage::Format_Indexed8); for(int i = 0; i < 256; i++) small8BitPixmap.setColor(i, qRgb(i,i,i)); for(int y = 0; y < smallPixmap.height(); y++) { const QRgb * scanline = (QRgb*)smallPixmap.scanLine(y); for(int x = 0; x < smallPixmap.width(); x++) { small8BitPixmap.setPixel(x, y, qRed(scanline[x])); } } small8BitPixmap.save(&file, m_format.toUtf8().data()); return true; }
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(); }
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(); } }
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); }
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(); }