Exemplo n.º 1
0
struct cxpr
cxround (struct cxpr z)
{
  struct cxpr w;

  w.re = xround (z.re);
  w.im = xround (z.im);
  return w;
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
    auto a = xround(5.5, int()); // = 6
    static_assert(std::is_same<decltype(a), int>::value, "");
    std::cout << a << "\n";       
    
    double b = xround(5.5); // = 6.0
    static_assert(std::is_same<decltype(b), double>::value, "");
    std::cout << b << "\n";
}    
Exemplo n.º 3
0
void rmlt_coefs_to_samples(int16_t coefs[],
                           int16_t old_samples[],
                           int16_t out_samples[],
                           int dct_length,
                           int16_t mag_shift)
{
    int i;
    int half_dct_length;
    int last;
    int16_t new_samples[MAX_DCT_LENGTH];
    const int16_t *win;
    int32_t sum;

    half_dct_length = dct_length >> 1;

    /* Perform a Type IV (inverse) DCT on the coefficients */
    dct_type_iv_s(coefs, new_samples, dct_length);

    if (mag_shift > 0)
    {
        for (i = 0;  i < dct_length;  i++)
            new_samples[i] = shr(new_samples[i], mag_shift);
    }
    else if (mag_shift < 0)
    {
        mag_shift = negate(mag_shift);
        for (i = 0;  i < dct_length;  i++)
            new_samples[i] = shl(new_samples[i], mag_shift);
    }

    win = (dct_length == DCT_LENGTH)  ?  rmlt_to_samples_window  :  max_rmlt_to_samples_window;
    last = half_dct_length - 1;
    for (i = 0;  i < half_dct_length;  i++)
    {
        /* Get the first half of the windowed samples */
        sum = L_mult(win[i], new_samples[last - i]);
        sum = L_mac(sum, win[dct_length - i - 1], old_samples[i]);
        out_samples[i] = xround(L_shl(sum, 2));
        /* Get the second half of the windowed samples */
        sum = L_mult(win[half_dct_length + i], new_samples[i]);
        sum = L_mac(sum, negate(win[last - i]), old_samples[last - i]);
        out_samples[half_dct_length + i] = xround(L_shl(sum, 2));
    }

    /* Save the second half of the new samples for
       next time, when they will be the old samples. */
    vec_copyi16(old_samples, &new_samples[half_dct_length], half_dct_length);
}
Exemplo n.º 4
0
Arquivo: swt.c Projeto: rosrad/go-rep
int32
maxround(int32 max, int32 v)
{
	v = xround(v, SZ_VLONG);
	if(v > max)
		return v;
	return max;
}
Exemplo n.º 5
0
ListBoxControl::ListBoxControl (const graphics_object& go, QListWidget* list)
     : BaseControl (go, list), m_blockCallback (false)
{
  uicontrol::properties& up = properties<uicontrol> ();

  list->addItems (Utils::fromStringVector (up.get_string_vector ()));
  if ((up.get_max () - up.get_min ()) > 1)
    list->setSelectionMode (QAbstractItemView::ExtendedSelection);
  else
    list->setSelectionMode (QAbstractItemView::SingleSelection);
  Matrix value = up.get_value ().matrix_value ();
  if (value.numel () > 0)
    {
      octave_idx_type n = value.numel ();
      int lc = list->count ();

      for (octave_idx_type i = 0; i < n; i++)
	{
	  int idx = xround (value(i));

	  if (1 <= idx && idx <= lc)
	    {
	      list->item (idx-1)->setSelected (true);
	      if (i == 0
		  && list->selectionMode () ==
		  	QAbstractItemView::SingleSelection)
		break;
	    }
	}
    }

  list->removeEventFilter (this);
  list->viewport ()->installEventFilter (this);

  connect (list, SIGNAL (itemSelectionChanged (void)),
	   SLOT (itemSelectionChanged (void)));
}
Exemplo n.º 6
0
void
codgen(Node *n, Node *nn)
{
	Prog *sp;
	Node *n1, nod, nod1;

	cursafe = 0;
	curarg = 0;
	maxargsafe = 0;

	/*
	 * isolate name
	 */
	for(n1 = nn;; n1 = n1->left) {
		if(n1 == Z) {
			diag(nn, "cant find function name");
			return;
		}
		if(n1->op == ONAME)
			break;
	}
	nearln = nn->lineno;

	p = gtext(n1->sym, stkoff);
	sp = p;

	/*
	 * isolate first argument
	 */
	if(REGARG >= 0) {
		if(typesuv[thisfn->link->etype]) {
			nod1 = *nodret->left;
			nodreg(&nod, &nod1, REGARG);
			gmove(&nod, &nod1);
		} else
		if(firstarg && typechlp[firstargtype->etype]) {
			nod1 = *nodret->left;
			nod1.sym = firstarg;
			nod1.type = firstargtype;
			nod1.xoffset = align(0, firstargtype, Aarg1, nil);
			nod1.etype = firstargtype->etype;
			nodreg(&nod, &nod1, REGARG);
			gmove(&nod, &nod1);
		}
	}

	retok = 0;

	canreach = 1;
	warnreach = 1;
	gen(n);
	if(canreach && thisfn->link->etype != TVOID)
		diag(Z, "no return at end of function: %s", n1->sym->name);
	noretval(3);
	gbranch(ORETURN);

	if(!debug['N'] || debug['R'] || debug['P'])
		regopt(sp);

	if(thechar=='6' || thechar=='7')	/* [sic] */
		maxargsafe = xround(maxargsafe, 8);
	sp->to.offset += maxargsafe;
}
Exemplo n.º 7
0
/*
	hPixels		- X resolution
	vLines		- Y resolution
	freq		- Frequency (Hz, KHz or MHz depending on type)
	type  		- 1 - vertical, 2 - horizontal, 3 - dot clock
	margins		- True if margins should be generated
	interlace	- True if interlaced timings to be generated
	t		- Place to store the resulting timings
*/
void gtf_calcTimings (double hPixels, double vLines, double freq, int type, int wantMargins, int wantInterlace, gtf_timings *t)
{
	double interlace;
	double vFieldRate;
	double hPeriod = 0;
	double topMarginLines;
	double botMarginLines;
	double leftMarginPixels;
	double rightMarginPixels;
	double hPeriodEst = 0;
	double vSyncBP = 0;
	double vBackPorch = 0;
	double vTotalLines = 0;
	double vFieldRateEst;
	double hTotalPixels;
	double hTotalActivePixels;
	double hBlankPixels;
	double idealDutyCycle = 0;
	double hSyncWidth;
	double hSyncBP;
	double hBackPorch;
	double idealHPeriod;
	double vFreq;
	double hFreq;
	double dotClock;
	gtf_constants c;

	/* Get rounded gtf constants used for internal calculations */
	c.margin = GC.margin;
	c.cellGran = xround(GC.cellGran);
	c.minPorch = xround(GC.minPorch);
	c.vSyncRqd = xround(GC.vSyncRqd);
	c.hSync = GC.hSync;
	c.minVSyncBP = GC.minVSyncBP;
	if (GC.k == 0) {
		c.k = 0.001;
        } else {
		c.k = GC.k;
	}
	c.m = (c.k / 256) * GC.m;
	c.c = (GC.c - GC.j) * (c.k / 256) + GC.j;
	c.j = GC.j;
	/* Move input parameters into appropriate variables */
	vFreq = hFreq = dotClock = freq;
	/* Round pixels to character cell granularity */
	hPixels = xround(hPixels / c.cellGran) * c.cellGran;
	/* For interlaced mode halve the vertical parameters, and double
	 * the required field refresh rate.
	 */
	if (wantInterlace) {
		vLines = xround(vLines / 2);
		vFieldRate = vFreq * 2;
		dotClock = dotClock * 2;
		interlace = 0.5;
	} else {
		vFieldRate = vFreq;
		interlace = 0;
	}
	/* Determine the lines for margins */
	if (wantMargins) {
		topMarginLines = xround(c.margin / 100 * vLines);
		botMarginLines = xround(c.margin / 100 * vLines);
	} else {
		topMarginLines = 0;
		botMarginLines = 0;
	}
	if (type != gtf_lockPF) {
		if (type == gtf_lockVF) {
			/* Estimate the horizontal period */
			hPeriodEst = ((1/vFieldRate) - (c.minVSyncBP/1000000)) /
				     (vLines + (2*topMarginLines) + c.minPorch + interlace) * 1000000;
			/* Find the number of lines in vSync + back porch */
			vSyncBP = xround(c.minVSyncBP / hPeriodEst);
		} else if (type == gtf_lockHF) {
			/* Find the number of lines in vSync + back porch */
			vSyncBP = xround((c.minVSyncBP * hFreq) / 1000);
		}
		/* Find the number of lines in the V back porch alone */
		vBackPorch = vSyncBP - c.vSyncRqd;
		/* Find the total number of lines in the vertical period */
		vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP +
		              interlace + c.minPorch;
		if (type == gtf_lockVF) {
			/* Estimate the vertical frequency */
			vFieldRateEst = 1000000 / (hPeriodEst * vTotalLines);
			/* Find the actual horizontal period */
			hPeriod = (hPeriodEst * vFieldRateEst) / vFieldRate;
			/* Find the actual vertical field frequency */
			vFieldRate = 1000000 / (hPeriod * vTotalLines);
		} else if (type == gtf_lockHF) {
			/* Find the actual vertical field frequency */
			vFieldRate = (hFreq / vTotalLines) * 1000;
		}
	}
	/* Find the number of pixels in the left and right margins */
	if (wantMargins) {
		leftMarginPixels = xround(hPixels * c.margin) / (100 * c.cellGran);
		rightMarginPixels = xround(hPixels * c.margin) / (100 * c.cellGran);
	} else {
		leftMarginPixels = 0;
		rightMarginPixels = 0;
	}
	/* Find the total number of active pixels in image + margins */
	hTotalActivePixels = hPixels + leftMarginPixels + rightMarginPixels;
	if (type == gtf_lockVF) {
		/* Find the ideal blanking duty cycle */
		idealDutyCycle = c.c - ((c.m * hPeriod) / 1000);
	} else if (type == gtf_lockHF) {
		/* Find the ideal blanking duty cycle */
		idealDutyCycle = c.c - (c.m / hFreq);
	} else if (type == gtf_lockPF) {
		/* Find ideal horizontal period from blanking duty cycle formula */
		idealHPeriod = (((c.c - 100) + (sqrt((pow(100-c.c,2)) +
			        (0.4 * c.m * (hTotalActivePixels + rightMarginPixels +
			        leftMarginPixels) / dotClock)))) / (2 * c.m)) * 1000;
		/* Find the ideal blanking duty cycle */
		idealDutyCycle = c.c - ((c.m * idealHPeriod) / 1000);
	}
	/* Find the number of pixels in blanking time */
	hBlankPixels = xround((hTotalActivePixels * idealDutyCycle) /
	                     ((100 - idealDutyCycle) * 2 * c.cellGran)) * (2 * c.cellGran);
	/* Find the total number of pixels */
	hTotalPixels = hTotalActivePixels + hBlankPixels;
	/* Find the horizontal back porch */
	hBackPorch = xround((hBlankPixels / 2) / c.cellGran) * c.cellGran;
	/* Find the horizontal sync width */
	hSyncWidth = xround(((c.hSync/100) * hTotalPixels) / c.cellGran) * c.cellGran;
	/* Find the horizontal sync + back porch */
	hSyncBP = hBackPorch + hSyncWidth;
	if (type == gtf_lockPF) {
		/* Find the horizontal frequency */
		hFreq = (dotClock / hTotalPixels) * 1000;
		/* Find the horizontal period */
		hPeriod = 1000 / hFreq;
		/* Find the number of lines in vSync + back porch */
		vSyncBP = xround((c.minVSyncBP * hFreq) / 1000);
		/* Find the number of lines in the V back porch alone */
		vBackPorch = vSyncBP - c.vSyncRqd;
		/* Find the total number of lines in the vertical period */
		vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP +
		              interlace + c.minPorch;
		/* Find the actual vertical field frequency */
		vFieldRate = (hFreq / vTotalLines) * 1000;
	} else {
		if (type == gtf_lockVF) {
			/* Find the horizontal frequency */
			hFreq = 1000 / hPeriod;
		} else if (type == gtf_lockHF) {
			/* Find the horizontal frequency */
			hPeriod = 1000 / hFreq;
		}
        	/* Find the pixel clock frequency */
		dotClock = hTotalPixels / hPeriod;
	}
	/* Find the vertical frame frequency */
	if (wantInterlace) {
		vFreq = vFieldRate / 2;
		dotClock = dotClock / 2;
	} else {
		vFreq = vFieldRate;
	}
	/* Return the computed frequencies */
	t->vFreq = vFreq;
	t->hFreq = hFreq;
	t->dotClock = dotClock;
	/* Determine the vertical timing parameters */
	t->h.hTotal = hTotalPixels;
	t->h.hDisp = hTotalActivePixels;
	t->h.hSyncStart = t->h.hTotal - hSyncBP;
	t->h.hSyncEnd = t->h.hTotal - hBackPorch;
	t->h.hFrontPorch = t->h.hSyncStart - t->h.hDisp;
	t->h.hSyncWidth = hSyncWidth;
	t->h.hBackPorch = hBackPorch;
	/* Determine the vertical timing parameters */
	t->v.vTotal = vTotalLines;
	t->v.vDisp = vLines;
	t->v.vSyncStart = t->v.vTotal - vSyncBP;
	t->v.vSyncEnd = t->v.vTotal - vBackPorch;
	t->v.vFrontPorch = t->v.vSyncStart - t->v.vDisp;
	t->v.vSyncWidth = c.vSyncRqd;
	t->v.vBackPorch = vBackPorch;
	/* Mark as gtf timing using the sync polarities */
	t->interlace = (wantInterlace) ? 'I' : 'N';
	t->hSyncPol = '-';
	t->vSyncPol = '+';
}
Exemplo n.º 8
0
Arquivo: swt.c Projeto: rosrad/go-rep
int32
align(int32 i, Type *t, int op, int32 *maxalign)
{
	int32 o;
	Type *v;
	int w;

	o = i;
	w = 1;
	switch(op) {
	default:
		diag(Z, "unknown align opcode %d", op);
		break;

	case Asu2:	/* padding at end of a struct */
		w = *maxalign;
		if(w < 1)
			w = 1;
		if(packflg)
			w = packflg;
		break;

	case Ael1:	/* initial align of struct element */
		for(v=t; v->etype==TARRAY; v=v->link)
			;
		if(v->etype == TSTRUCT || v->etype == TUNION)
			w = v->align;
		else
			w = ewidth[v->etype];
		if(w < 1 || w > SZ_VLONG)
			fatal(Z, "align");
		if(packflg) 
			w = packflg;
		break;

	case Ael2:	/* width of a struct element */
		o += t->width;
		break;

	case Aarg0:	/* initial passbyptr argument in arg list */
		if(typesu[t->etype]) {
			o = align(o, types[TIND], Aarg1, nil);
			o = align(o, types[TIND], Aarg2, nil);
		}
		break;

	case Aarg1:	/* initial align of parameter */
		if(ewidth[TIND] == 4) {
			if(typesu[t->etype]) {
				for(v = t->link; v != T; v = v->down)
					o = align(o, v, Aarg1, maxalign);
				goto out;
			}
			w = ewidth[t->etype];
			if(typev[t->etype] || t->etype == TDOUBLE)
				w = 8;
			else if(w <= 0 || w >= 4)
				w = 4;
			else
				w = 1;
			break;
		}
		w = ewidth[t->etype];
		if(w <= 0 || w >= SZ_VLONG) {
			w = SZ_VLONG;
			break;
		}
		w = 1;		/* little endian no adjustment */
		break;

	case Aarg2:	/* width of a parameter */
		o += t->width;
		if(ewidth[TIND] == 4) {
			o = align(o, t, Aarg1, maxalign);
			goto out;
		}
		w = t->width;
		if(w > SZ_VLONG)
			w = SZ_VLONG;
		break;

	case Aaut3:	/* total align of automatic */
		o = align(o, t, Ael1, nil);
		o = align(o, t, Ael2, nil);
		break;
	}
	o = xround(o, w);
	if(maxalign && *maxalign < w)
		*maxalign = w;
out:
	if(debug['A'])
		print("align %s %d %T = %d\n", bnames[op], i, t, o);
	return o;
}
Exemplo n.º 9
0
static void
set_user_icon_from_png (char *path, uint32_t bgcolor)
{
	int j, alpha;
	image_s *img = image_new_from_png (path, 1, NULL, 0, 1, 0, &alpha);
	image_s *img_sm, *img_lrg;
	struct icon_struct newicons;
	double n, scale_lrg, scale_sm;

	if (img == (image_s *)NULL)
	{
		DPRINTF (E_WARN, L_GENERAL,
				"Unable to load icon file \"%s\".\n", path);
		return;
	}

	n = (img->height > img->width) ? img->height : img->width;
	scale_lrg = 120.0 / n;
	scale_sm = 48.0 / n;

	if ((img_lrg = image_resize (img,
					xround (img->width*scale_lrg),
					xround(img->height*scale_lrg))) == (image_s *)NULL)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to rescale large icon image (%s).\n", path);
		image_free (img);
		return;
	}

	if ((img_sm = image_resize (img,
					xround(img->width*scale_sm),
					xround(img->height*scale_sm))) == (image_s *)NULL)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to rescale small icon image (%s).\n", path);
		image_free (img);
		image_free (img_lrg);
		return;
	}

	image_free (img);

	for (j = ICON_FIRST; j <= ICON_LAST; j++)
		newicons.dynamic[j] = 1;

	if ((newicons.size[ICON_PNG_LRG] = image_save_to_png (img_lrg, NULL,
			&newicons.icon[ICON_PNG_LRG], alpha, 9)) < 0)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create large PNG icon (%s).\n", path);
		newicons.icon[ICON_PNG_LRG] = icons.icon[ICON_PNG_LRG];
		newicons.size[ICON_PNG_LRG] = icons.size[ICON_PNG_LRG];
		newicons.dynamic[ICON_PNG_LRG] = icons.dynamic[ICON_PNG_LRG];
	}

	if ((newicons.size[ICON_PNG_SM] = image_save_to_png (img_sm, NULL,
			&newicons.icon[ICON_PNG_SM], alpha, 9)) < 0)
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create small PNG icon (%s).\n", path);
		newicons.icon[ICON_PNG_SM] = icons.icon[ICON_PNG_SM];
		newicons.size[ICON_PNG_SM] = icons.size[ICON_PNG_SM];
		newicons.dynamic[ICON_PNG_SM] = icons.dynamic[ICON_PNG_SM];
	}

	if (alpha)
	{
		image_bgcolor_composite (img_lrg, bgcolor, -1);
		image_bgcolor_composite (img_sm, bgcolor, -1);
	}

	if (!(newicons.icon[ICON_JPEG_LRG] = image_save_to_jpeg_buf (img_lrg,
			&newicons.size[ICON_JPEG_LRG])))
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create large JPEG icon (%s).\n", path);
		newicons.icon[ICON_JPEG_LRG] = icons.icon[ICON_JPEG_LRG];
		newicons.size[ICON_JPEG_LRG] = icons.size[ICON_JPEG_LRG];
		newicons.dynamic[ICON_JPEG_LRG] = icons.dynamic[ICON_JPEG_LRG];
	}

	if (!(newicons.icon[ICON_JPEG_SM] = image_save_to_jpeg_buf (img_sm,
			&newicons.size[ICON_JPEG_SM])))
	{
		DPRINTF (E_ERROR, L_GENERAL,
				"Failed to create small JPEG icon (%s).\n", path);
		newicons.icon[ICON_JPEG_SM] = icons.icon[ICON_JPEG_SM];
		newicons.size[ICON_JPEG_SM] = icons.size[ICON_JPEG_SM];
		newicons.dynamic[ICON_JPEG_SM] = icons.dynamic[ICON_JPEG_SM];
	}

	image_free (img_sm);
	image_free (img_lrg);
	destroy_icons (&icons);
	icons = newicons;
}
Exemplo n.º 10
0
int16_t samples_to_rmlt_coefs(const int16_t new_samples[],
                              int16_t old_samples[],
                              int16_t coefs[],
                              int dct_length)
{
    int i;
    int half_dct_length;
    int last;
    int16_t mag_shift;
    int16_t n;
    int16_t windowed_data[MAX_DCT_LENGTH];
    const int16_t *win;
    int32_t acca;
    int32_t accb;
    int16_t temp;
    int16_t temp1;
    int16_t temp2;

    half_dct_length = dct_length >> 1;

    win = (dct_length == DCT_LENGTH)  ?  samples_to_rmlt_window  :  max_samples_to_rmlt_window;
    /* Get the first half of the windowed samples */
    last = half_dct_length - 1;
    for (i = 0;  i < half_dct_length;  i++)
    {
        acca = L_mult(win[last - i], old_samples[last - i]);
        acca = L_mac(acca, win[half_dct_length + i], old_samples[half_dct_length + i]);
        windowed_data[i] = xround(acca);
    }
    /* Get the second half of the windowed samples */
    last = dct_length - 1;
    for (i = 0;  i < half_dct_length;  i++)
    {
        acca = L_mult(win[last - i], new_samples[i]);
        acca = L_mac(acca, negate(win[i]), new_samples[last - i]);
        windowed_data[half_dct_length + i] = xround(acca);
    }

    /* Save the new samples for next time, when they will be the old samples. */
    vec_copyi16(old_samples, new_samples, dct_length);

    /* Calculate how many bits to shift up the input to the DCT. */
    temp1 = 0;
    for (i = 0;  i < dct_length;  i++)
    {
        temp2 = abs_s(windowed_data[i]);
        temp = sub(temp2, temp1);
        if (temp > 0)
            temp1 = temp2;
    }

    mag_shift = 0;
    temp = sub(temp1, 14000);
    if (temp < 0)
    {
        temp = sub(temp1, 438);
        temp = (temp < 0)  ?  add(temp1, 1)  :  temp1;
        accb = L_mult(temp, 9587);
        acca = L_shr(accb, 20);
        temp = norm_s((int16_t) acca);
        mag_shift = (temp == 0)  ?  9  :  sub(temp, 6);
    }

    acca = 0;
    for (i = 0;  i < dct_length;  i++)
    {
        temp = abs_s(windowed_data[i]);
        acca = L_add(acca, temp);
    }

    acca = L_shr(acca, 7);
    if (temp1 < acca)
        mag_shift = sub(mag_shift, 1);
    if (mag_shift > 0)
    {
        for (i = 0;  i < dct_length;  i++)
            windowed_data[i] = shl(windowed_data[i], mag_shift);
    }
    else if (mag_shift < 0)
    {
        n = negate(mag_shift);
        for (i = 0;  i < dct_length;  i++)
            windowed_data[i] = shr(windowed_data[i], n);
    }

    /* Perform a Type IV DCT on the windowed data to get the coefficients */
    dct_type_iv_a(windowed_data, coefs, dct_length);

    return mag_shift;
}
Exemplo n.º 11
0
Arquivo: swt.c Projeto: 8l/golang
int32
align(int32 i, Type *t, int op, int32 *maxalign)
{
	int32 o;
	Type *v;
	int w, packw;

	o = i;
	w = 1;
	packw = 0;
	switch(op) {
	default:
		diag(Z, "unknown align opcode %d", op);
		break;

	case Asu2:	/* padding at end of a struct */
		w = *maxalign;
		if(w < 1)
			w = 1;
		if(packflg)
			packw = packflg;
		break;

	case Ael1:	/* initial align of struct element */
		for(v=t; v->etype==TARRAY; v=v->link)
			;
		if(v->etype == TSTRUCT || v->etype == TUNION)
			w = v->align;
		else {
			w = ewidth[v->etype];
			if(w == 8)
				w = 4;
		}
		if(w < 1 || w > SZ_LONG)
			fatal(Z, "align");
		if(packflg) 
			packw = packflg;
		break;

	case Ael2:	/* width of a struct element */
		o += t->width;
		break;

	case Aarg0:	/* initial passbyptr argument in arg list */
		if(typesuv[t->etype]) {
			o = align(o, types[TIND], Aarg1, nil);
			o = align(o, types[TIND], Aarg2, nil);
		}
		break;

	case Aarg1:	/* initial align of parameter */
		w = ewidth[t->etype];
		if(w <= 0 || w >= SZ_LONG) {
			w = SZ_LONG;
			break;
		}
		w = 1;		/* little endian no adjustment */
		break;

	case Aarg2:	/* width of a parameter */
		o += t->width;
		w = t->width;
		if(w > SZ_LONG)
			w = SZ_LONG;
		break;

	case Aaut3:	/* total align of automatic */
		o = align(o, t, Ael1, nil);
		o = align(o, t, Ael2, nil);
		break;
	}
	if(packw != 0 && xround(o, w) != xround(o, packw))
		diag(Z, "#pragma pack changes offset of %T", t);
	o = xround(o, w);
	if(maxalign && *maxalign < w)
		*maxalign = w;
	if(debug['A'])
		print("align %s %d %T = %d\n", bnames[op], i, t, o);
	return o;
}
Exemplo n.º 12
0
QImage makeImageFromCData (const octave_value& v, int width, int height)
{
  dim_vector dv (v.dims ());

  if (dv.length () == 3 && dv(2) == 3)
    {
      int w = qMin (dv(1), width);
      int h = qMin (dv(0), height);

      int x_off = (w < width ? (width - w) / 2 : 0);
      int y_off = (h < height ? (height - h) / 2 : 0);

      QImage img (width, height, QImage::Format_ARGB32);
      img.fill (qRgba (0, 0, 0, 0));

      if (v.is_uint8_type ())
	{
	  uint8NDArray d = v.uint8_array_value ();

	  for (int i = 0; i < w; i++)
	    for (int j = 0; j < h; j++)
	      {
		int r = d(j, i, 0);
		int g = d(j, i, 1);
		int b = d(j, i, 2);
		int a = 255;

		img.setPixel (x_off + i, y_off + j, qRgba (r, g, b, a));
	      }
	}
      else if (v.is_single_type ())
	{
	  FloatNDArray f = v.float_array_value ();

	  for (int i = 0; i < w; i++)
	    for (int j = 0; j < h; j++)
	      {
		float r = f(j, i, 0);
		float g = f(j, i, 1);
		float b = f(j, i, 2);
		int a = (xisnan (r) || xisnan (g) || xisnan (b) ? 0 : 255);

		img.setPixel (x_off + i, y_off + j,
			      qRgba (xround (r * 255),
				     xround (g * 255),
				     xround (b * 255),
				     a));
	      }
	}
      else if (v.is_real_type ())
	{
	  NDArray d = v.array_value ();

	  for (int i = 0; i < w; i++)
	    for (int j = 0; j < h; j++)
	      {
		double r = d(j, i, 0);
		double g = d(j, i, 1);
		double b = d(j, i, 2);
		int a = (xisnan (r) || xisnan (g) || xisnan (b) ? 0 : 255);

		img.setPixel (x_off + i, y_off + j,
			      qRgba (xround (r * 255),
				     xround (g * 255),
				     xround (b * 255),
				     a));
	      }
	}

      return img;
    }

  return QImage ();
}