Ejemplo n.º 1
0
QColor KColorUtils::tint(const QColor &base, const QColor &color, qreal amount)
{
    if (amount <= 0.0) {
        return base;
    }
    if (amount >= 1.0) {
        return color;
    }
    if (qIsNaN(amount)) {
        return base;
    }

    qreal baseLuma = luma(base); //cache value because luma call is expensive
    double ri = contrastRatioForLuma(baseLuma, luma(color));
    double rg = 1.0 + ((ri + 1.0) * amount * amount * amount);
    double u = 1.0, l = 0.0;
    QColor result;
    for (int i = 12; i; --i) {
        double a = 0.5 * (l + u);
        result = tintHelper(base, baseLuma, color, a);
        double ra = contrastRatioForLuma(baseLuma, luma(result));
        if (ra > rg) {
            u = a;
        } else {
            l = a;
        }
    }
    return result;
}
Ejemplo n.º 2
0
// Given a 3-channel RGB input, return a function with a single
// channel - the luminance channel (grayscale)
// See http://en.wikipedia.org/wiki/YUV
Halide::Func rgb_extract_luma(Halide::Func rgb) {
    Halide::Var x,y,c;
    Halide::Func luma("luma");
    luma(x, y) = 0.299f * rgb(x, y, RED) + 
                 0.587f * rgb(x, y, GREEN) + 
                 0.114f * rgb(x, y, BLUE);
    return luma;
}
Ejemplo n.º 3
0
QString Conversion::contrastColor(const QString& color)
{
    if (color.isNull()) {
        return QColor(Qt::black).name();
    }

#if 0
    QColor color(bgColor);
    int d = 0;

    // counting the perceptive luminance - human eye favors green color...
    double a = 1 - (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255;

    if (a < 0.5) {
        d = 0; // bright colors - black font
    } else {
        d = 255; // dark colors - white font
    }
    return  QColor(d, d, d).name();
#else
    int luminosity = luma(QColor(color));
    if (luminosity <= 60) {
         return QColor(Qt::white).name();
    } else {
         return QColor(Qt::black).name();
    }
#endif
}
uint8_t ADMVideoMPD3Dlow::configure(AVDMGenericVideoStream *instream)
{

        _in=instream;
        ELEM_TYPE_FLOAT fluma,fchroma,ftemporal;
#define PX(x) &x
#define OOP(x,y) f##x=(ELEM_TYPE_FLOAT )_param->y;
        
        OOP(luma,param1);
        OOP(chroma,param2);
        OOP(temporal,param3);
        
    diaElemFloat   luma(PX(fluma),QT_TR_NOOP("_Spatial luma strength:"),0.,100.);
    diaElemFloat   chroma(PX(fchroma),QT_TR_NOOP("S_patial chroma strength:"),0.,100.);
    diaElemFloat   temporal(PX(ftemporal),QT_TR_NOOP("_Temporal strength:"),0.,100.);
    
       diaElem *elems[3]={&luma,&chroma,&temporal};
  
   if(  diaFactoryRun(QT_TR_NOOP("MPlayer denoise3d"),3,elems))
        {
#undef OOP
#define OOP(x,y) _param->y=(double) f##x
                OOP(luma,param1);
                OOP(chroma,param2);
                OOP(temporal,param3);
          
                setup();
                return 1;
        }
        return 0;
}
uint8_t ADMVideoLargeMedian::configure(AVDMGenericVideoStream * instream)
{
  diaElemToggle luma(&(_param->luma),QT_TR_NOOP("_Process luma"),QT_TR_NOOP("Process luma plane"));
  diaElemToggle chroma(&(_param->chroma),QT_TR_NOOP("P_rocess chroma"));
  
  diaElem *elems[2]={&luma,&chroma};
  
  return diaFactoryRun(QT_TR_NOOP("Large Median 5x5"),2,elems);
  
}
Ejemplo n.º 6
0
/**
    \fn configure
*/
bool largeMedian::configure(void)
{
  
  diaElemToggle luma(&(param.luma),QT_TRANSLATE_NOOP("largemedian","_Process luma"),QT_TRANSLATE_NOOP("largemedian","Process luma plane"));
  diaElemToggle chroma(&(param.chroma),QT_TRANSLATE_NOOP("largemedian","P_rocess chroma"));
  
  diaElem *elems[2]={&luma,&chroma};
  
  return diaFactoryRun(QT_TRANSLATE_NOOP("largemedian","Fast Convolution"),2,elems);
}
uint8_t AVDMFastVideoConvolution::configure(AVDMGenericVideoStream * instream)
{
  
  //return DIA_getLumaChroma(&(_param->luma),&(_param->chroma)) ; 
  diaElemToggle luma(&(_param->luma),QT_TR_NOOP("_Process luma"),QT_TR_NOOP("Process luma plane"));
  diaElemToggle chroma(&(_param->chroma),QT_TR_NOOP("P_rocess chroma"));
  
  diaElem *elems[2]={&luma,&chroma};
  
  return diaFactoryRun(QT_TR_NOOP("Fast Convolution"),2,elems);
}
Ejemplo n.º 8
0
std::vector<pixel_t> construct_pixels(B::Image &img){
	int w, h;
	img.get_dimensions(w, h);
	
	std::vector<pixel_t> pixels(w * h);

	B::ImageIterator it(img);
	u8 *pixel;
	int i = 0;
	while (it.next(pixel))
		pixels[i++] = luma(pixel[0], pixel[1], pixel[2]);
	
	return pixels;
}
uint8_t ADMVideoMaskedSoften::configure( AVDMGenericVideoStream *instream)
{
        _in=instream;
        /*uint32_t luma,chroma;
	uint32_t radius;
	*/
        
        diaElemUInteger luma(&(_param->luma),QT_TR_NOOP("_Luma threshold:"),0,255);
        diaElemUInteger chroma(&(_param->chroma),QT_TR_NOOP("C_hroma threshold:"),0,255);
        diaElemUInteger radius(&(_param->radius),QT_TR_NOOP("_Radius:"),1,60);
	  
    diaElem *elems[3]={&luma,&chroma,&radius};
  
    return diaFactoryRun(QT_TR_NOOP("Soften"),3,elems);
}
Ejemplo n.º 10
0
uint8_t AVDMVideoVlad::configure( AVDMGenericVideoStream *instream)
{
UNUSED_ARG(instream);
int i,j;

   diaElemUInteger luma(&(_param->ythresholdMask),QT_TR_NOOP("_Luma temporal threshold:"),0,255);
   diaElemUInteger chroma(&(_param->cthresholdMask),QT_TR_NOOP("Ch_roma temporal threshold:"),0,255);
    
    diaElem *elems[]={&luma,&chroma};
  
    if(diaFactoryRun(QT_TR_NOOP("Temporal Cleaner"),sizeof(elems)/sizeof(diaElem *),elems))
    {
      ythresholdMask = (uint64_t)_param->ythresholdMask;
      cthresholdMask = (uint64_t)_param->cthresholdMask;	   

      EXPAND(	ythresholdMask);
      EXPAND(	cthresholdMask);	
      return 1;
    }
    return 0;
}
Ejemplo n.º 11
0
QString Conversion::computeAutoColor(const wvWare::Word97::SHD& shd, const QString& bgColor, const QString& fontColor)
{
    // NOTE: by definition, see
    // http://social.msdn.microsoft.com/Forums/en-US/os_binaryfile/thread/a02a9a24-efb6-4ba0-a187-0e3d2704882b

#ifdef CONVERSION_DEBUG_SHD
    qDebug() << Q_FUNC_INFO;
    qDebug() << "bgColor:" << bgColor;
    qDebug() << "fontColor:" << fontColor;
    qDebug() << "ipat:" << shd.ipat;
    qDebug() << "cvBack:" << hex << shd.cvBack;
    qDebug() << "cvFore:" << hex << shd.cvFore;
#endif

    if (shd.isShdAuto() || shd.isShdNil()) {
        return contrastColor(bgColor);
    }

    QColor foreColor;
    QColor backColor;

    if (shd.cvFore == wvWare::Word97::cvAuto) {
        if (fontColor.isEmpty()) {
            foreColor = QColor(contrastColor(bgColor));
        } else {
            foreColor = QColor(fontColor);
        }
    } else {
        foreColor = QColor(QRgb(shd.cvFore));
    }

    if (shd.cvBack == wvWare::Word97::cvAuto) {
        if (bgColor.isEmpty()) {
            backColor = QColor(Qt::white).name();
        } else {
            backColor = QColor(bgColor);
        }
    } else {
        backColor = QColor(QRgb(shd.cvBack));
    }

    int luminosity = 0;

    if (shd.ipat == ipatAuto) {
        luminosity = luma(backColor);
    }
    else if (shd.ipat == ipatSolid) {
        luminosity = luma(foreColor);
    }
    else if ((shd.ipat > 13) && (shd.ipat < 34)) {
        luminosity = 61;
    } else {
        if (SHADING_TABLE.contains(shd.ipat)) {
            qreal pct = SHADING_TABLE.value(shd.ipat);
            luminosity = yMix( luma(foreColor), luma(backColor), pct);
        } else {
            // this should not happen, but it's binary data
            luminosity = 61;
        }
    }

#ifdef CONVERSION_DEBUG_SHD
    qDebug() << "ooooooooooooooooooooooooooooooo    chp: oooooooooooooooo bgColor:" << bgColor;
    qDebug() << "fontColor:" << fontColor;
    qDebug() << (shd.cvFore == wvWare::Word97::cvAuto);
    qDebug() << (shd.cvBack == wvWare::Word97::cvAuto);
    qDebug() << "ipat" << shd.ipat;
    qDebug() << "fore" << QString::number(shd.cvFore | 0xff000000, 16).right(6) << foreColor.name();
    qDebug() << "back" << QString::number(shd.cvBack | 0xff000000, 16).right(6) << backColor.name();
    qDebug() << "luminosity " << luminosity;
#endif

    if (luminosity <= 60) { // it is dark color
        // window background color
        return QColor(Qt::white).name();
    } else {
        // window text color
        return QColor(Qt::black).name();
    }

} //computeAutoColor
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
	MyAssertHandler assertHandler;
	MyMessageHandler messageHandler;

	bool compareNormal = false;
	bool compareAlpha = false;

	nv::Path input0;
	nv::Path input1;
	nv::Path output;

	// Parse arguments.
	for (int i = 1; i < argc; i++)
	{
		// Input options.
		if (strcmp("-normal", argv[i]) == 0)
		{
			compareNormal = true;
		}
		else if (strcmp("-alpha", argv[i]) == 0)
		{
			compareAlpha = true;
		}
		else if (argv[i][0] != '-')
		{
			input0 = argv[i];

			if (i+1 < argc && argv[i+1][0] != '-') {
				input1 = argv[i+1];
			}

			break;
		}
		else
		{
			printf("Warning: unrecognized option \"%s\"\n", argv[i]);
		}
	}

	if (input0.isNull() || input1.isNull())
	{
		printf("NVIDIA Texture Tools - Copyright NVIDIA Corporation 2007\n\n");
		
		printf("usage: nvimgdiff [options] original_file updated_file [output]\n\n");
		
		printf("Diff options:\n");
		printf("  -normal \tCompare images as if they were normal maps.\n");
		printf("  -alpha  \tCompare alpha weighted images.\n");

		return 1;
	}

	nv::Image image0, image1;
	if (!loadImage(image0, input0.str())) return 0;
	if (!loadImage(image1, input1.str())) return 0;

	const uint w0 = image0.width();
	const uint h0 = image0.height();
	const uint w1 = image1.width();
	const uint h1 = image1.height();
	const uint w = nv::min(w0, w1);
	const uint h = nv::min(h0, h1);

	// Compute errors.
	Error error_r;
	Error error_g;
	Error error_b;
	Error error_a;
    Error error_luma;
	Error error_total;
	NormalError error_normal;

	for (uint i = 0; i < h; i++)
	{
		for (uint e = 0; e < w; e++)
		{
			const nv::Color32 c0(image0.pixel(e, i));
			const nv::Color32 c1(image1.pixel(e, i));

			double r = float(c0.r - c1.r);
			double g = float(c0.g - c1.g);
			double b = float(c0.b - c1.b);
			double a = float(c0.a - c1.a);

			error_r.addSample(r);
			error_g.addSample(g);
			error_b.addSample(b);
			error_a.addSample(a);

            double l0 = luma(c0);
            double l1 = luma(c1);

            error_luma.addSample(l0 - l1);

            double d = sqrt(r*r + g*g + b*b);

			if (compareAlpha) {
                d *= c0.a / 255.0;
			}

            error_total.addSample(d);

			if (compareNormal) {
				error_normal.addSample(c0, c1);
			}
		}
	}

	error_r.done();
	error_g.done();
	error_b.done();
	error_a.done();
    error_luma.done();
	error_total.done();
	error_normal.done();
	

	printf("Image size compared: %dx%d\n", w, h);
	if (w != w0 || w != w1 || h != h0 || h != h1) {
		printf("--- NOTE: only the overlap between the 2 images (%d,%d) and (%d,%d) was compared\n", w0, h0, w1, h1);
	}
	printf("Total pixels: %d\n", w*h);

	printf("Color:\n");
	error_total.print();

	printf("Luma:\n");
	error_luma.print();

	if (compareNormal)
	{
		printf("Normal:\n");
		error_normal.print();
	}

	if (compareAlpha)
	{
		printf("Alpha:\n");
		error_a.print();
	}

	// @@ Write image difference.
	
	return 0;
}
Ejemplo n.º 13
0
qreal KColorUtils::contrastRatio(const QColor &c1, const QColor &c2)
{
    return contrastRatioForLuma(luma(c1), luma(c2));
}