Esempio n. 1
0
void pix_convolve :: processGrayImage(imageStruct &image)
{
  const int csize=image.csize;
  image.copy2Image(&tempImg);
  int initX = m_rows / 2;
  int initY = m_cols / 2;
  int maxX = tempImg.xsize - initX;
  int maxY = tempImg.ysize - initY;
  int xTimesc = tempImg.xsize * csize;
  int initOffset = initY * xTimesc + initX * csize;

  for (int y = initY; y < maxY; y++)    {
    int realY = y * xTimesc;
    int offsetY = realY - initOffset;

    for (int x = initX; x < maxX; x++)        {
      int offsetXY = x + offsetY;

      int new_val = 0;
      int offsetXYC = offsetXY;
      for (int matY = 0; matY < m_cols; matY++)   {
        int offsetXYCMat = matY * xTimesc + offsetXYC;
        int realMatY = matY * m_rows;
        for (int matX = 0; matX < m_rows; matX++)     {
          new_val += (tempImg.data[offsetXYCMat + matX] *
                      m_imatrix[realMatY + matX])>>8;
        }
      }
      image.data[x+realY] = CLAMP(new_val);
      //removes insult from injury ??
      // we do not use the m_irange anymore ...  remove it ??
    }
  }
}
Esempio n. 2
0
bool imageTIFF::save(const imageStruct&constimage, const std::string&filename, const std::string&mimetype, const gem::Properties&props) {
  TIFF *tif = NULL;

  if(GL_YUV422_GEM==constimage.format) {
    error("don't know how to write YUV-images with libTIFF");
    return false;
  }

  tif=TIFFOpen(filename.c_str(), "w");
  if (tif == NULL) {
    return false;
  }
  imageStruct image; constimage.copy2Image(&image);
  image.fixUpDown();

  uint32 width=image.xsize, height = image.ysize;
  short bits=8, samps=image.csize;
  int npixels = width * height;
  //int planar_conf = PLANARCONFIG_CONTIG;
  const char *gemstring = "PD/GEM";

  TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
  TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
  TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bits);
  TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, samps);
  TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
  TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);

  TIFFSetField(tif, TIFFTAG_XRESOLUTION, 72);
  TIFFSetField(tif, TIFFTAG_YRESOLUTION, 72);
  TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);

  TIFFSetField(tif, TIFFTAG_SOFTWARE, gemstring);

  int yStride = image.xsize * image.csize;
  unsigned char *srcLine = &(image.data[npixels * image.csize]);
  srcLine -= yStride;

  for (uint32 row = 0; row < height; row++) {
    unsigned char *buf = srcLine;
    if (TIFFWriteScanline(tif, buf, row, 0) < 0)
      {
        error("GEM: could not write line %d to image %s", row, filename.c_str());
        TIFFClose(tif);
        delete [] buf;
        return(false);
      }
    srcLine -= yStride;
  }
  TIFFClose(tif);

  return true;
}
Esempio n. 3
0
void pix_convolve :: processYUVImage(imageStruct &image)
{
  image.copy2Image(&tempImg);
  //float range = 1;
  int initX = m_rows / 2;
  int initY = m_cols / 2;
  int maxX = tempImg.xsize - initX;
  int maxY = tempImg.ysize - initY;
  int xTimesc = tempImg.xsize * tempImg.csize;
  int initOffset = initY * xTimesc + initX * tempImg.csize;

//   calculate3x3YUV(image,tempImg);

//quick fix for Intel 3x3YUV problems
#ifdef __BIG_ENDIAN__
  if (m_rows == 3 && m_cols == 3) {
    calculate3x3YUV(image,tempImg);
    return;
  }
#endif
  if (m_chroma) {
    for (int y = initY; y < maxY; y++)   {
      int realY = y * xTimesc;
      int offsetY = realY - initOffset;

      for (int x = initX; x < maxX; x++) {
        int realPos = x * tempImg.csize + realY;
        int offsetXY = x * tempImg.csize + offsetY;

        // skip the UV
        for (int c = 1; c < 3; c+=2) {
          int new_val = 0;
          int offsetXYC = offsetXY + c;
          for (int matY = 0; matY < m_cols; matY++) {
            int offsetXYCMat = matY * xTimesc + offsetXYC;
            int realMatY = matY * m_rows;
            for (int matX = 0; matX < m_rows; matX++) {
              new_val += (tempImg.data[offsetXYCMat + matX * tempImg.csize] *
                          m_imatrix[realMatY + matX])>>8;
            }
          }
          image.data[realPos + c] = CLAMP(new_val);
          // image.data[realPos + c-1] = 128;  //remove the U+V
        }
      }
    }
  } else {
    for (int y = initY; y < maxY; y++) {
Esempio n. 4
0
void pix_convolve :: processRGBAImage(imageStruct &image)
{
  image.copy2Image(&tempImg);
  int initX = m_rows / 2;
  int initY = m_cols / 2;
  int maxX = tempImg.xsize - initX;
  int maxY = tempImg.ysize - initY;
  int xTimesc = tempImg.xsize * tempImg.csize;
  int initOffset = initY * xTimesc + initX * tempImg.csize;
  const int csize = tempImg.csize;

  if (m_rows == 3 && m_cols == 3) {
    calculateRGBA3x3(image,tempImg);
    return;
  }

  for (int y = initY; y < maxY; y++) {
    int realY = y * xTimesc;
    int offsetY = realY - initOffset;

    for (int x = initX; x < maxX; x++) {
      int realPos = x * csize + realY;
      int offsetXY = x * csize + offsetY;

      // skip the alpha value
      for (int c = 1; c < csize; c++) {
        int new_val = 0;
        int offsetXYC = offsetXY + c;
        for (int matY = 0; matY < m_cols; matY++) {
          int offsetXYCMat = matY * xTimesc + offsetXYC;
          int realMatY = matY * m_rows;
          for (int matX = 0; matX < m_rows; matX++) {
            new_val += (tempImg.data[offsetXYCMat + matX * csize] *
                        m_imatrix[realMatY + matX])>>8;
          }
        }
        image.data[realPos + c] = CLAMP(new_val);
        //removes insult from injury ??
        // we do not use the m_irange anymore ...  remove it ??

      }
    }
  }

}
Esempio n. 5
0
/////////////////////////////////////////////////////////
// processImage
//
/////////////////////////////////////////////////////////
void pix_flip :: processRGBAImage(imageStruct &image)
{
    // eventually should do this inline, but in the interest of getting it done...
    imageStruct tempImg;
    if (image.data==0)return;
    image.copy2Image(&tempImg);
    int ySrcStride = image.xsize * image.csize;
    int yDstStride = image.xsize * image.csize;
    int xSrcStride = image.csize;
    int xDstStride = image.csize;
    unsigned char *srcLine = tempImg.data;
    unsigned char *dstLine = image.data;

    FlipType flip=m_flip;
    if(!image.upsidedown) {
      switch(flip) {
      case(HORIZONTAL) : flip=BOTH;break;
      case(VERTICAL)   : flip=NONE;break;
      case(BOTH)       : flip=HORIZONTAL;break;
      case(NONE)       : flip=VERTICAL  ;break;
      default   :break;
      }
    }
    image.upsidedown=true;

    switch(flip)
    {
    	case(HORIZONTAL):
            srcLine = tempImg.data + ySrcStride - xSrcStride;
            xSrcStride = -xSrcStride;
    	    break;
    	case(VERTICAL):
            srcLine = tempImg.data + ySrcStride * image.ysize - ySrcStride;
            ySrcStride = -ySrcStride;
    	    break;
    	case(BOTH):
            srcLine = tempImg.data + ySrcStride * image.ysize - xSrcStride;
            xSrcStride = -xSrcStride;
            ySrcStride = -ySrcStride;
    	    break;
    	default:
            return;
    	    // break;
    }
    int ySize = image.ysize;
    int xHold = image.xsize;

    while(ySize--)
    {
      unsigned char *srcPixels = srcLine;
      unsigned char *dstPixels = dstLine;
      int xSize = xHold;
      while(xSize--)        {
	dstPixels[chRed] = srcPixels[chRed];
	dstPixels[chGreen] = srcPixels[chGreen];
	dstPixels[chBlue] = srcPixels[chBlue];
	dstPixels[chAlpha] = srcPixels[chAlpha];
	dstPixels += xDstStride;
	srcPixels += xSrcStride;
      }
      dstLine += yDstStride;
      srcLine += ySrcStride;
    }
}
Esempio n. 6
0
bool imageTIFF::save(const imageStruct&constimage, const std::string&filename, const std::string&mimetype, const gem::Properties&props) {
  TIFF *tif = NULL;

  if(GL_YUV422_GEM==constimage.format) {
    error("don't know how to write YUV-images with libTIFF");
    return false;
  }

  tif=TIFFOpen(filename.c_str(), "w");
  if (tif == NULL) {
    return false;
  }
  imageStruct image; constimage.copy2Image(&image);
  image.fixUpDown();

  uint32 width=image.xsize, height = image.ysize;
  short bits=8, samps=image.csize;
  int npixels = width * height;
  //int planar_conf = PLANARCONFIG_CONTIG;
  std::string software = "PD/GEM";
  std::string artist;
  std::string hostcomputer;

  double xresolution = 72., yresolution=72.;
  short resunit = RESUNIT_INCH;

  props.get("xresolution", xresolution);
  props.get("yresolution", yresolution);
  std::string resunit_s;
  if(props.get("resolutionunit", resunit_s)) {
    if(("inch"==resunit_s) || ("english"==resunit_s) || ("imperial"==resunit_s))
      resunit=RESUNIT_INCH;
    else if(("centimeter"==resunit_s) || ("metric"==resunit_s))
      resunit=RESUNIT_CENTIMETER;
    else
      resunit=RESUNIT_NONE;
  }
  props.get("software", software);
  props.get("artist", artist);
  props.get("hostcomputer", hostcomputer);


  TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
  TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
  TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bits);
  TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, samps);
  TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
  TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);

  TIFFSetField(tif, TIFFTAG_XRESOLUTION, xresolution); // RATIONAL
  TIFFSetField(tif, TIFFTAG_YRESOLUTION, yresolution); // RATIONAL
  TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, resunit);

  if(!software.empty())
    TIFFSetField(tif, TIFFTAG_SOFTWARE, software.c_str());
  if(!artist.empty())
    TIFFSetField(tif, TIFFTAG_ARTIST, artist.c_str());
  if(!hostcomputer.empty())
    TIFFSetField(tif, TIFFTAG_HOSTCOMPUTER, hostcomputer.c_str());

  int yStride = image.xsize * image.csize;
  unsigned char *srcLine = &(image.data[npixels * image.csize]);
  srcLine -= yStride;

  for (uint32 row = 0; row < height; row++) {
    unsigned char *buf = srcLine;
    if (TIFFWriteScanline(tif, buf, row, 0) < 0)
      {
        error("GEM: could not write line %d to image %s", row, filename.c_str());
        TIFFClose(tif);
        delete [] buf;
        return(false);
      }
    srcLine -= yStride;
  }
  TIFFClose(tif);

  return true;
}