ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const
{
    Q_ASSERT( index >= 0 && index < TABLE_COLORS );

    if ( randomSeed != 0 )
        qsrand(randomSeed);

    ColorEntry entry = colorTable()[index];

    if ( randomSeed != 0 &&
        _randomTable != 0 &&
        !_randomTable[index].isNull() )
    {
        const RandomizationRange& range = _randomTable[index];


        int hueDifference = range.hue ? (qrand() % range.hue) - range.hue/2 : 0;
        int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation/2 : 0;
        int  valueDifference = range.value ? (qrand() % range.value) - range.value/2 : 0;

        QColor& color = entry.color;

        int newHue = qAbs( (color.hue() + hueDifference) % MAX_HUE );
        int newValue = qMin( qAbs(color.value() + valueDifference) , 255 );
        int newSaturation = qMin( qAbs(color.saturation() + saturationDifference) , 255 );

        color.setHsv(newHue,newSaturation,newValue);
    }

    return entry;
}
Пример #2
0
inline QImage threshold(const QImage &src,
                        const QVector<int> &thresholds,
                        const QVector<int> &colors)
{
    QImage dst(src.size(), src.format());
    QVector<quint8> colorTable(256);
    int j = 0;

    for (int i = 0; i < colorTable.size(); i++) {
        if (j < thresholds.size() && i >= thresholds[j])
            j++;

        colorTable[i] = quint8(colors[j]);
    }

    for (int y = 0; y < src.height(); y++) {
        const quint8 *srcLine = src.constScanLine(y);
        quint8 *dstLine = dst.scanLine(y);

        for (int x = 0; x < src.width(); x++)
            dstLine[x] = colorTable[srcLine[x]];
    }

    return dst;
}
void DREAM3DGraphicsView::loadBaseImageFile(const QString& filename)
{
  m_BaseImage = QImage(filename);
  if (m_BaseImage.isNull() == true)
  {
    return;
  }
  QSize pSize(0, 0);
  pSize = m_BaseImage.size();

  m_OverlayImage = m_BaseImage;
  m_CompositedImage = m_BaseImage;

  QVector<QRgb > colorTable(256);
  for (quint32 i = 0; i < 256; ++i)
  {
    colorTable[i] = qRgb(i, i, i);
  }
  m_BaseImage.setColorTable(colorTable);

  if (m_BaseImage.isNull() == true)
  {
    std::cout << "Base Image was NULL for some reason. Returning" << std::endl;
    return;
  }
  QGraphicsScene* gScene = scene();
  if (gScene == NULL)
  {
    gScene = new QGraphicsScene(this);
    setScene(gScene);
  }
  else
  {

    setScene(NULL);
    gScene->deleteLater();
    gScene = new QGraphicsScene(this);
    setScene(gScene);

    delete m_ImageGraphicsItem;
    m_ImageGraphicsItem = NULL;
  }
  if (NULL == m_ImageGraphicsItem)
  {
    QImageReader reader(filename);
    QPixmap pixmap = QPixmap::fromImageReader(&reader, 0);
    m_ImageGraphicsItem = gScene->addPixmap(pixmap);
  }
  m_ImageGraphicsItem->setAcceptDrops(true);
  m_ImageGraphicsItem->setZValue(-1);


  QRectF rect = m_ImageGraphicsItem->boundingRect();
  gScene->setSceneRect(rect);
  centerOn(m_ImageGraphicsItem);
  this->updateDisplay();
  emit fireBaseImageFileLoaded(filename);
}
Пример #4
0
int QgsGrassRasterProvider::colorInterpretation( int bandNo ) const
{
  // TODO: avoid loading color table here or cache it
  QList<QgsColorRampShader::ColorRampItem> ct = colorTable( bandNo );
  if ( ct.size() > 0 )
  {
    return QgsRaster::ContinuousPalette;
  }
  return QgsRaster::GrayIndex;
}
void ColorScheme::write(KConfig& config) const
{
    KConfigGroup configGroup = config.group("General");

    configGroup.writeEntry("Description",_description);
    configGroup.writeEntry("Opacity",_opacity);

    for (int i=0 ; i < TABLE_COLORS ; i++)
    {
        RandomizationRange random = _randomTable != 0 ? _randomTable[i] : RandomizationRange();
        writeColorEntry(config,colorNameForIndex(i),colorTable()[i],random);
    }
}
Пример #6
0
QVector<QColor> ZLabelColorTable::constructColorTable()
{
  QVector<QColor> colorTable(10);

  colorTable[0] = QColor(Qt::white);
  colorTable[1] = QColor(Qt::red);
  colorTable[2] = QColor(Qt::green);
  colorTable[3] = QColor(Qt::blue);
  colorTable[4] = QColor(Qt::cyan);
  colorTable[5] = QColor(Qt::magenta);
  colorTable[6] = QColor(Qt::yellow);
  colorTable[7] = QColor(Qt::darkCyan);
  colorTable[8] = QColor(165, 42, 42);
  colorTable[9] = QColor(255, 140, 0);

  for (QVector<QColor>::iterator iter = colorTable.begin();
       iter != colorTable.end(); ++iter) {
    iter->setAlpha(128);
  }

  return colorTable;
}
Пример #7
0
// Regression test for decoding a gif image with sampleSize of 4, which was
// previously crashing.
DEF_TEST(Gif_Sampled, r) {
    SkAutoTDelete<SkFILEStream> stream(
            new SkFILEStream(GetResourcePath("test640x479.gif").c_str()));
    REPORTER_ASSERT(r, stream->isValid());
    if (!stream->isValid()) {
        return;
    }

    SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
    REPORTER_ASSERT(r, codec);
    if (!codec) {
        return;
    }

    // Construct a color table for the decode if necessary
    SkAutoTUnref<SkColorTable> colorTable(nullptr);
    SkPMColor* colorPtr = nullptr;
    int* colorCountPtr = nullptr;
    int maxColors = 256;
    if (kIndex_8_SkColorType == codec->getInfo().colorType()) {
        SkPMColor colors[256];
        colorTable.reset(new SkColorTable(colors, maxColors));
        colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
        colorCountPtr = &maxColors;
    }

    SkAndroidCodec::AndroidOptions options;
    options.fSampleSize = 4;
    options.fColorPtr = colorPtr;
    options.fColorCount = colorCountPtr;

    SkBitmap bm;
    bm.allocPixels(codec->getInfo(), nullptr, colorTable.get());
    const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.getPixels(),
            bm.rowBytes(), &options);
    REPORTER_ASSERT(r, result == SkCodec::kSuccess);
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureImageUtilities::GenerateScalarBar(int imageWidth, int imageHeight, PoleFigureConfiguration_t& config)
{
  int numColors = config.numColors;
  QImage pImage(imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
  pImage.fill(0xFFFFFFFF); // All white background

  // Create a Painter backed by a QImage to draw into
  QPainter painter;
  painter.begin(&pImage);
  painter.setRenderHint(QPainter::Antialiasing, true);

  int penWidth = 1;

#if 0
  // DRAW A BORDER AROUND THE IMAGE FOR DEBUGGING
  QColor c(RgbColor::dRgb(255, 0, 0, 255));
  painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));

  painter.drawLine(0, 0, imageWidth, 0); // Top
  painter.drawLine(0, 0, 0, imageHeight); // Left
  painter.drawLine(imageWidth, 0, imageWidth, imageHeight); // Right
  painter.drawLine(0, imageHeight, imageWidth, imageHeight); // Bottom
  //-----------------
#endif

  //Get all the colors that we will need
  QVector<SIMPL::Rgb> colorTable(numColors);
  QVector<float> colors(3 * numColors, 0.0);
  SIMPLColorTable::GetColorTable(numColors, colors); // Generate the color table values
  float r = 0.0, g = 0.0, b = 0.0;
  for (int i = 0; i < numColors; i++) // Convert them to QRgbColor values
  {
    r = colors[3 * i];
    g = colors[3 * i + 1];
    b = colors[3 * i + 2];
    colorTable[i] = RgbColor::dRgb(r * 255, g * 255, b * 255, 255);
  }

  // Now start from the bottom and draw colored lines up the scale bar
  // A Slight Indentation for the scalar bar
  float margin = 0.05f;
  float scaleBarRelativeWidth = 0.10f;
  float scaleBarRelativeHeight = 1.0f - (margin * 2);

  int colorHeight = int( (imageHeight * scaleBarRelativeHeight) / numColors);

  QPointF topLeft(imageWidth * margin, imageHeight * margin);
  QSizeF size(imageWidth * scaleBarRelativeWidth, imageHeight * scaleBarRelativeHeight);

  int yLinePos = topLeft.y();

  QPointF start = topLeft;
  QPointF end = topLeft;

  for(int i = numColors - 1; i >= 0; i--)
  {
    QColor c(colorTable[i]);
    painter.setPen(QPen(c, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin));
    for(int j = 0; j < colorHeight; j++)
    {
      start.setY(yLinePos);
      end.setX(topLeft.x() + (imageWidth * scaleBarRelativeWidth));
      end.setY(yLinePos);
      painter.drawLine(start, end);
      yLinePos++;
    }
  }

  // Draw the border of the scale bar
  size = QSizeF(imageWidth * scaleBarRelativeWidth, numColors * colorHeight); // Add two pixel to the height so we don't over write part of the scale bar
  QRectF scaleBorder(topLeft, size);
  penWidth = 2;
  painter.setPen(QPen(QColor(0, 0, 0, 255), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
  painter.drawRect(scaleBorder);


  // Draw the Text Labels of the Scale Bar
  int startFontPtSize = 10;
  QFont font("Ariel", startFontPtSize, QFont::Bold);

  QFontMetrics metrics(font);
  int fontPixelsHeight = metrics.height();
  while(fontPixelsHeight < colorHeight * 2)
  {
    startFontPtSize++;
    font = QFont("Ariel", startFontPtSize, QFont::Bold);
    metrics = QFontMetrics(font);
    fontPixelsHeight = metrics.height();
  }
  painter.setFont(font);

  // Draw some more information to the right of the Scale Bar
  QString maxStr = QString::number(config.maxScale, 'f', 3);
  painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + fontPixelsHeight, maxStr);

  QString minStr = QString::number(config.minScale, 'f', 3);
  painter.drawText(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, topLeft.y() + size.height(), minStr);
  //------------------------------


  // Draw some statistics for the pole figures
  startFontPtSize = 8; // Set it to a rather large point size so we can fit the text perfectly. Only an insanely large Polefigure would go past this size
  int labelWidth = 0;

  // Make sure the size of font we just picked will allow the string to NOT be clipped because the rendered
  // pixel width is past the right side of the image
  int endOfStringYPos = topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10 + labelWidth;
  while(endOfStringYPos < imageWidth)
  {
    startFontPtSize++;
    font = QFont("Ariel", startFontPtSize, QFont::Bold);
    metrics = QFontMetrics(font);
    QString label("Upper & Lower");
    QString label2 = QString("Samples: ") + QString::number(config.eulers->getNumberOfTuples());
    fontPixelsHeight = metrics.height(); // Update the font height
    int labelWidth = metrics.width(label); // Figure out which string is longer (pixel wise)
    if (labelWidth < metrics.width(label2))
    {
      labelWidth = metrics.width(label2);
    }
    endOfStringYPos = topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10 + labelWidth;
  }
  startFontPtSize--;
  font = QFont("Ariel", startFontPtSize, QFont::Bold);
  metrics = QFontMetrics(font);
  QString label("Upper & Lower");
  QString label2 = QString("Samples: ") + QString::number(config.eulers->getNumberOfTuples());

  labelWidth = metrics.width(label);
  if (labelWidth < metrics.width(label2))
  {
    labelWidth = metrics.width(label2);
  }

  // Set the font into the Painter
  painter.setFont(font);

  QPointF statsPoint(topLeft.x() + (imageWidth * scaleBarRelativeWidth) + 10, imageHeight * .5);

  // Draw some more Statistics Text
  painter.drawText(statsPoint, label);
  statsPoint.setY(imageHeight * .5 + fontPixelsHeight);
  painter.drawText(statsPoint, label2);

  painter.end();
  // Scale the image down to 225 pixels
  return pImage;

}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QImage PoleFigureMaker::generateColorPoleFigureImage(const PoleFigureData& config)
{

  int kernelWidth = config.kernelRadius[0];
  int kernelHeight = config.kernelRadius[1];
  int imageWidth = config.imageSize[0];
  int imageHeight = config.imageSize[1];

  //  qDebug() << "Size: " << size << "\n";

  // Generate the Kernel Weights
  generateKernelWeigths(kernelWidth, kernelHeight);


  // Allocate an array to hold the image data and initialize it to all zeros
  QVector<qint32> data(imageWidth * imageHeight, 1);
  QVector<qint32> counts(imageWidth * imageHeight, 0);

  QVector<float> xPoints = config.xData;
  QVector<float> yPoints = config.yData;
  int size = yPoints.size();

  // Find the max count
  qint32 max = -2147483646;
  qint32 min = 2147483647;

  // Loop over all the data and get the x,y coords (scaled) and turn on the data pixel
  // This discretizes the data onto the pixel grid
  for (int i = 0; i < size; ++i)
  {
    int xCoord = (xPoints[i] + 1) * imageWidth / 2;
    int yCoord = (yPoints[i] + 1) * imageHeight / 2;
    data[ yCoord * imageWidth + xCoord]++;
    if (data[ yCoord * imageWidth + xCoord] > max) { max = data[ yCoord * imageWidth + xCoord];}
    if (data[ yCoord * imageWidth + xCoord] < min) { min = data[ yCoord * imageWidth + xCoord];}

  }

// qDebug() << "Max Data[]: " << max << "\n";

  qint32 value = 0;
  for (int yCoord = 0; yCoord < imageHeight; ++yCoord)
  {
    for (int xCoord = 0; xCoord < imageWidth; ++xCoord)
    {
      value = countPixelNeighbors(imageWidth, imageHeight, xCoord, yCoord, data, counts, kernelWidth, kernelHeight);
      if (value > max) { max = value;}
      if (value < min) { min = value;}
    }
  }



  value = 0;
  for (int yCoord = 0; yCoord < imageHeight; ++yCoord)
  {
    for (int xCoord = 0; xCoord < imageWidth; ++xCoord)
    {
      value = countPixelNeighbors(imageWidth, imageHeight, xCoord, yCoord, data, counts, kernelWidth, kernelHeight, true);
    }
  }

  if (max < 14) { max = 14; }
  QImage image (imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
  image.fill(0);
  qint32 numColors = max + 1;

  QVector<QColor> colorTable(numColors);
  qint32 range = max - min;

  float r, g, b;
  for (int i = 0; i < numColors; i++)
  {
    int val = min + ((float)i / numColors) * range;
    getColorCorrespondingTovalue(val, r, g, b, max, min);
    colorTable[i] = QColor(r * 255, g * 255, b * 255, 255);
  }
  // Index 0 is all white which is every pixel outside of the ODF circle
  colorTable[0] = QColor(255, 255, 255, 255);

  for (int yCoord = 0; yCoord < imageHeight; ++yCoord)
  {
    for (int xCoord = 0; xCoord < imageWidth; ++xCoord)
    {
      quint32 colorIndex = counts[yCoord * imageWidth + xCoord];
      image.setPixel(xCoord, yCoord, colorTable[colorIndex].rgba());
    }
  }

  // Flip the image so the (-1, -1) is in the lower left
  image = image.mirrored(true, false);

  return paintImage(config.imageSize[0], config.imageSize[1], config.label, image);
}
Пример #10
0
QColor ColorScheme::backgroundColor() const
{
    return colorTable()[1].color;
}
Пример #11
0
QColor ColorScheme::foregroundColor() const
{
    return colorTable()[0].color;
}
Пример #12
0
bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
        const SkIRect& desiredSubset, int sampleSize, SkColorType prefColorType,
        bool requireUnpremul) {

    // Fix the input sampleSize if necessary.
    if (sampleSize < 1) {
        sampleSize = 1;
    }

    // The size of the output bitmap is determined by the size of the
    // requested subset, not by the size of the intersection of the subset
    // and the image dimensions.
    // If inputX is negative, we will need to place decoded pixels into the
    // output bitmap starting at a left offset.  Call this outX.
    // If outX is non-zero, subsetX must be zero.
    // If inputY is negative, we will need to place decoded pixels into the
    // output bitmap starting at a top offset.  Call this outY.
    // If outY is non-zero, subsetY must be zero.
    int outX;
    int outY;
    SkIRect subset = desiredSubset;
    SubsetType type = adjust_subset_rect(fCodec->getInfo().dimensions(), &subset, &outX, &outY);
    if (SubsetType::kOutside_SubsetType == type) {
        return false;
    }

    // Ask the codec for a scaled subset
    if (!fCodec->getSupportedSubset(&subset)) {
        SkCodecPrintf("Error: Could not get subset.\n");
        return false;
    }
    SkISize scaledSize = fCodec->getSampledSubsetDimensions(sampleSize, subset);

    // Create the image info for the decode
    SkColorType dstColorType = fCodec->computeOutputColorType(prefColorType);
    SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul);
    SkImageInfo decodeInfo = fCodec->getInfo().makeWH(scaledSize.width(), scaledSize.height())
                                              .makeColorType(dstColorType)
                                              .makeAlphaType(dstAlphaType);

    // Construct a color table for the decode if necessary
    SkAutoTUnref<SkColorTable> colorTable(nullptr);
    int maxColors = 256;
    SkPMColor colors[256];
    if (kIndex_8_SkColorType == dstColorType) {
        colorTable.reset(new SkColorTable(colors, maxColors));
    }

    // Initialize the destination bitmap
    int scaledOutX = 0;
    int scaledOutY = 0;
    int scaledOutWidth = scaledSize.width();
    int scaledOutHeight = scaledSize.height();
    if (SubsetType::kPartiallyInside_SubsetType == type) {
        scaledOutX = outX / sampleSize;
        scaledOutY = outY / sampleSize;
        // We need to be safe here because getSupportedSubset() may have modified the subset.
        const int extraX = SkTMax(0, desiredSubset.width() - outX - subset.width());
        const int extraY = SkTMax(0, desiredSubset.height() - outY - subset.height());
        const int scaledExtraX = extraX / sampleSize;
        const int scaledExtraY = extraY / sampleSize;
        scaledOutWidth += scaledOutX + scaledExtraX;
        scaledOutHeight += scaledOutY + scaledExtraY;
    }
    SkImageInfo outInfo = decodeInfo.makeWH(scaledOutWidth, scaledOutHeight);
    if (kGray_8_SkColorType == dstColorType) {
        // The legacy implementations of BitmapFactory and BitmapRegionDecoder
        // used kAlpha8 for grayscale images (before kGray8 existed).  While
        // the codec recognizes kGray8, we need to decode into a kAlpha8
        // bitmap in order to avoid a behavior change.
        outInfo = outInfo.makeColorType(kAlpha_8_SkColorType).makeAlphaType(kPremul_SkAlphaType);
    }
    bitmap->setInfo(outInfo);
    if (!bitmap->tryAllocPixels(allocator, colorTable.get())) {
        SkCodecPrintf("Error: Could not allocate pixels.\n");
        return false;
    }

    // Zero the bitmap if the region is not completely within the image.
    // TODO (msarett): Can we make this faster by implementing it to only
    //                 zero parts of the image that we won't overwrite with
    //                 pixels?
    SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() :
            SkCodec::kNo_ZeroInitialized;
    if (SubsetType::kPartiallyInside_SubsetType == type &&
            SkCodec::kNo_ZeroInitialized == zeroInit) {
        void* pixels = bitmap->getPixels();
        size_t bytes = outInfo.getSafeSize(bitmap->rowBytes());
        memset(pixels, 0, bytes);
    }

    // Decode into the destination bitmap
    SkAndroidCodec::AndroidOptions options;
    options.fSampleSize = sampleSize;
    options.fSubset = &subset;
    options.fColorPtr = colors;
    options.fColorCount = &maxColors;
    options.fZeroInitialized = zeroInit;
    void* dst = bitmap->getAddr(scaledOutX, scaledOutY);

    SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, bitmap->rowBytes(),
            &options);
    if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) {
        SkCodecPrintf("Error: Could not get pixels.\n");
        return false;
    }

    // Intialize the color table
    if (kIndex_8_SkColorType == dstColorType) {
        colorTable->dangerous_overwriteColors(colors, maxColors);
    }

    return true;
}