Example #1
0
int lut(string option, string img){
	Mat src = imread(img);
	if (src.empty())
	{
		cout << "cannot open the pic" << endl;
		return -1;
	}
	resizeToscreen(src, Size(1920 / 4, 1080 / 4));
	int w_pic, h_pic;
	w_pic = src.cols;
	h_pic = src.rows;

	double t = (double)getTickCount();
	Mat fin_res;
	Image imgi(src);
	if (option == "-e")
	{
		fin_res = Mat(src.rows * 2, src.cols * 2, src.type());
		drawtheblock(apply(imgi, 0), fin_res, Point(w_pic, 0), "log");
		drawtheblock(apply(imgi, 1), fin_res, Point(0, h_pic), "sqrt");
		drawtheblock(apply(imgi, 2), fin_res, Point(w_pic, h_pic), "pow_0.3");
	}
	else
		fin_res = Mat(src.rows, src.cols * 2, src.type());

	drawtheblock(src, fin_res, Point(0, 0), "original");
	if (option == "-e")
		NULL;
	else if (option=="-log")
		drawtheblock(apply(imgi, 0), fin_res, Point(w_pic, 0), "log");
	else if (option == "-sqrt")
		drawtheblock(apply(imgi, 1), fin_res, Point(w_pic, 0), "sqrt");
	else if (option == "-pow")
		drawtheblock(apply(imgi, 2), fin_res, Point(w_pic, 0), "pow_0.3");
	else if (option == "-h")
		help();
	else{
		cout << "invalid input , try again" << endl;
		help();
	}
	

	t = ((double)getTickCount() - t) / getTickFrequency();
	cout << "total time:" << t * 1000 << "ms" << endl;
	imshow("dst", fin_res);
	Mat gray;
	cvtColor(apply(imgi, 1), gray, CV_RGB2GRAY);
	Mat g2c = gray2Color(gray,true,8);
	imshow("graytoColor", g2c);
	waitKey(0);
	return 0;
}
Example #2
0
glyph *TeXFont_PFB::getGlyph(Q_UINT16 ch, bool generateCharacterPixmap, const QColor& color)
{
#ifdef DEBUG_PFB
  kdDebug(4300) << "TeXFont_PFB::getGlyph( ch=" << ch << ", '" << (char)(ch) << "', generateCharacterPixmap=" << generateCharacterPixmap << " )" << endl;
#endif
  
  // Paranoia checks
  if (ch >= TeXFontDefinition::max_num_of_chars_in_font) {
    kdError(4300) << "TeXFont_PFB::getGlyph(): Argument is too big." << endl;
    return glyphtable;
  }

  // This is the address of the glyph that will be returned.
  struct glyph *g = glyphtable+ch;


  if (fatalErrorInFontLoading == true)
    return g;
  
  if ((generateCharacterPixmap == true) && ((g->shrunkenCharacter.isNull()) || (color != g->color)) ) {
    int error;
    unsigned int res =  (unsigned int)(parent->displayResolution_in_dpi/parent->enlargement +0.5);
    g->color = color;

    // Character height in 1/64th of points (reminder: 1 pt = 1/72 inch)
    // Only approximate, may vary from file to file!!!! @@@@@

    long int characterSize_in_printers_points_by_64 = (long int)((64.0*72.0*parent->scaled_size_in_DVI_units*parent->font_pool->getCMperDVIunit())/2.54 + 0.5 ); 
    error = FT_Set_Char_Size(face, 0, characterSize_in_printers_points_by_64, res, res );
    if (error) {
      QString msg = i18n("FreeType reported an error when setting the character size for font file %1.").arg(parent->filename);
      if (errorMessage.isEmpty())
	errorMessage = msg;
      kdError(4300) << msg << endl;
      g->shrunkenCharacter.resize(1,1);
      g->shrunkenCharacter.fill(QColor(255, 255, 255));
      return g;
    }
    
    // load glyph image into the slot and erase the previous one
    if (parent->font_pool->getUseFontHints() == true)
      error = FT_Load_Glyph(face, charMap[ch], FT_LOAD_DEFAULT ); 
    else
      error = FT_Load_Glyph(face, charMap[ch], FT_LOAD_NO_HINTING );

    if (error) {
      QString msg = i18n("FreeType is unable to load glyph #%1 from font file %2.").arg(ch).arg(parent->filename);
      if (errorMessage.isEmpty())
	errorMessage = msg;
      kdError(4300) << msg << endl;
      g->shrunkenCharacter.resize(1,1);
      g->shrunkenCharacter.fill(QColor(255, 255, 255));
      return g;
    }
    
    // convert to an anti-aliased bitmap
    error = FT_Render_Glyph( face->glyph, ft_render_mode_normal );
    if (error) {
      QString msg = i18n("FreeType is unable to render glyph #%1 from font file %2.").arg(ch).arg(parent->filename);
      if (errorMessage.isEmpty())
	errorMessage = msg;
      kdError(4300) << msg << endl;
      g->shrunkenCharacter.resize(1,1);
      g->shrunkenCharacter.fill(QColor(255, 255, 255));
      return g;
    }
    
    FT_GlyphSlot slot = face->glyph;

    if ((slot->bitmap.width == 0) || (slot->bitmap.rows == 0)) {
      if (errorMessage.isEmpty())
	errorMessage = i18n("Glyph #%1 is empty.").arg(ch);
      kdError(4300) << i18n("Glyph #%1 from font file %2 is empty.").arg(ch).arg(parent->filename) << endl;
      g->shrunkenCharacter.resize( 15, 15 );
      g->shrunkenCharacter.fill(QColor(255, 0, 0));
      g->x2 = 0;
      g->y2 = 15;
    } else {
      QImage imgi(slot->bitmap.width, slot->bitmap.rows, 32);
      imgi.setAlphaBuffer(true);

      // Do QPixmaps fully support the alpha channel? If yes, we use
      // that. Otherwise, use other routines as a fallback
      if (parent->font_pool->QPixmapSupportsAlpha) {
	// If the alpha channel is properly supported, we set the
	// character glyph to a colored rectangle, and define the
	// character outline only using the alpha channel. That
	// ensures good quality rendering for overlapping characters.
	uchar *srcScanLine = slot->bitmap.buffer;
	for(int row=0; row<slot->bitmap.rows; row++) {
	  uchar *destScanLine = imgi.scanLine(row);
	  for(int col=0; col<slot->bitmap.width; col++) {
	    destScanLine[4*col+0] = color.blue();
	    destScanLine[4*col+1] = color.green();
	    destScanLine[4*col+2] = color.red();
	    destScanLine[4*col+3] = srcScanLine[col];
	  }
	  srcScanLine += slot->bitmap.pitch;
	}
      } else {
	// If the alpha channel is not supported... QT seems to turn
	// the alpha channel into a crude bitmap which is used to mask
	// the resulting QPixmap. In this case, we define the
	// character outline using the image data, and use the alpha
	// channel only to store "maximally opaque" or "completely
	// transparent" values. When characters are rendered,
	// overlapping characters are no longer correctly drawn, but
	// quality is still sufficient for most purposes. One notable
	// exception is output from the gftodvi program, which will be
	// partially unreadable.
	Q_UINT16 rInv = 0xFF - color.red();
	Q_UINT16 gInv = 0xFF - color.green();
	Q_UINT16 bInv = 0xFF - color.blue();
	
	for(Q_UINT16 y=0; y<slot->bitmap.rows; y++) {
	  Q_UINT8 *srcScanLine = slot->bitmap.buffer + y*slot->bitmap.pitch;
	  unsigned int *destScanLine = (unsigned int *)imgi.scanLine(y);
	  for(Q_UINT16 col=0; col<slot->bitmap.width; col++) {
	    Q_UINT16 data =  *srcScanLine;
	    // The value stored in "data" now has the following meaning:
	    // data = 0 -> white; data = 0xff -> use "color"
	    *destScanLine = qRgba(0xFF - (rInv*data + 0x7F) / 0xFF,
				  0xFF - (gInv*data + 0x7F) / 0xFF,
				  0xFF - (bInv*data + 0x7F) / 0xFF,
				  (data > 0x03) ? 0xff : 0x00);
	    destScanLine++;
	    srcScanLine++;
	  }
	}
      }
      
      g->shrunkenCharacter.convertFromImage (imgi, 0);
      g->x2 = -slot->bitmap_left;
      g->y2 = slot->bitmap_top;
    }
  }
  
  // Load glyph width, if that hasn't been done yet.
  if (g->dvi_advance_in_units_of_design_size_by_2e20 == 0) {
    int error = FT_Load_Glyph(face, charMap[ch], FT_LOAD_NO_SCALE);
    if (error) {
      QString msg = i18n("FreeType is unable to load metric for glyph #%1 from font file %2.").arg(ch).arg(parent->filename);
      if (errorMessage.isEmpty())
	errorMessage = msg;
      kdError(4300) << msg << endl;
      g->dvi_advance_in_units_of_design_size_by_2e20 =  1;
    }
    g->dvi_advance_in_units_of_design_size_by_2e20 =  (Q_INT32)(((Q_INT64)(1<<20) * (Q_INT64)face->glyph->metrics.horiAdvance) / (Q_INT64)face->units_per_EM);
  }
  
  return g;
}