コード例 #1
0
ファイル: color_sliders.cpp プロジェクト: JamesLongo/aseprite
void HsvSliders::onSetColor(const app::Color& color)
{
  setAbsSliderValue(0, color.getHue());
  setAbsSliderValue(1, color.getSaturation());
  setAbsSliderValue(2, color.getValue());
  setAbsSliderValue(3, color.getAlpha());
}
コード例 #2
0
ファイル: cmd_eyedropper.cpp プロジェクト: 4144/aseprite
void EyedropperCommand::pickSample(const doc::Site& site,
                                   const gfx::Point& pixelPos,
                                   app::Color& color)
{
  // Check if we've to grab alpha channel or the merged color.
  Preferences& pref = Preferences::instance();
  bool allLayers =
    (pref.eyedropper.sample() == app::gen::EyedropperSample::ALL_LAYERS);

  ColorPicker picker;
  picker.pickColor(site,
                   pixelPos,
                   (allLayers ?
                    ColorPicker::FromComposition:
                    ColorPicker::FromActiveLayer));

  app::gen::EyedropperChannel channel =
    pref.eyedropper.channel();

  app::Color picked = picker.color();

  switch (channel) {
    case app::gen::EyedropperChannel::COLOR_ALPHA:
      color = picked;
      break;
    case app::gen::EyedropperChannel::COLOR:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::ALPHA:
      switch (color.getType()) {

        case app::Color::RgbType:
        case app::Color::IndexType:
          color = app::Color::fromRgb(color.getRed(),
                                      color.getGreen(),
                                      color.getBlue(),
                                      picked.getAlpha());
          break;

        case app::Color::HsvType:
          color = app::Color::fromHsv(color.getHue(),
                                      color.getSaturation(),
                                      color.getValue(),
                                      picked.getAlpha());
          break;

        case app::Color::GrayType:
          color = app::Color::fromGray(color.getGray(),
                                       picked.getAlpha());
          break;

      }
      break;
    case app::gen::EyedropperChannel::RGBA:
      if (picked.getType() == app::Color::RgbType)
        color = picked;
      else
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::RGB:
      if (picked.getAlpha() > 0)
        color = app::Color::fromRgb(picked.getRed(),
                                    picked.getGreen(),
                                    picked.getBlue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSVA:
      if (picked.getType() == app::Color::HsvType)
        color = picked;
      else
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::HSV:
      if (picked.getAlpha() > 0)
        color = app::Color::fromHsv(picked.getHue(),
                                    picked.getSaturation(),
                                    picked.getValue(),
                                    color.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAYA:
      if (picked.getType() == app::Color::GrayType)
        color = picked;
      else
        color = app::Color::fromGray(picked.getGray(),
                                     picked.getAlpha());
      break;
    case app::gen::EyedropperChannel::GRAY:
      if (picked.getAlpha() > 0)
        color = app::Color::fromGray(picked.getGray(),
                                     color.getAlpha());
      break;
    case app::gen::EyedropperChannel::INDEX:
      color = app::Color::fromIndex(picked.getIndex());
      break;
  }
}
コード例 #3
0
ファイル: cmd_palette_editor.cpp プロジェクト: 93i/aseprite
void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel channel, const app::Color& color)
{
    PalettePicks entries;
    getPicks(entries);
    int picksCount = entries.picks();

    uint32_t src_color;
    int r, g, b;

    Palette* palette = get_current_palette();
    for (int c=0; c<palette->size(); c++) {
        if (!entries[c])
            continue;

        // Get the current RGB values of the palette entry
        src_color = palette->getEntry(c);
        r = rgba_getr(src_color);
        g = rgba_getg(src_color);
        b = rgba_getb(src_color);

        switch (m_type) {

        case app::Color::RgbType:
            // Modify one entry
            if (picksCount == 1) {
                r = color.getRed();
                g = color.getGreen();
                b = color.getBlue();
            }
            // Modify one channel a set of entries
            else {
                // Setup the new RGB values depending of the modified channel.
                switch (channel) {
                case ColorSliders::Red:
                    r = color.getRed();
                case ColorSliders::Green:
                    g = color.getGreen();
                    break;
                case ColorSliders::Blue:
                    b = color.getBlue();
                    break;
                }
            }
            break;

        case app::Color::HsvType:
        {
            Hsv hsv;

            // Modify one entry
            if (picksCount == 1) {
                hsv.hue(color.getHue());
                hsv.saturation(double(color.getSaturation()) / 100.0);
                hsv.value(double(color.getValue()) / 100.0);
            }
            // Modify one channel a set of entries
            else {
                // Convert RGB to HSV
                hsv = Hsv(Rgb(r, g, b));

                // Only modify the desired HSV channel
                switch (channel) {
                case ColorSliders::Hue:
                    hsv.hue(color.getHue());
                    break;
                case ColorSliders::Saturation:
                    hsv.saturation(double(color.getSaturation()) / 100.0);
                    break;
                case ColorSliders::Value:
                    hsv.value(double(color.getValue()) / 100.0);
                    break;
                }
            }

            // Convert HSV back to RGB
            Rgb rgb(hsv);
            r = rgb.red();
            g = rgb.green();
            b = rgb.blue();
        }
        break;
        }

        palette->setEntry(c, doc::rgba(r, g, b, 255));
    }
}