flossColor
addSquareColorVersion_0_9_2_16::transform(const flossColor& color) const {

  if (color.type() == flossDMC || !::colorIsDmc(color.color())) {
    return color;
  }
  else { // it's a dmc color not marked as DMC
    return flossColor(color.color(), flossDMC);
  }
}
Exemple #2
0
QVector<typedFloss> rgbToFloss(const QVector<flossColor>& colors) {

  // Keep this in sync with rgbToFloss(const flossColor& color) - we're keeping
  // this version separate so that we don't need to load the DMC/Anchor color
  // list for each color on this list.
  // Also, WARNING: there was a bug in an old version of cstitch which in
  // certain cases allowed a non-floss color to be labeled as floss, so now
  // forevermore we need to handle that case just for any projects saved with
  // the bug. :(
  QVector<typedFloss> returnFloss;
  returnFloss.reserve(colors.size());
  QVector<floss> dmcColors;
  QVector<floss> anchorColors;
  for (int i = 0, size = colors.size(); i < size; ++i) {
    const flossColor color = colors[i];
    switch (color.type().value()) {
      case flossDMC: {
        if (dmcColors.isEmpty()) {
          dmcColors = ::initializeDMC();
        }
        const int index = dmcColors.indexOf(floss(color.color()));
        if (index != -1) {
          const floss thisDmcFloss = dmcColors[index];
          returnFloss.push_back(typedFloss(thisDmcFloss, flossDMC));
        }
        else {
          returnFloss.push_back(typedFloss(floss(color.color()), flossVariable));
        }
        break;
      }
      case flossAnchor: {
        if (anchorColors.isEmpty()) {
          anchorColors = ::initializeAnchor();
        }
        const int index = anchorColors.indexOf(floss(color.color()));
        if (index != -1) {
          const floss thisAnchorFloss = anchorColors[index];
          returnFloss.push_back(typedFloss(thisAnchorFloss, flossAnchor));
        }
        else {
          returnFloss.push_back(typedFloss(floss(color.color()), flossVariable));
        }
        break;
      }
      case flossVariable:
        returnFloss.push_back(typedFloss(floss(color.color()), flossVariable));
        break;
    }
  }
  return returnFloss;
}
Exemple #3
0
typedFloss rgbToFloss(const flossColor& color) {

  // Keep this in sync with rgbToFloss(const QVector<flossColor>& colors).
  const flossTypeValue type = color.type().value();
  if (type == flossDMC) {
    const QVector<floss> dmcColors = ::initializeDMC();
    const int index = dmcColors.indexOf(floss(color.color()));
    if (index != -1) {
      const floss thisDmcFloss = dmcColors[index];
      return typedFloss(thisDmcFloss, flossDMC);
    }
  }
  else if (type == flossAnchor) {
    const QVector<floss> anchorColors = ::initializeAnchor();
    const int index = anchorColors.indexOf(floss(color.color()));
    if (index != -1) {
      const floss thisAnchorFloss = anchorColors[index];
      return typedFloss(thisAnchorFloss, flossAnchor);
    }
  }

  return typedFloss(floss(color.color()), flossVariable);
}
dockListUpdate mutableSquareImageContainer::fillRegion(int x, int y,
                                                       flossColor newColor) {

  const triC oldColor = image_.pixel(x, y);
  if (newColor == oldColor) {
    return dockListUpdate();
  }
  const QVector<pairOfInts> coordinates =
    ::fillRegion(&image_, x, y, newColor.qrgb(), originalDimension_);

  const bool colorAdded = addColor(newColor);
  const flossColor oldFlossColor = getFlossColorFromColor(oldColor);
  addToHistory(historyItemPtr(new fillRegionHistoryItem(oldFlossColor,
                                                        newColor,
                                                        colorAdded,
                                                        coordinates)));
  colorListCheckNeeded_ = true;
  return dockListUpdate(newColor.color(), colorAdded);
}
Exemple #5
0
QVector<typedFloss> rgbToFloss(const QVector<flossColor>& rgbColors) {

  QVector<typedFloss> returnFloss;
  returnFloss.reserve(rgbColors.size());
  const QVector<floss> dmcFloss = ::initializeDMC();
  const QVector<int> flossCodes = ::rgbToCode(rgbColors);
  for (int i = 0, size = rgbColors.size(); i < size; ++i) {
    const flossColor thisColor = rgbColors[i];
    if (thisColor.type() == flossDMC) {
      const int dmcIndex = dmcFloss.indexOf(floss(thisColor.color()));
      if (dmcIndex != -1) { // (paranoia check)
        const floss thisDmcFloss = dmcFloss[dmcIndex];
        returnFloss.push_back(typedFloss(thisDmcFloss, flossDMC));
      }
      else {
        qWarning() << "DMC color not found in rgbToFloss: " <<
          ::ctos(thisColor.color());
        returnFloss.push_back(typedFloss(-1, "ERROR", thisColor.color(),
                                         thisColor.type()));
      }
    }
    else {
      const triC closestDmcColor = ::transformColor(thisColor.color(),
                                                    flossDMC);
      const int dmcIndex = dmcFloss.indexOf(floss(closestDmcColor));
      if (dmcIndex != -1) { // (paranoia check)
        const floss closestDmcFloss = dmcFloss[dmcIndex];
        const QString dmcApproximation =
          "~" + QString::number(closestDmcFloss.code()) + ":" +
          closestDmcFloss.name();
        returnFloss.push_back(typedFloss(flossCodes[i], dmcApproximation,
                                         thisColor.color(), thisColor.type()));
      }
      else {
        qWarning() << "DMC transform failed in rgbToFloss: " <<
          ::ctos(thisColor.color()) << thisColor.type().value() <<
          ::ctos(closestDmcColor);
        returnFloss.push_back(typedFloss(-1, "ERROR", thisColor.color(),
                                         thisColor.type()));
      }
    }
  }
  return returnFloss;
}
dockListUpdate
mutableSquareImageContainer::changeColor(QRgb oldColor,
                                         flossColor newFlossColor) {

  const QRgb newColor = newFlossColor.color().qrgb();
  if (oldColor == newColor) {
    return dockListUpdate();
  }
  const QVector<pairOfInts> changedSquares =
    ::changeColor(&image_, oldColor, newColor, originalDimension_);
  if (!changedSquares.empty()) {
    const bool colorAdded = addColor(newFlossColor);
    const flossColor oldFlossColor = removeColor(oldColor);
    addToHistory(historyItemPtr(new changeAllHistoryItem(oldFlossColor,
                                                         newFlossColor,
                                                         colorAdded,
                                                         changedSquares)));
    return dockListUpdate(newColor, colorAdded, oldColor);
  }
  else {
    return dockListUpdate();
  }
}