コード例 #1
0
ファイル: MetavoxelSystem.cpp プロジェクト: Chris7/hifi
int MetavoxelSystem::SimulateVisitor::visit(MetavoxelInfo& info) {
    SpannerVisitor::visit(info);

    if (!info.isLeaf) {
        return _order;
    }
    QRgb color = info.inputValues.at(0).getInlineValue<QRgb>();
    QRgb normal = info.inputValues.at(1).getInlineValue<QRgb>();
    int alpha = qAlpha(color);
    if (alpha > 0) {
        Point point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size),
            { qRed(color), qGreen(color), qBlue(color), alpha }, { qRed(normal), qGreen(normal), qBlue(normal) } };
        _points.append(point);
    }
    return STOP_RECURSION;
}
コード例 #2
0
void FilterOp::filterHorizontally(QImage &src, QRgb *trg, const QRgb *rgba)
{
    const uchar* pixels = src.constScanLine(0);
    int sourcePitch = src.bytesPerLine();

    for (int k = 0; k < srcHeight; ++k)
    {
        int destOfsY = dstWidth * k;
        for (int i = dstWidth - 1; i >= 0 ; --i)
        {
            float red = 0;
            float green = 0;
            float blue = 0;
            float alpha = 0;

            int max = horizontalSubsamplingData.numberOfSamples[i];
            int index = i * horizontalSubsamplingData.matrixWidth;

            for (int j = max - 1; j >= 0; --j)
            {
                int ofsX = horizontalSubsamplingData.pixelPositions[index];
                int palIdx = pixels[ofsX] & 0xff;
                float w = horizontalSubsamplingData.weights[index];
                red += qRed(rgba[palIdx]) * w;
                green += qGreen(rgba[palIdx]) * w;
                blue+= qBlue(rgba[palIdx]) * w;
                alpha += qAlpha(rgba[palIdx]) * w;
                index++;
            }

            int ri = std::max((int)red, 0);
            ri = std::min(ri, 255);

            int gi = std::max((int)green, 0);
            gi = std::min(gi, 255);

            int bi = std::max((int)blue, 0);
            bi = std::min(bi, 255);

            int ai = std::max((int)alpha, 0);
            ai = std::min(ai, 255);

            trg[i + destOfsY] = qRgba(ri, gi, bi, ai);
        }
        pixels += sourcePitch;
    }
}
コード例 #3
0
QImage ColorMatrixEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const
{
    QImage result = image;

    QRgb *src = (QRgb*)image.bits();
    QRgb *dst = (QRgb*)result.bits();
    int w = result.width();

    const qreal * m = m_matrix.data();
    qreal sa, sr, sg, sb;
    qreal da, dr, dg, db;

    QRect roi = context.filterRegion().toRect();
    for (int row = roi.top(); row < roi.bottom(); ++row) {
        for (int col = roi.left(); col < roi.right(); ++col) {
            const QRgb &s = src[row*w+col];
            sa = fromIntColor[qAlpha(s)];
            sr = fromIntColor[qRed(s)];
            sg = fromIntColor[qGreen(s)];
            sb = fromIntColor[qBlue(s)];
            // the matrix is applied to non-premultiplied color values
            // so we have to convert colors by dividing by alpha value
            if (sa > 0.0 && sa < 1.0) {
                sr /= sa;
                sb /= sa;
                sg /= sa;
            }

            // apply matrix to color values
            dr = m[ 0] * sr + m[ 1] * sg + m[ 2] * sb + m[ 3] * sa + m[ 4];
            dg = m[ 5] * sr + m[ 6] * sg + m[ 7] * sb + m[ 8] * sa + m[ 9];
            db = m[10] * sr + m[11] * sg + m[12] * sb + m[13] * sa + m[14];
            da = m[15] * sr + m[16] * sg + m[17] * sb + m[18] * sa + m[19];

            // the new alpha value
            da *= 255.0;

            // set pre-multiplied color values on destination image
            dst[row*w+col] = qRgba(static_cast<quint8>(qBound(qreal(0.0), dr * da, qreal(255.0))),
                                   static_cast<quint8>(qBound(qreal(0.0), dg * da, qreal(255.0))),
                                   static_cast<quint8>(qBound(qreal(0.0), db * da, qreal(255.0))),
                                   static_cast<quint8>(qBound(qreal(0.0), da, qreal(255.0))));
        }
    }

    return result;
}
コード例 #4
0
ファイル: layer.cpp プロジェクト: LionsPhil/Drawpile
/**
 * @param x
 * @param y
 * @return invalid color if x or y is outside image boundaries
 */
QColor Layer::colorAt(int x, int y, int dia) const
{
    if(x<0 || y<0 || x>=_width || y>=_height)
        return QColor();

    if(dia<=1) {
        quint32 c = pixelAt(x, y);
        if(qAlpha(c)==0)
            return QColor();

        return QColor::fromRgb(c);
    } else {
        Brush b(dia, 0.9);
        BrushStamp bs = makeGimpStyleBrushStamp(b, Point(x, y, 1));
        return getDabColor(bs);
    }
}
コード例 #5
0
ファイル: Spinda.cpp プロジェクト: ncorgan/libpkmn
 static void drawSpindaSpot(
     QImage* image,
     const spinda_coords* coords,
     const char** single_spot_map,
     const spinda_colors_t* face_colors,
     const spinda_colors_t* spot_colors
 )
 {
     for(size_t i = 0; i < MAX_SPOT_HEIGHT and single_spot_map[i] != NULL; ++i)
     {
         for(size_t j = 0; j < std::strlen(single_spot_map[i]); ++j)
         {
             if(single_spot_map[i][j] == '*')
             {
                 QPoint point(
                            int(coords->x+j),
                            int(coords->y+i)
                        );
                 if(qAlpha(image->pixel(point)) > 0)
                 {
                     if(image->pixel(point) == face_colors->color_main.rgb())
                     {
                         image->setPixel(
                             point,
                             spot_colors->color_main.rgb()
                         );
                     }
                     else if(image->pixel(point) == face_colors->color_light.rgb())
                     {
                         image->setPixel(
                             point,
                             spot_colors->color_light.rgb()
                         );
                     }
                     else if(image->pixel(point) == face_colors->color_dark.rgb())
                     {
                         image->setPixel(
                             point,
                             spot_colors->color_dark.rgb()
                         );
                     }
                 }
             }
         }
     }
 }
コード例 #6
0
ファイル: qkernelconv.cpp プロジェクト: LilyOfTheWest/image
QImage QKernelConv::inverseColor(QImage *src) {
    QRgb color,color2;
    int r,g,b,alpha;
    QImage *ret = new QImage(src->width(),src->height(),src->format());
    for (int i=0; i< src->height() ; i++) {
        for (int j=0; j<src->width() ; j++) {
            color=src->pixel(j,i);
            r=255-qRed(color);
            g=255-qBlue(color);
            b=255-qGreen(color);
            alpha=qAlpha(color);
            color2=qRgba(r,g,b,alpha);
            ret->setPixel(j,i,color2);
        }
    }
    return *ret;
}
コード例 #7
0
QgsRasterBlock* QgsSingleBandColorDataRenderer::block( int bandNo, QgsRectangle  const & extent, int width, int height )
{
  Q_UNUSED( bandNo );

  QgsRasterBlock *outputBlock = new QgsRasterBlock();
  if ( !mInput )
  {
    return outputBlock;
  }

  QgsRasterBlock *inputBlock = mInput->block( mBand, extent, width, height );
  if ( !inputBlock || inputBlock->isEmpty() )
  {
    QgsDebugMsg( "No raster data!" );
    delete inputBlock;
    return outputBlock;
  }

  bool hasTransparency = usesTransparency();
  if ( !hasTransparency )
  {
    // Nothing to do, just retype if necessary
    inputBlock->convert( QgsRasterBlock::ARGB32_Premultiplied );
    delete outputBlock;
    return inputBlock;
  }

  if ( !outputBlock->reset( QgsRasterBlock::ARGB32_Premultiplied, width, height ) )
  {
    delete inputBlock;
    return outputBlock;
  }

  for ( size_t i = 0; i < ( size_t )width*height; i++ )
  {
    QRgb pixelColor;
    double alpha = 255.0;
    QRgb c = inputBlock->color( i );
    alpha = qAlpha( c );
    pixelColor = qRgba( mOpacity * qRed( c ), mOpacity * qGreen( c ), mOpacity * qBlue( c ), mOpacity * alpha );
    outputBlock->setColor( i,  pixelColor );
  }

  delete inputBlock;
  return outputBlock;
}
コード例 #8
0
ファイル: qiconset.cpp プロジェクト: opieproject/qte-opie
static QPixmap* newDisablePixmap(const QPixmap& pm)
{
    // Use nice alpha-blended pixmaps
    QImage i = pm.convertToImage().convertDepth(32);
    for ( int y = 0; y < i.height(); y++ ) {
	for ( int x = 0; x < i.width(); x++ ) {
	    QRgb p = i.pixel( x, y );
	    int a = qAlpha(p)/3;
	    int g = qGray(qRed(p),qGreen(p),qBlue(p));
	    i.setPixel( x, y, qRgba(g,g,g,a) );
	}
    }
    i.setAlphaBuffer( TRUE );
    QPixmap* r = new QPixmap;
    r->convertFromImage(i);
    return r;
}
コード例 #9
0
// compute changes. TODO: implement functionality to do this on the gpu
void UnitySupportGui::addToSmoothness(int to_apply)
{
    for (int y=0; y<image->height();y++)
    {
        for(int x = 0; x<image->width();x++)
        {
            QRgb* line_out = (QRgb *)image->scanLine(y);

            line_out += x;
            int appliedValue = qAlpha(*line_out)+to_apply;
            int c = qGreen(*line_out);

            //Supposed to be a grayscaled Image;
            *line_out = qRgba(c,c,c,appliedValue);
        }
    }
}
コード例 #10
0
ファイル: util_icon.cpp プロジェクト: JLuc/scribus
void SCRIBUS_API iconToGrayscale(QPixmap* pm)
{
	QImage qi(pm->toImage());
	int h=qi.height();
	int w=qi.width();
	QRgb c_rgb;
	for (int i=0;i<w;++i)
	{
		for (int j=0;j<h;++j)
		{
			c_rgb=qi.pixel(i,j);
			int k = qMin(qRound(0.3 * qRed(c_rgb) + 0.59 * qGreen(c_rgb) + 0.11 * qBlue(c_rgb)), 255);
			qi.setPixel(i, j, qRgba(k, k, k, qAlpha(c_rgb)));
		}
	}
	*pm=QPixmap::fromImage(qi);
}
コード例 #11
0
ファイル: data.cpp プロジェクト: MinjieTao/PoissonImage
void Data::crackImage()
{
    if(subImage.isNull()||maskImage.isNull())
        return;

    int w, h;

    w=maskImage.width();
    h=maskImage.height();



    for(int y=0;y<h;y++)
    {
        for(int x=0;x<w;x++)
        {
            QRgb val=subImage.pixel(x,y);
           if(qAlpha(val)==255)
           {
               QPoint p(x,y);
               pixData newPix;
               newPix.p=p;
               newPix.d=val;
                fp<<newPix;
                index[getId(newPix.p)]=fp.count()-1;

           }

        }
    }

    for(int i=0;i<fp.count();i++)
    {
        QPoint newNeigh;
        QPoint p;
        p=fp[i].p;
        newNeigh=p+QPoint(1,0);
        checkNeigh(i,newNeigh);
        newNeigh=p+QPoint(0,1);
        checkNeigh(i,newNeigh);
        newNeigh=p+QPoint(-1,0);
        checkNeigh(i,newNeigh);
        newNeigh=p+QPoint(0,-1);
        checkNeigh(i,newNeigh);
    }
}
コード例 #12
0
ファイル: sepia.cpp プロジェクト: amtep/quillimagefilters
QuillImage Sepia::apply(const QuillImage &image) const
{
    QuillImage newImage(image);

    QRgb *endp = (QRgb*)(newImage.bits()+newImage.byteCount());

    // Apply the actual operation

    for (QRgb *p=(QRgb*)newImage.bits(); p<endp; p++)
    {
        QRgb rgb = *p;

        int colorvalue = (qRed(rgb)*299 + qGreen(rgb)*587 + qBlue(rgb)*114)
            / 1000;

        int newRed, newGreen, newBlue;

        if (colorvalue < 128) {
            newRed = colorvalue;
            newGreen = colorvalue * 104 / 128;
            newBlue = colorvalue * 69 / 128;
        }
        else {
            newRed = colorvalue;
            newGreen = 104 + (colorvalue-128) * 152 / 128;
            newBlue = 69 + (colorvalue-128) * 187 / 128;
        }

        if (newRed < 0) newRed = 0;
        if (newRed > 255) newRed = 255;

        if (newGreen < 0) newGreen = 0;
        if (newGreen > 255) newGreen = 255;

        if (newBlue < 0) newBlue = 0;
        if (newBlue > 255) newBlue = 255;

	*p = qRgba(newRed, newGreen, newBlue,
		   qAlpha(rgb));
    }

    newImage = Vignette::apply(newImage, 1.0, 0.5);

    return newImage;
}
コード例 #13
0
ファイル: rgbimage.cpp プロジェクト: bjorkegeek/qlcplus
RGBMap RGBImage::rgbMap(const QSize& size, uint rgb, int step)
{
    Q_UNUSED(rgb);

    QMutexLocker locker(&m_mutex);

    if (m_image.width() == 0 || m_image.height() == 0)
        return RGBMap();

    int xOffs = xOffset();
    int yOffs = yOffset();

    switch(animationStyle()) 
    {
    default:
    case Static:
        break;
    case Horizontal:
        xOffs += step;
        break;
    case Vertical:
        yOffs += step;
        break;
    case Animation:
        xOffs += step * size.width();
        break;
    }

    RGBMap map(size.height());
    for (int y = 0; y < size.height(); y++)
    {
        map[y].resize(size.width());
        for (int x = 0; x < size.width(); x++)
        {
            int x1 = (x + xOffs) % m_image.width();
            int y1 = (y + yOffs) % m_image.height();

            map[y][x] = m_image.pixel(x1,y1);
            if (qAlpha(map[y][x]) == 0)
                map[y][x] = 0;
        }
    }

    return map;
}
コード例 #14
0
/**
 * Automatic marshaling of a QImage for org.freedesktop.Notifications.Notify
 *
 * This function is from the Clementine project (see
 * http://www.clementine-player.org) and licensed under the GNU General Public
 * License, version 3 or later.
 *
 * Copyright 2010, David Sansome <*****@*****.**>
 */
QDBusArgument &operator<<( QDBusArgument &arg, const QImage &image )
{
  if ( image.isNull() )
  {
    arg.beginStructure();
    arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
    arg.endStructure();
    return arg;
  }

  QImage scaled = image.scaledToHeight( 100, Qt::SmoothTransformation );
  scaled = scaled.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.numBytes() );
  arg.endStructure();
  return arg;
}
コード例 #15
0
void RenderArea::updateInputPoints()
{
    int intensity;

    inputPoints->clear();

    for (int i = 0; i < m_points_count; i++)
    {
        columnPoints *column = new columnPoints;

        for (int o = m_points_count - 1; o >= 0; o--)
        {
            intensity = QColor(imageInput->pixel(centerX + i,centerY + o)).red();
            FPoint *point = new FPoint;

            if (imageMask)
            {
                QRgb bodMasky = imageMask->pixel(centerX + i,centerY + o);

                if (qAlpha(bodMasky) == 255)
                {
                    intensity = -1;
                }
            }

            point->intensity = intensity;

            /*
            if (i == m_points_count - 1)
            {
                qDebug() << "o - intensity" << o << " - " << intensity;

                // intenzita je v poøádku, test mapy je tøeba!
            }
            */

            column->append(point);
        }

        inputPoints->append(column);
    }

    emit pointsChanged();
}
コード例 #16
0
void FilterOp::filterVertically(QVector<QRgb>& src, QVector<QRgb>& trg)
{
    const QRgb *inPixels = src.constData();

    for (int x = 0; x < dstWidth; ++x)
    {
        for (int y = dstHeight - 1; y >= 0 ; --y)
        {
            int yTimesNumContributors = y * verticalSubsamplingData.matrixWidth;
            int max = verticalSubsamplingData.numberOfSamples[y];
            int ofsY = dstWidth * y;
            float red = 0;
            float green = 0;
            float blue = 0;
            float alpha = 0;

            int index = yTimesNumContributors;
            for (int j = max - 1; j >= 0 ; --j)
            {
                int color = inPixels[x + (dstWidth * verticalSubsamplingData.pixelPositions[index])];
                float w = verticalSubsamplingData.weights[index];
                alpha += qAlpha(color) * w;
                red += qRed(color) * w;
                green += qGreen(color) * w;
                blue += qBlue(color) * w;
                index++;
            }

            int ri = std::max((int)red, 0);
            ri = std::min(ri, 255);

            int gi = std::max((int)green, 0);
            gi = std::min(gi, 255);

            int bi = std::max((int)blue, 0);
            bi = std::min(bi, 255);

            int ai = std::max((int)alpha, 0);
            ai = std::min(ai, 255);

            trg[x + ofsY] = qRgba(ri, gi, bi, ai);
        }
    }
}
コード例 #17
0
ファイル: cell.cpp プロジェクト: radekp/qneoroid
void Cell::initPixmaps()
{
  typedef QMap<int, QString> NamesMap;
  NamesMap names;
  names[L]     = "0001";
  names[D]     = "0010";
  names[D|L]   = "0011";
  names[R]     = "0100";
  names[R|L]   = "0101";
  names[R|D]   = "0110";
  names[R|D|L] = "0111";
  names[U]     = "1000";
  names[U|L]   = "1001";
  names[U|D]   = "1010";
  names[U|D|L] = "1011";
  names[U|R]   = "1100";
  names[U|R|L] = "1101";
  names[U|R|D] = "1110";

  NamesMap::ConstIterator it;
  for(it = names.constBegin(); it != names.constEnd(); ++it)
  {
    connectedpixmap[it.key()] = new QPixmap(":/cable" + it.value() + ".png");

    QImage image = connectedpixmap[it.key()]->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 + 4 * qGreen(pix)) / 5;
          int b = (255 + 4 * qBlue(pix)) / 5;
          int r = (255 + 4 * qRed(pix)) / 5;
          line[x] = qRgb(r, g, b);
        }
      }
    }

    disconnectedpixmap[it.key()] = new QPixmap(QPixmap::fromImage(image));
  }
}
コード例 #18
0
bb::ImageData PictureHelper::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;
}
コード例 #19
0
ファイル: BT_StickyNoteActor.cpp プロジェクト: DX94/BumpTop
void StickyNoteActor::toGrayScale(QImage& image, int bias) const
{
	// naive grayscale conversion, since it is only done once when 
	// the theme is loaded/changed
	// http://en.wikipedia.org/wiki/Grayscale
	QRgb pixel;
	int gray = 0;
	int width = image.width();
	int height = image.height();
	for (int i = 0; i < height; ++i)
	{
		for (int j = 0; j < width; ++j)
		{
			pixel = image.pixel(j, i);
			gray = (11 * qRed(pixel) + 16 * qGreen(pixel) + 5 * qBlue(pixel)) / 32 + bias;
			image.setPixel(j, i, qRgba(gray, gray, gray, qAlpha(pixel)));
		}
	}
}
コード例 #20
0
static void addImage( FlifEncoder& encoder, const QImage& in ) {
    FlifImage img( in.width(), in.height() );

    auto buffer = std::make_unique<uint8_t[]>( in.width() * 4 );
    for( int iy=0; iy<in.height(); iy++ ) {
        auto line = (const QRgb*)in.constScanLine( iy );

        for( int ix=0; ix<in.width(); ix++ ) {
            buffer[ix*4+0] = qRed( line[ix] );
            buffer[ix*4+1] = qGreen( line[ix] );
            buffer[ix*4+2] = qBlue( line[ix] );
            buffer[ix*4+3] = qAlpha( line[ix] );
        }

        img.writeRowRgba8( iy, buffer.get(), in.width() * 4 );
    }

    encoder.addImage( img ); //TODO: investigate memory model
}
コード例 #21
0
ファイル: imageProcessor.cpp プロジェクト: hywwqq/Android
static void _gray(QString sourceFile, QString destFile)
{
    QImage image(sourceFile);
    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);
}
コード例 #22
0
ファイル: TextureCache.cpp プロジェクト: brotchie/hifi
void DilatableNetworkTexture::imageLoaded(const QImage& image) {
    _image = image;
    
    // scan out from the center to find inner and outer radii
    int halfWidth = image.width() / 2;
    int halfHeight = image.height() / 2;
    const int BLACK_THRESHOLD = 32;
    while (_innerRadius < halfWidth && qGray(image.pixel(halfWidth + _innerRadius, halfHeight)) < BLACK_THRESHOLD) {
        _innerRadius++;
    }
    _outerRadius = _innerRadius;
    const int TRANSPARENT_THRESHOLD = 32;
    while (_outerRadius < halfWidth && qAlpha(image.pixel(halfWidth + _outerRadius, halfHeight)) > TRANSPARENT_THRESHOLD) {
        _outerRadius++;
    }
    
    // clear out any textures we generated before loading
    _dilatedTextures.clear();
}
コード例 #23
0
ファイル: bitmap.cpp プロジェクト: HanruZhou/wxWidgets
static wxImage ConvertImage( QImage qtImage )
{
    bool hasAlpha = qtImage.hasAlphaChannel();
    
    int numPixels = qtImage.height() * qtImage.width();

    //Convert to ARGB32 for scanLine
    qtImage = qtImage.convertToFormat(QImage::Format_ARGB32);
    
    unsigned char *data = (unsigned char *)malloc(sizeof(char) * 3 * numPixels);
    unsigned char *startData = data;
    
    unsigned char *alpha = NULL;
    if (hasAlpha)
        alpha = (unsigned char *)malloc(sizeof(char) * numPixels);

    unsigned char *startAlpha = alpha;
    
    for (int y = 0; y < qtImage.height(); y++)
    {
        QRgb *line = (QRgb*)qtImage.scanLine(y);
        
        for (int x = 0; x < qtImage.width(); x++)
        {
            QRgb colour = line[x];
            
            data[0] = qRed(colour);
            data[1] = qGreen(colour);
            data[2] = qBlue(colour);
            
            if (hasAlpha)
            {
                alpha[0] = qAlpha(colour);
                alpha++;
            }
            data += 3;
        }
    }
    if (hasAlpha)
        return wxImage(wxQtConvertSize(qtImage.size()), startData, startAlpha);
    else
        return wxImage(wxQtConvertSize(qtImage.size()), startData);
}
コード例 #24
0
ファイル: gimageutils.cpp プロジェクト: lexical/unity2d
QImage imageForPixbuf(const GdkPixbuf* pixbuf, const QString &name)
{
    QImage result;
    if (gdk_pixbuf_get_n_channels(pixbuf) == 3 && gdk_pixbuf_get_bits_per_sample(pixbuf) == 8 && !gdk_pixbuf_get_has_alpha(pixbuf)) {
        const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf),
                             gdk_pixbuf_get_width(pixbuf),
                             gdk_pixbuf_get_height(pixbuf),
                             gdk_pixbuf_get_rowstride(pixbuf),
                             QImage::QImage::Format_RGB888);
        result = image.convertToFormat(QImage::Format_ARGB32);
    } else {
        if (gdk_pixbuf_get_n_channels(pixbuf) != 4 || gdk_pixbuf_get_bits_per_sample(pixbuf) != 8 || !gdk_pixbuf_get_has_alpha(pixbuf)) {
            UQ_WARNING << "Pixbuf is not in the expected format. Trying to load it anyway, will most likely fail" << name;
        }
        const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf),
                             gdk_pixbuf_get_width(pixbuf),
                             gdk_pixbuf_get_height(pixbuf),
                             gdk_pixbuf_get_rowstride(pixbuf),
                             QImage::Format_ARGB32);

#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
        /* ABGR → ARGB */
        result = image.rgbSwapped();
#else
        /* ABGR → BGRA */
        /* Reference: https://bugs.launchpad.net/unity-2d/+bug/758782 */
        result = QImage(image.size(), image.format());
        for (int i = 0; i < swappedImage.height(); ++i) {
            QRgb* p = (QRgb*) image.constScanLine(i);
            QRgb* q = (QRgb*) swappedImage.scanLine(i);
            QRgb* end = p + image.width();
            while (p < end) {
                *q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p));
                p++;
                q++;
            }
        }
#endif
    }

    return result;
}
コード例 #25
0
ファイル: shadowengine.cpp プロジェクト: KDE/smaragd
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));
}
コード例 #26
0
ファイル: playlistitem.cpp プロジェクト: gms8994/amarok-1.4
/**
 * 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 )] );
    }
}
コード例 #27
0
ファイル: viratingwidget.cpp プロジェクト: EQ4/Visore
ViRatingItem::ViRatingItem(QWidget *parent, bool grayScale)
	: ViWidget(parent)
{
	//mImage.load(ViThemeManager::image("star.png", ViThemeImage::Normal, ViThemeManager::Icon).path());
	if(grayScale)
	{
		int value;
		QRgb rgb;
		for(int i = 0; i < mImage.width(); ++i)	
		{
			for(int j = 0; j < mImage.height(); ++j)
			{
				rgb = mImage.pixel(i, j);
				value = GRAY(rgb);
				mImage.setPixel(i, j, qRgba(value, value, value, qAlpha(rgb)));
			}
		}
	}
	mOffset = 0;
}
コード例 #28
0
ファイル: shade.cpp プロジェクト: mgottschlag/kwin-tiling
int main( int argc, char* argv[] )
{
    if( argc != 2 )
        return 1;
    QImage im( argv[ 1 ] );
    if( im.isNull())
        return 2;
    for( int x = 0;
            x < im.width();
            ++x )
        for( int y = 0;
                y < im.height();
                ++y )
        {
            QRgb c = im.pixel( x, y );
            QRgb c2 = qRgba( qGray( c ), qGray( c ), qGray( c ), qAlpha( c ) / 2 );
            im.setPixel( x, y, c2 );
        }
    im.save( "result.png", "PNG" );
}
コード例 #29
0
ファイル: cell.cpp プロジェクト: Summeli/NetwalkMobile-BB10
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);
}
コード例 #30
0
ファイル: pictureflow.cpp プロジェクト: ashang/fqterm
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;
}