Ejemplo n.º 1
0
      void
      MinimalTIFFWriter::setupIFD() const
      {
        // Default to single strips for now.
        ifd->setImageWidth(getSizeX());
        ifd->setImageHeight(getSizeY());

        ifd->setTileType(tiff::STRIP);
        ifd->setTileWidth(getSizeX());
        ifd->setTileHeight(1U);

        ome::compat::array<dimension_size_type, 3> coords = getZCTCoords(getPlane());

        dimension_size_type channel = coords[1];

        ifd->setPixelType(getPixelType());
        ifd->setBitsPerSample(bitsPerPixel(getPixelType()));
        ifd->setSamplesPerPixel(getRGBChannelCount(channel));

        const boost::optional<bool> interleaved(getInterleaved());
        if (isRGB(channel) && interleaved && *interleaved)
          ifd->setPlanarConfiguration(tiff::CONTIG);
        else
          ifd->setPlanarConfiguration(tiff::SEPARATE);

        // This isn't necessarily always true; we might want to use a
        // photometric interpretation other than RGB with three
        // subchannels.
        if (isRGB(channel) && getRGBChannelCount(channel) == 3)
          ifd->setPhotometricInterpretation(tiff::RGB);
        else
          ifd->setPhotometricInterpretation(tiff::MIN_IS_BLACK);
      }
Ejemplo n.º 2
0
void Image::desaturate()
{
    if (isARGB() || isRGB())
    {
        const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite);

        if (isARGB())
        {
            for (int y = 0; y < destData.height; ++y)
            {
                uint8* p = destData.getLinePointer (y);

                for (int x = 0; x < destData.width; ++x)
                {
                    ((PixelARGB*) p)->desaturate();
                    p += destData.pixelStride;
                }
            }
        }
        else
        {
            for (int y = 0; y < destData.height; ++y)
            {
                uint8* p = destData.getLinePointer (y);

                for (int x = 0; x < destData.width; ++x)
                {
                    ((PixelRGB*) p)->desaturate();
                    p += destData.pixelStride;
                }
            }
        }
    }
}
Ejemplo n.º 3
0
int motionDetection(MotionDetect* md, Transform* trans, unsigned char *frame) {
  assert(md->initialized==2);

  md->currorig = frame;
  // smoothen image to do better motion detection
  //  (larger stepsize or eventually gradient descent (need higher resolution)
  if (isRGB(md->fi.pFormat)) {
    // we could calculate a grayscale version and use the YUV stuff afterwards
    // so far only YUV implemented
    memcpy(md->curr, frame, md->fi.framesize);
  } else {
    // box-kernel smoothing (plain average of pixels), which is fine for us
    boxblurYUV(md->curr, frame, md->currtmp, &md->fi, md->stepSize*1/*1.4*/,
               BoxBlurNoColor);
    // two times yields tent-kernel smoothing, which may be better, but I don't
    //  think we need it
    //boxblurYUV(md->curr, md->curr, md->currtmp, &md->fi, md->stepSize*1,
    // BoxBlurNoColor);
  }

  if (md->hasSeenOneFrame) {
    //    md->curr = frame;
    if (isRGB(md->fi.pFormat)) {
      if (md->algo == 0)
        *trans = calcShiftRGBSimple(md);
      else if (md->algo == 1)
        *trans = calcTransFields(md, calcFieldTransRGB, contrastSubImgRGB);
    } else if (md->fi.pFormat == PF_YUV) {
      if (md->algo == 0)
        *trans = calcShiftYUVSimple(md);
      else if (md->algo == 1)
        *trans = calcTransFields(md, calcFieldTransYUV, contrastSubImgYUV);
    } else {
      ds_log_warn(md->modName, "unsupported Pixel Format (Codec: %i)\n",
                  md->fi.pFormat);
      return DS_ERROR;
    }
  } else {
    md->hasSeenOneFrame = 1;
    *trans = null_transform();
  }

  // copy current frame (smoothed) to prev for next frame comparison
  memcpy(md->prev, md->curr, md->fi.framesize);
  md->frameNum++;
  return DS_OK;
}
Ejemplo n.º 4
0
void Image::desaturate()
{
    if (isARGB() || isRGB())
    {
        const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), BitmapData::readWrite);
        performPixelOp (destData, DesaturateOp());
    }
}
Ejemplo n.º 5
0
//==============================================================================
void Image::clear (const Rectangle<int>& area, const Colour& colourToClearTo)
{
    const Rectangle<int> clipped (area.getIntersection (getBounds()));

    if (! clipped.isEmpty())
    {
        const PixelARGB col (colourToClearTo.getPixelARGB());

        const BitmapData destData (*this, clipped.getX(), clipped.getY(), clipped.getWidth(), clipped.getHeight(), BitmapData::writeOnly);
        uint8* dest = destData.data;
        int dh = clipped.getHeight();

        while (--dh >= 0)
        {
            uint8* line = dest;
            dest += destData.lineStride;

            if (isARGB())
            {
                for (int x = clipped.getWidth(); --x >= 0;)
                {
                    ((PixelARGB*) line)->set (col);
                    line += destData.pixelStride;
                }
            }
            else if (isRGB())
            {
                for (int x = clipped.getWidth(); --x >= 0;)
                {
                    ((PixelRGB*) line)->set (col);
                    line += destData.pixelStride;
                }
            }
            else
            {
                for (int x = clipped.getWidth(); --x >= 0;)
                {
                    *line = col.getAlpha();
                    line += destData.pixelStride;
                }
            }
        }
    }
}
Ejemplo n.º 6
0
QColor GeneralConfig::getColorFromString(QString colorString) {
/* -converts a color defined in a string to a 'QColor' object, using regexp validation, and returnes it */
    if ( colorString.isEmpty() ) return QColor();   //return if no color is specified

    //cleen up the string
    colorString = colorString.simplified();
    colorString = colorString.trimmed();

    QColor returnColor(0, 0, 0);    //dummy color to be returned
    int p = 0;                      //used for regexp validator

    //regexps to check color value
    QRegularExpressionValidator isRGB( QRegularExpression("\\d{1,3} \\d{1,3} \\d{1,3}") );              //check if RGB
    QRegularExpressionValidator isRGBA( QRegularExpression("\\d{1,3} \\d{1,3} \\d{1,3} \\d{1,3}") );    //check if RGBA
    QRegularExpressionValidator isHEX( QRegularExpression("^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8}|[0-9A-Fa-f]{9}|[0-9A-Fa-f]{12})$") );//check if HEX code
    QRegularExpressionValidator isName( QRegularExpression("\\w+") );                                   //check if color name

    //check color value
    if ( isRGB.validate(colorString, p) == 2) {
        QStringList rgb = colorString.split( QRegularExpression("\\s") );
        returnColor.setRgb( rgb.at(0).toInt(), rgb.at(1).toInt(), rgb.at(2).toInt() );
    }
    else if ( isRGBA.validate(colorString, p) == 2) {
        QStringList rgb = colorString.split( QRegularExpression("\\s") );
        returnColor.setRgb( rgb.at(0).toInt(), rgb.at(1).toInt(), rgb.at(2).toInt(), rgb.at(3).toInt() );
    }
    else if ( isHEX.validate(colorString, p) == 2) {
        returnColor.setNamedColor(colorString);
    }
    else if ( isName.validate(colorString, p) ) {
        returnColor.setNamedColor( colorString.toLower().remove( QRegularExpression("\\s+") ) );
    }

    //check color is valid and return
    if ( returnColor.isValid() ) return returnColor;
    else return QColor();
}