예제 #1
0
/* Loop through the given pattern */
void PixelUtil::patternLoop(byte pattern[][3], int pattern_size, int periodms) {
  static unsigned long next_time = millis();
  static byte current = 0;

  if (millis() > next_time) {
    setPixelRGB(current, 0, 0, 0);
    current = (current + 1) % numPixels();
    next_time += periodms;

    for (byte i = 0; i <  pattern_size; i++) {
      setPixelRGB((current + i) % numPixels(),
		  pattern[i][0], pattern[i][1], pattern[i][2]);
    }
  }
}
예제 #2
0
void
imageHorizontalLineRGB(
    IMAGE_T *image,
    int32_t x1,
    int32_t x2,
    int32_t y,
    const RGBA8_T *rgb)
{
    int32_t sign_x = (x1 <= x2) ? 1 : -1;
    int32_t x = x1;

    setPixelRGB(image, x, y, rgb);

    while (x != x2)
    {
        x += sign_x;
        setPixelRGB(image, x, y, rgb);
    }
}
예제 #3
0
void
imageVerticalLineRGB(
    IMAGE_T *image,
    int32_t x,
    int32_t y1,
    int32_t y2,
    const RGBA8_T *rgb)
{
    int32_t sign_y = (y1 <= y2) ? 1 : -1;
    int32_t y = y1;

    setPixelRGB(image, x, y, rgb);

    while (y != y2)
    {
        y += sign_y;
        setPixelRGB(image, x, y, rgb);
    }
}
예제 #4
0
void
drawWorm(
    WORM_T *worm,
    IMAGE_T *image)
{
    uint16_t i = 0;
    for (i = 0 ; i < worm->size ; i++)
    {
        setPixelRGB(image,
                    (int32_t)floor(worm->body[i].x),
                    (int32_t)floor(worm->body[i].y),
                    &(worm->colour));
    }
}
예제 #5
0
void ColorChooser::loadForegroundPixmap(QRgb rgbBg)
{
  // build foreground/background pixmap. for the foreground color we use black or white,
  // whichever is furthest in rgb space from the background color
  int width = ChooserWidth + 2 * ChooserPadding;
  QImage imageScale(width, m_scaleHeight, 32);

  int rBg, gBg, bBg;
  QColor colorBg(rgbBg);
  colorBg.rgb(&rBg, &gBg, &bBg);
  
  QRgb rgbFg;
  int distanceBlack = (rBg - 0) * (rBg - 0) + (gBg - 0) * (gBg - 0) + (bBg - 0) * (bBg - 0);
  int distanceWhite = (rBg - 255) * (rBg - 255) + (gBg - 255) * (gBg - 255) + (bBg - 255) * (bBg - 255);
  if (distanceWhite > distanceBlack)
    rgbFg = QColor(Qt::white).rgb();
  else
    rgbFg = QColor(Qt::black).rgb();

  for (int x = 0; x < width; x++)
    for (int y = 0; y < m_scaleHeight; y++)
    {
      // show an triangle with bottom side on the left, and point on the right
      if (x < (y * width) / (m_scaleHeight - 2 * ChooserFrame))
        setPixelRGB(&imageScale, x, y, rgbBg);
      else
        setPixelRGB(&imageScale, x, y, rgbFg);
    }

  pixmapForeground.convertFromImage(imageScale, Qt::ThresholdDither);

  if (m_discretizeMethod == DiscretizeForeground)
  {
    scaleCanvas->setBackgroundPixmap(pixmapForeground);
    scaleCanvas->update();
  }
}
예제 #6
0
void
undrawWorm(
    WORM_T *worm,
    IMAGE_T *image)
{
    RGBA8_T colour = { 0, 0, 0, 0 };

    uint32_t i = 0;
    for (i = 0 ; i < worm->size ; i++)
    {
        setPixelRGB(image,
                    (int32_t)floor(worm->body[i].x),
                    (int32_t)floor(worm->body[i].y),
                    &colour);
    }
}
예제 #7
0
void renderExplosionEffect()
{
	if(explosionGoing)
	{
		// Draw it
		for(int y = areaToCheck.y; y < areaToCheck.h; y++)
		{
			for(int x = areaToCheck.x; x < areaToCheck.w; x++)
			{
				if(explosionBuffer[x][y])
				{
					colorRGB curC = palette[explosionBuffer[x][y]];
					setPixelRGB(x, y, curC.r, curC.g, curC.b);
				}
			}
		}
	}
}
예제 #8
0
void PixelUtil::setAllRGB(uint32_t color)
{
  for (uint16_t led = 0; led < numPixels(); led++) {
    setPixelRGB(led, color);
  }
}
예제 #9
0
void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int)
{
    if (m_frameBufferCache.isEmpty())
        return;

    // Initialize the framebuffer if needed.
    ImageFrame& buffer = m_frameBufferCache[0];
    if (buffer.status() == ImageFrame::FrameEmpty) {
        png_structp png = m_reader->pngPtr();
        if (!buffer.setSize(scaledSize().width(), scaledSize().height())) {
            longjmp(JMPBUF(png), 1);
            return;
        }

        unsigned colorChannels = m_reader->hasAlpha() ? 4 : 3;
        if (PNG_INTERLACE_ADAM7 == png_get_interlace_type(png, m_reader->infoPtr())) {
            m_reader->createInterlaceBuffer(colorChannels * size().width() * size().height());
            if (!m_reader->interlaceBuffer()) {
                longjmp(JMPBUF(png), 1);
                return;
            }
        }

#if USE(QCMSLIB)
        if (m_reader->colorTransform()) {
            m_reader->createRowBuffer(colorChannels * size().width());
            if (!m_reader->rowBuffer()) {
                longjmp(JMPBUF(png), 1);
                return;
            }
        }
#endif
        buffer.setStatus(ImageFrame::FramePartial);
        buffer.setHasAlpha(false);
        buffer.setColorProfile(m_colorProfile);

        // For PNGs, the frame always fills the entire image.
        buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
    }

    /* libpng comments (here to explain what follows).
     *
     * this function is called for every row in the image.  If the
     * image is interlacing, and you turned on the interlace handler,
     * this function will be called for every row in every pass.
     * Some of these rows will not be changed from the previous pass.
     * When the row is not changed, the new_row variable will be NULL.
     * The rows and passes are called in order, so you don't really
     * need the row_num and pass, but I'm supplying them because it
     * may make your life easier.
     */

    // Nothing to do if the row is unchanged, or the row is outside
    // the image bounds: libpng may send extra rows, ignore them to
    // make our lives easier.
    if (!rowBuffer)
        return;
    int y = !m_scaled ? rowIndex : scaledY(rowIndex);
    if (y < 0 || y >= scaledSize().height())
        return;

    /* libpng comments (continued).
     *
     * For the non-NULL rows of interlaced images, you must call
     * png_progressive_combine_row() passing in the row and the
     * old row.  You can call this function for NULL rows (it will
     * just return) and for non-interlaced images (it just does the
     * memcpy for you) if it will make the code easier.  Thus, you
     * can just do this for all cases:
     *
     *    png_progressive_combine_row(png_ptr, old_row, new_row);
     *
     * where old_row is what was displayed for previous rows.  Note
     * that the first pass (pass == 0 really) will completely cover
     * the old row, so the rows do not have to be initialized.  After
     * the first pass (and only for interlaced images), you will have
     * to pass the current row, and the function will combine the
     * old row and the new row.
     */

    bool hasAlpha = m_reader->hasAlpha();
    unsigned colorChannels = hasAlpha ? 4 : 3;
    png_bytep row = rowBuffer;

    if (png_bytep interlaceBuffer = m_reader->interlaceBuffer()) {
        row = interlaceBuffer + (rowIndex * colorChannels * size().width());
        png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer);
    }

#if USE(QCMSLIB)
    if (qcms_transform* transform = m_reader->colorTransform()) {
        qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width());
        row = m_reader->rowBuffer();
    }
#endif

    // Write the decoded row pixels to the frame buffer.
    ImageFrame::PixelData* address = buffer.getAddr(0, y);
    int width = scaledSize().width();
    unsigned char nonTrivialAlphaMask = 0;

#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
    if (m_scaled) {
        for (int x = 0; x < width; ++x) {
            png_bytep pixel = row + m_scaledColumns[x] * colorChannels;
            unsigned alpha = hasAlpha ? pixel[3] : 255;
            buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
            nonTrivialAlphaMask |= (255 - alpha);
        }
    } else
#endif
    {
        png_bytep pixel = row;
        if (hasAlpha) {
            if (buffer.premultiplyAlpha()) {
                for (int x = 0; x < width; ++x, pixel += 4)
                    setPixelPremultipliedRGBA(address++, pixel, nonTrivialAlphaMask);
            } else {
                for (int x = 0; x < width; ++x, pixel += 4)
                    setPixelRGBA(address++, pixel, nonTrivialAlphaMask);
            }
        } else {
            for (int x = 0; x < width; ++x, pixel += 3)
                setPixelRGB(address++, pixel);
        }
    }


    if (nonTrivialAlphaMask && !buffer.hasAlpha())
        buffer.setHasAlpha(true);
}
예제 #10
0
void
imageLineRGB(
    IMAGE_T *image,
    int32_t x1,
    int32_t y1,
    int32_t x2,
    int32_t y2,
    const RGBA8_T *rgb)
{
    if (y1 == y2)
    {
        imageHorizontalLineRGB(image, x1, x2, y1, rgb);
    }
    else if (x1 == x2)
    {
        imageVerticalLineRGB(image, x1, y1, y2, rgb);
    }
    else
    {
        int32_t dx = abs(x2 - x1);
        int32_t dy = abs(y2 - y1);

        int32_t sign_x = (x1 <= x2) ? 1 : -1;
        int32_t sign_y = (y1 <= y2) ? 1 : -1;

        int32_t x = x1;
        int32_t y = y1;

        setPixelRGB(image, x, y, rgb);

        if (dx > dy)
        {
            int32_t d = 2 * dy - dx;
            int32_t incrE = 2 * dy;
            int32_t incrNE = 2 * (dy - dx);

            while (x != x2)
            {
                x += sign_x;

                if (d <= 0)
                {
                    d += incrE;
                }
                else
                {
                    d += incrNE;
                    y += sign_y;
                }

                setPixelRGB(image, x, y, rgb);
            }
        }
        else
        {
            int32_t d = 2 * dx - dy;
            int32_t incrN = 2 * dx;
            int32_t incrNE = 2 * (dx - dy);

            while (y != y2)
            {
                y += sign_y;

                if (d <= 0)
                {
                    d += incrN;
                }
                else
                {
                    d += incrNE;
                    x += sign_x;
                }

                setPixelRGB(image, x, y, rgb);
            }
        }
    }
}