Exemplo n.º 1
0
static struct ImBuf *make_sep_waveform_view_from_ibuf_float(
	struct ImBuf * ibuf)
{
	struct ImBuf * rval = IMB_allocImBuf(
		ibuf->x + 3, 515, 32, IB_rect);
	int x,y;
	float* src = ibuf->rect_float;
	unsigned char* tgt = (unsigned char*) rval->rect;
	int w = ibuf->x + 3;
	int sw = ibuf->x/3;
	int h = 515;
	float waveform_gamma = 0.2;
	unsigned char wtable[256];

	wform_put_grid(tgt, w, h);

	for (x = 0; x < 256; x++) {
		wtable[x] = (unsigned char) (pow(((float) x + 1)/256, 
						 waveform_gamma)*255);
	}

	for (y = 0; y < ibuf->y; y++) {
		unsigned char *last_p[3] = {NULL, NULL, NULL};

		for (x = 0; x < ibuf->x; x++) {
			int c;
			float * rgb = src + 4 * (ibuf->x * y + x);
			for (c = 0; c < 3; c++) {
				unsigned char * p = tgt;
				float v = rgb[c];

				CLAMP(v, 0.0f, 1.0f);

				p += 4 * (w * ((int) (v * (h - 3)) + 1)
					  + c * sw + x/3 + 1);

				scope_put_pixel_single(wtable, p, c);
				p += 4 * w;
				scope_put_pixel_single(wtable, p, c);

				if (last_p[c] != NULL) {
					wform_put_line_single(
						w, last_p[c], p, c);
				}
				last_p[c] = p;
			}
		}
	}

	wform_put_border(tgt, w, h);
	
	return rval;
}
Exemplo n.º 2
0
static struct ImBuf *make_waveform_view_from_ibuf_float(struct ImBuf * ibuf)
{
	struct ImBuf * rval = IMB_allocImBuf(ibuf->x + 3, 515, 32, IB_rect);
	int x,y;
	float* src = ibuf->rect_float;
	unsigned char* tgt = (unsigned char*) rval->rect;
	int w = ibuf->x + 3;
	int h = 515;
	float waveform_gamma = 0.2;
	unsigned char wtable[256];

	wform_put_grid(tgt, w, h);

	for (x = 0; x < 256; x++) {
		wtable[x] = (unsigned char) (pow(((float) x + 1)/256, 
						 waveform_gamma)*255);
	}

	for (y = 0; y < ibuf->y; y++) {
		unsigned char * last_p = NULL;

		for (x = 0; x < ibuf->x; x++) {
			float * rgb = src + 4 * (ibuf->x * y + x);
			float v = 1.0f *
				(  0.299f*rgb[0]
				 + 0.587f*rgb[1]
				 + 0.114f*rgb[2]);
			unsigned char * p = tgt;

			CLAMP(v, 0.0f, 1.0f);

			p += 4 * (w * ((int) (v * (h - 3)) + 1) + x + 1);

			scope_put_pixel(wtable, p);
			p += 4 * w;
			scope_put_pixel(wtable, p);

			if (last_p != NULL) {
				wform_put_line(w, last_p, p);
			}
			last_p = p;
		}
	}

	wform_put_border(tgt, w, h);
	
	return rval;
}
Exemplo n.º 3
0
static struct ImBuf *make_histogram_view_from_ibuf_byte(
	struct ImBuf * ibuf)
{
	struct ImBuf * rval = IMB_allocImBuf(515, 128, 32, IB_rect);
	int c,x,y;
	unsigned int n;
	unsigned char* src = (unsigned char*) ibuf->rect;

	unsigned int bins[3][256];

	memset(bins, 0, 3 * 256* sizeof(unsigned int));

	for (y = 0; y < ibuf->y; y++) {
		for (x = 0; x < ibuf->x; x++) {
			bins[0][*src++]++;
			bins[1][*src++]++;
			bins[2][*src++]++;
			src++;
		}
	}

	n = 0;
	for (c = 0; c < 3; c++) {
		for (x = 0; x < 256; x++) {
			if (bins[c][x] > n) {
				n = bins[c][x];
			}
		}
	}

	for (c = 0; c < 3; c++) {
		for (x = 0; x < 256; x++) {
			draw_histogram_bar(rval, x*2+1, 
					   ((float) bins[c][x])/n, c);
			draw_histogram_bar(rval, x*2+2, 
					   ((float) bins[c][x])/n, c);
		}
	}

	wform_put_border((unsigned char*) rval->rect, rval->x, rval->y);
	
	return rval;
}
Exemplo n.º 4
0
static ImBuf *make_waveform_view_from_ibuf_byte(ImBuf *ibuf)
{
	ImBuf *rval = IMB_allocImBuf(ibuf->x + 3, 515, 32, IB_rect);
	int x, y;
	unsigned char *src = (unsigned char *) ibuf->rect;
	unsigned char *tgt = (unsigned char *) rval->rect;
	int w = ibuf->x + 3;
	int h = 515;
	float waveform_gamma = 0.2;
	unsigned char wtable[256];

	wform_put_grid(tgt, w, h);

	for (x = 0; x < 256; x++) {
		wtable[x] = (unsigned char) (pow(((float) x + 1) / 256,
		                                 waveform_gamma) * 255);
	}

	for (y = 0; y < ibuf->y; y++) {
		unsigned char *last_p = NULL;

		for (x = 0; x < ibuf->x; x++) {
			unsigned char *rgb = src + 4 * (ibuf->x * y + x);
			float v = (float)rgb_to_luma_byte(rgb) / 255.0f;
			unsigned char *p = tgt;
			p += 4 * (w * ((int) (v * (h - 3)) + 1) + x + 1);

			scope_put_pixel(wtable, p);
			p += 4 * w;
			scope_put_pixel(wtable, p);

			if (last_p != NULL) {
				wform_put_line(w, last_p, p);
			}
			last_p = p;
		}
	}

	wform_put_border(tgt, w, h);
	
	return rval;
}
Exemplo n.º 5
0
static struct ImBuf *make_histogram_view_from_ibuf_float(
	struct ImBuf * ibuf)
{
	struct ImBuf * rval = IMB_allocImBuf(515, 128, 32, IB_rect);
	int n,c,x,y;
	float* src = ibuf->rect_float;

	unsigned int bins[3][512];

	memset(bins, 0, 3 * 256* sizeof(unsigned int));

	for (y = 0; y < ibuf->y; y++) {
		for (x = 0; x < ibuf->x; x++) {
			bins[0][get_bin_float(*src++)]++;
			bins[1][get_bin_float(*src++)]++;
			bins[2][get_bin_float(*src++)]++;
			src++;
		}
	}

	draw_histogram_marker(rval, get_bin_float(0.0));
	draw_histogram_marker(rval, get_bin_float(1.0));

	n = 0;
	for (c = 0; c < 3; c++) {
		for (x = 0; x < 512; x++) {
			if (bins[c][x] > n) {
				n = bins[c][x];
			}
		}
	}
	for (c = 0; c < 3; c++) {
		for (x = 0; x < 512; x++) {
			draw_histogram_bar(rval, x+1, (float) bins[c][x]/n, c);
		}
	}

	wform_put_border((unsigned char*) rval->rect, rval->x, rval->y);
	
	return rval;
}
static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf)
{
	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
	int nr, ng, nb, x, y;
	const float *src = ibuf->rect_float;

	unsigned int bins[3][HIS_STEPS];

	memset(bins, 0, sizeof(bins));

#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256)
	for (y = 0; y < ibuf->y; y++) {
		unsigned int cur_bins[3][HIS_STEPS];

		memset(cur_bins, 0, sizeof(cur_bins));

		for (x = 0; x < ibuf->x; x++) {
			const float *pixel = src + (y * ibuf->x + x) * 4;

			cur_bins[0][get_bin_float(pixel[0])]++;
			cur_bins[1][get_bin_float(pixel[1])]++;
			cur_bins[2][get_bin_float(pixel[2])]++;
		}

#pragma omp critical
		{
			int i;
			for (i = 0; i < HIS_STEPS; i++) {
				bins[0][i] += cur_bins[0][i];
				bins[1][i] += cur_bins[1][i];
				bins[2][i] += cur_bins[2][i];
			}
		}
	}

	nr = nb = ng = 0;
	for (x = 0; x < HIS_STEPS; x++) {
		if (bins[0][x] > nr)
			nr = bins[0][x];
		if (bins[1][x] > ng)
			ng = bins[1][x];
		if (bins[2][x] > nb)
			nb = bins[2][x];
	}
	
	for (x = 0; x < HIS_STEPS; x++) {
		if (nr) {
			draw_histogram_bar(rval, x + 1, ((float) bins[0][x]) / nr, 0);
		}
		if (ng) {
			draw_histogram_bar(rval, x + 1, ((float) bins[1][x]) / ng, 1);
		}
		if (nb) {
			draw_histogram_bar(rval, x + 1, ((float) bins[2][x]) / nb, 2);
		}
	}
	
	draw_histogram_marker(rval, get_bin_float(0.0));
	draw_histogram_marker(rval, get_bin_float(1.0));
	wform_put_border((unsigned char *) rval->rect, rval->x, rval->y);
	
	return rval;
}