Exemple #1
0
static bool is_same_pixel(PixelFormat pixelFormat, color_t pixel1, color_t pixel2)
{
  switch (pixelFormat) {
    case IMAGE_RGB:
      if (rgba_geta(pixel1) == 0 && rgba_geta(pixel2) == 0)
        return true;
      break;
    case IMAGE_GRAYSCALE:
      if (graya_geta(pixel1) == 0 && graya_geta(pixel2) == 0)
        return true;
      break;
  }
  return pixel1 == pixel2;
}
Exemple #2
0
bool Palette::hasAlpha() const
{
  for (int i=0; i<(int)m_colors.size(); ++i)
    if (rgba_geta(getEntry(i)) < 255)
      return true;
  return false;
}
Exemple #3
0
static inline bool color_equal_32(color_t c1, color_t c2, int tolerance)
{
  if (tolerance == 0)
    return (c1 == c2) || (rgba_geta(c1) == 0 && rgba_geta(c2) == 0);
  else {
    int r1 = rgba_getr(c1);
    int g1 = rgba_getg(c1);
    int b1 = rgba_getb(c1);
    int a1 = rgba_geta(c1);
    int r2 = rgba_getr(c2);
    int g2 = rgba_getg(c2);
    int b2 = rgba_getb(c2);
    int a2 = rgba_geta(c2);

    if (a1 == 0 && a2 == 0)
      return true;

    return ((ABS(r1-r2) <= tolerance) &&
            (ABS(g1-g2) <= tolerance) &&
            (ABS(b1-b2) <= tolerance) &&
            (ABS(a1-a2) <= tolerance));
  }
}
Exemple #4
0
// Creates a linear ramp in the palette.
void Palette::makeGradient(int from, int to)
{
  int r, g, b, a;
  int r1, g1, b1, a1;
  int r2, g2, b2, a2;
  int i, n;

  ASSERT(from >= 0 && from <= 255);
  ASSERT(to >= 0 && to <= 255);

  if (from > to)
    std::swap(from, to);

  n = to - from;
  if (n < 2)
    return;

  r1 = rgba_getr(getEntry(from));
  g1 = rgba_getg(getEntry(from));
  b1 = rgba_getb(getEntry(from));
  a1 = rgba_geta(getEntry(from));

  r2 = rgba_getr(getEntry(to));
  g2 = rgba_getg(getEntry(to));
  b2 = rgba_getb(getEntry(to));
  a2 = rgba_geta(getEntry(to));

  for (i=from+1; i<to; ++i) {
    r = r1 + (r2-r1) * (i-from) / n;
    g = g1 + (g2-g1) * (i-from) / n;
    b = b1 + (b2-b1) * (i-from) / n;
    a = a1 + (a2-a1) * (i-from) / n;

    setEntry(i, rgba(r, g, b, a));
  }
}
Exemple #5
0
void Sprite::pickCels(int x, int y, frame_t frame, int opacityThreshold, CelList& cels) const
{
  std::vector<Layer*> layers;
  getLayersList(layers);

  for (int i=(int)layers.size()-1; i>=0; --i) {
    Layer* layer = layers[i];
    if (!layer->isImage() || !layer->isVisible())
      continue;

    Cel* cel = layer->cel(frame);
    if (!cel)
      continue;

    Image* image = cel->image();
    if (!image)
      continue;

    if (!cel->bounds().contains(gfx::Point(x, y)))
      continue;

    color_t color = get_pixel(image,
      x - cel->x(),
      y - cel->y());

    bool isOpaque = true;

    switch (image->pixelFormat()) {
      case IMAGE_RGB:
        isOpaque = (rgba_geta(color) >= opacityThreshold);
        break;
      case IMAGE_INDEXED:
        isOpaque = (color != image->maskColor());
        break;
      case IMAGE_GRAYSCALE:
        isOpaque = (graya_geta(color) >= opacityThreshold);
        break;
    }

    if (!isOpaque)
      continue;

    cels.push_back(cel);
  }
  fflush(stdout);
}
Exemple #6
0
raster::color_t color_utils::fixup_color_for_background(PixelFormat format, raster::color_t color)
{
  switch (format) {
    case IMAGE_RGB:
      if (rgba_geta(color) < 255) {
        return rgba(rgba_getr(color),
                    rgba_getg(color),
                    rgba_getb(color), 255);
      }
      break;
    case IMAGE_GRAYSCALE:
      if (graya_geta(color) < 255) {
        return graya(graya_getv(color), 255);
      }
      break;
  }
  return color;
}
int convert_color_to_allegro<RgbTraits, 32>(color_t c, const Palette* palette) {
  return makeacol32(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c));
}
int convert_color_to_allegro<BitmapTraits, 32>(color_t color, const Palette* palette) {
  color_t c = palette->getEntry(color);
  return makeacol32(rgba_getr(c), rgba_getg(c), rgba_getb(c), rgba_geta(c));
}