Beispiel #1
0
int pnm_set_imagetype(pnm_img* img, int p){
	int oc, nc;
	nc = num_channels(p);
	if (nc == -1)
		return -1;
	oc = num_channels(img->p);

	if (img->p == p)
		return 0;
	
	if (nc == oc){ /* same colour depth, fileformat difference */
		img->p = p;
		return 0;
	}
	else{
		if(oc == 3){
			pnm_to_grayscale(img);
		}
		else{
			pnm_to_rgb(img);
		}
	}
	img->p = p;
	return 0;
}
Beispiel #2
0
bool desc::ac3_audio(dvbpsi_descriptor_t* p_descriptor)
{
#if DVBPSI_SUPPORTS_DR_81_86_A0_A1
	if (p_descriptor->i_tag != DT_Ac3Audio)
		return false;

	dvbpsi_ac3_audio_dr_t* dr = dvbpsi_DecodeAc3AudioDr(p_descriptor);
	if (desc_dr_failed(dr)) return false;

	dPrintf("sample rate: %s", sample_rate(dr->i_sample_rate_code));
	dPrintf("bsid: %02x", dr->i_bsid);
	dPrintf("bit rate code: %02x", dr->i_bit_rate_code);
	dPrintf("surround mode: %s", surround_mode(dr->i_surround_mode));
	dPrintf("bsmod: %02x", dr->i_bsmod);
	dPrintf("num channels: %s", num_channels(dr->i_num_channels));
	dPrintf("full svc: %s", (dr->b_full_svc) ? "true" : "false");
	dPrintf("description: %s", dr->text);
	if (dr->b_language_flag)
		dPrintf("language: %c%c%c",
			dr->language[0],
			dr->language[1],
			dr->language[2]);
	if (dr->b_language_flag_2)
		dPrintf("language_2: %c%c%c",
			dr->language_2[0],
			dr->language_2[1],
			dr->language_2[2]);
#endif
	return true;
}
Beispiel #3
0
static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx,
                                  grpc_server *server) {
  size_t i;
  if (!gpr_atm_acq_load(&server->shutdown_flag) || server->shutdown_published) {
    return;
  }

  kill_pending_work_locked(exec_ctx, server,
                           GRPC_ERROR_CREATE("Server Shutdown"));

  if (server->root_channel_data.next != &server->root_channel_data ||
      server->listeners_destroyed < num_listeners(server)) {
    if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
                                  server->last_shutdown_message_time),
                     gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
      server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
      gpr_log(GPR_DEBUG,
              "Waiting for %d channels and %d/%d listeners to be destroyed"
              " before shutting down server",
              num_channels(server),
              num_listeners(server) - server->listeners_destroyed,
              num_listeners(server));
    }
    return;
  }
  server->shutdown_published = 1;
  for (i = 0; i < server->num_shutdown_tags; i++) {
    server_ref(server);
    grpc_cq_end_op(exec_ctx, server->shutdown_tags[i].cq,
                   server->shutdown_tags[i].tag, GRPC_ERROR_NONE,
                   done_shutdown_event, server,
                   &server->shutdown_tags[i].completion);
  }
}
Beispiel #4
0
void pnm_set_pixel(pnm_img *img, int x, int y, void* pixel) {
	void* p =pnm_get_pixel(img, x,y);
	if (num_channels(img->p) == 1)
		*((char*)p) = *((char*)pixel);
	else
		*((pnm_pixmap*)p) = *((pnm_pixmap*)pixel);
}
Beispiel #5
0
int main(int argc, char** argv)
{
	if(argc <= 1)
	{
		tl::log_err("Usage: ", argv[0], " <image>");
		return -1;
	}

	std::string strImg = argv[1];

	auto pimg = tl::load_image<gil::gray16_pixel_t, false>(strImg.c_str());
	if(!pimg)
		return -1;

	auto view = gil::view(*pimg);

	std::size_t iChan = view.num_channels();
	std::size_t iW = view.width();
	std::size_t iH = view.height();
	std::cout << iW << " x " << iH << ", " << iChan << " channels." << std::endl;

	//const auto iterRow = view.row_begin(908);
	//for(unsigned int iX=0; iX<iW; ++iX)
	//	std::cout << iterRow[iX] << " ";

	unsigned long lBkg = tl::get_roi_avg(view, 0, 500, 0, 300);
	std::cout << "Background counts: " << lBkg << std::endl;

	unsigned long lInt = tl::get_roi_sum(view, 310, 365, 880, 940, lBkg);
	std::cout << "Integrated counts: " << lInt << std::endl;

	return 0;
}
Beispiel #6
0
bool
test_exact()
{
	int i, Bpp, channels;
	float *tmp_float;
	GLubyte *data, *observed;
	GLint tex_width, tex_height;
	bool pass = true;

	if (format->data_type == GL_NONE) {
		piglit_report_subtest_result(PIGLIT_SKIP,
					     "Exact upload-download of %s",
					     piglit_get_gl_enum_name(format->internal_format));
		return true;
	}

	channels = num_channels(format->format);
	Bpp = bytes_per_pixel(format->format, format->data_type);

	if (format->data_type == GL_FLOAT) {
		/* Sanatize so we don't get invalid floating point values */
		tmp_float = malloc(texture_size * texture_size *
				   channels * sizeof(float));
		for (i = 0; i < texture_size * texture_size * channels; ++i)
			tmp_float[i] = sn_to_float(32, ((GLint *)rand_data)[i]);
		data = (GLubyte *)tmp_float;
	} else {
		tmp_float = NULL;
		data = rand_data;
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format,
		     texture_size, texture_size, 0, format->format,
		     format->data_type, data);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex_width);
	glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex_height);
	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	observed = malloc(tex_width * tex_height * Bpp);

	glGetTexImage(GL_TEXTURE_2D, 0, format->format, format->data_type,
		      observed);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	for (i = 0; i < texture_size; ++i)
		pass &= memcmp(&data[i * texture_size * Bpp],
			       &observed[i * tex_width * Bpp],
			       texture_size * Bpp) == 0;

	free(observed);
	free(tmp_float);

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "Exact upload-download of %s",
				     piglit_get_gl_enum_name(format->internal_format));

	return pass;
}
Beispiel #7
0
pnm_img *pnm_create(int width, int height, int p) {
	pnm_img *img = (pnm_img*) malloc(sizeof(pnm_img));
	img->width = width;
	img->height = height;
	img->max_color = 255;
	img->p = p;
	img->pixels= calloc(height*width* num_channels(p),sizeof(char));
	return img;
}
Beispiel #8
0
static void pnm_to_grayscale(pnm_img *img){
	if (num_channels(img->p)==1){
		printf("pnm_to_grayscale: already a greyscale image!\n");
		return;
	}
	pnm_pixmap* p = (pnm_pixmap*)img->pixels;
	unsigned char* g = (unsigned char*)img->pixels;
	int n_pixels = img->width*img->height;
	for(int i=0; i<n_pixels;i++,p++,g++)
		*g = (p->R + p->G + p->B)/3;
	img->pixels = realloc(img->pixels, sizeof(char)*n_pixels);
}
Beispiel #9
0
void pnm_write(pnm_img *img, const char file_name[]) {
	int linewidth = 0;
	FILE* fp;
	fp = fopen(file_name, "w");

	if(img->p >1 && img->p <4){
		fprintf(fp, "P%d\n%d %d\n%d\n", 
			img->p,img->width, img->height, img->max_color);
		if(num_channels(img->p) == 3){
			pnm_pixmap* pm = (pnm_pixmap*)img->pixels;
			for(int i = 0; i<img->height*img->width; i++) {
				linewidth += 3*3+3+1;
				fprintf(fp, "%i %i %i  %s", 
					(int)(pm[i].R),
					(int)(pm[i].G),
					(int)(pm[i].B),
					linewidth >= 72?"\n":"");
					if (linewidth >= 72)
						linewidth = 0;
			}
		}
		else {
			unsigned char* p = (unsigned char*)img->pixels;
			for(int i = 0; i<img->height*img->width; i++) {
				linewidth += 3+2;
				fprintf(fp, "%i  %s", 
					(int)p[i], linewidth >= 72?"\n":"");
					if (linewidth >= 72)
					linewidth = 0;
			}
		}
	}
	else if (img->p>4){
		fprintf(fp, "P%d\n%d %d\n%d\n", 
				img->p,img->width, img->height, img->max_color);
		fwrite(img->pixels, sizeof(unsigned char)*num_channels(img->p),
				img->height * img->width, fp);
	}
	fclose(fp);
}
Beispiel #10
0
pBuffer SourceBase::
        zeros( const Interval& I )
{
    EXCEPTION_ASSERT( I.count() );

    TIME_SOURCEBASE TaskTimer tt("%s.%s %s",
                  vartype(*this).c_str(), __FUNCTION__ ,
                  I.toString().c_str() );

    pBuffer r( new Buffer(I, sample_rate(), num_channels()) );
    // doesn't need to memset 0, will be set by the first initialization of a dataset
    //memset(r->waveform_data()->getCpuMemory(), 0, r->waveform_data()->getSizeInBytes1D());
    return r;
}
Beispiel #11
0
static void pnm_to_rgb(pnm_img *img) {
	if (num_channels(img->p)==3){
		printf("pnm_to_rgb: already an rgb image!\n");
		return;
	}
	int n_pixels = img->height*img->width;
	pnm_pixmap* pm = (pnm_pixmap*)malloc(sizeof(pnm_pixmap)*n_pixels);
	pnm_pixmap pv = {0,0,0};
	for(int i=0; i<n_pixels; i++){
		pv.R = pv.G = pv.B = *((unsigned char*)img->pixels+i);
		*(pm+i) = pv;
	}
	free(img->pixels);
	img->pixels = pm;
}
Beispiel #12
0
static int
bytes_per_pixel(GLenum format, GLenum type)
{
	int channels = num_channels(format);

	switch (type) {
	case GL_UNSIGNED_BYTE_3_3_2:
	case GL_UNSIGNED_BYTE_2_3_3_REV:
		assert(channels == 3);
		return 1;
	case GL_UNSIGNED_SHORT_5_6_5:
	case GL_UNSIGNED_SHORT_5_6_5_REV:
		assert(channels == 3);
		return 2;
	case GL_UNSIGNED_SHORT_4_4_4_4:
	case GL_UNSIGNED_SHORT_4_4_4_4_REV:
	case GL_UNSIGNED_SHORT_5_5_5_1:
	case GL_UNSIGNED_SHORT_1_5_5_5_REV:
		assert(channels == 4);
		return 2;
	case GL_UNSIGNED_INT_10_10_10_2:
	case GL_UNSIGNED_INT_2_10_10_10_REV:
	case GL_UNSIGNED_INT_8_8_8_8:
	case GL_UNSIGNED_INT_8_8_8_8_REV:
		assert(channels == 4);
		return 4;
	case GL_BYTE:
	case GL_UNSIGNED_BYTE:
		return channels;
	case GL_SHORT:
	case GL_UNSIGNED_SHORT:
		return channels * 2;
	case GL_FLOAT:
	case GL_INT:
	case GL_UNSIGNED_INT:
		return channels * 4;
	default:
		assert(!"Invalid type");
		return 0;
	}
}
Beispiel #13
0
void boost_parse_image(std::string filename, size_t& width, size_t& height, size_t& channels, Format& format, size_t& image_data_size, std::string format_string) {

  typedef boost::mpl::vector<gray8_image_t, gray16_image_t, rgb8_image_t, rgb16_image_t> my_img_types;

  any_image<my_img_types> src_image;

  if (format_string == "JPG"){
    jpeg_read_image(filename, src_image);
    format = Format::JPG;
  } else if (format_string == "PNG"){
    png_read_image(filename, src_image);
    format = Format::PNG;
  } else{
    if (boost::algorithm::ends_with(filename, "jpg") ||
      boost::algorithm::ends_with(filename, "jpeg")) {
      jpeg_read_image(filename, src_image);
      format = Format::JPG;
    } else if (boost::algorithm::ends_with(filename, "png")){
      png_read_image(filename, src_image);
      format = Format::PNG;
    } else {
      log_and_throw(std::string("Unsupported format."));
    }
  }

  // create a view of the image
  auto src_view = const_view(src_image);

  // extract image information
  width = src_view.width();
  height = src_view.height();
  channels = src_view.num_channels();
  image_data_size = width*height*channels;

  // Debug
  // std::cout << "Read image "<< filename << "\n"
  // << "width: " << width << "\n"
  // << "height: " << height << "\n"
  // << "num_channels " << channels << "\n"
  // << std::endl;
}
Beispiel #14
0
pnm_img *pnm_read(const char file_name[]){
	FILE* fp;
	int status;
	int p;
	char buffer[MAX_LINE_SIZE];

	// open file
	fp = fopen(file_name,"r"); 
	if(fp == NULL) {
		path_error(file_name);
		return NULL;
	}
	
	// get PPM type	
	read_line(buffer,MAX_LINE_SIZE,fp);
	if(buffer[0] != 'P') {
		printf("Bad header format\n");
		return NULL;
	}
	p = atoi(buffer+1);
	// read past any comments
	do {
		read_line(buffer,MAX_LINE_SIZE,fp);
	} while(buffer[0] == '#');

	// get dimensions 
	char* current_position;
	int width = strtol(buffer,&current_position,10);
	if (*current_position == '\n'){
		read_line(buffer,MAX_LINE_SIZE,fp);
		current_position = buffer;
	}
	int height = strtol(current_position,&current_position,10);

	pnm_img* img = pnm_create(width, height, p);

	if (*current_position == '\n'){
		read_line(buffer,MAX_LINE_SIZE,fp);
		current_position = buffer;
	}
	img->max_color = strtol(current_position,&current_position,10);

	// extract pixel data
	if(p == 5 || p == 6){
		fread(img->pixels, sizeof(char),height*width*num_channels(p),fp);
	}
	else{
		int R, G, B;
		if (num_channels(p) == 3){
			pnm_pixmap* pm = (pnm_pixmap*)img->pixels;
			for(int i = 0; i< height*width; i++){
				status = fscanf(fp," %i %i %i", &R, &G, &B);
				if(status == EOF) {
					printf("Bad file format\n");
					return NULL;		
				}
				pm[i].R = (unsigned char)R;
				pm[i].G = (unsigned char)G;
				pm[i].B = (unsigned char)B;
			}
		}
		else{
			int grey;
			for(int i = 0; i< height*width; i++){
				status = fscanf(fp," %i", &grey);
				if(status == EOF) {
					printf("Bad file format\n");
					return NULL;		
				}
				*((unsigned char*)img->pixels+i) = (unsigned char)grey;
			}
		}
	}
	fclose(fp); 
	return img;
}
Beispiel #15
0
void
to_expected(GLenum test_format, GLenum test_type, void *up_raw, float *expected)
{
	float up_rgba[4];
	int num_chan = num_channels(test_format);

	to_float(up_raw, num_chan, test_type, up_rgba);

	expected[0] = 0.0f;
	expected[1] = 0.0f;
	expected[2] = 0.0f;
	expected[3] = 1.0f;

	switch (test_format) {
	case GL_RED:
		expected[0] = up_rgba[0];
		break;
	case GL_GREEN:
		expected[1] = up_rgba[0];
		break;
	case GL_BLUE:
		expected[2] = up_rgba[0];
		break;
	case GL_ALPHA:
		expected[3] = up_rgba[0];
		break;
	case GL_RG:
		expected[0] = up_rgba[0];
		expected[1] = up_rgba[1];
		break;
	case GL_RGBA:
		expected[3] = up_rgba[3];
	case GL_RGB:
		expected[0] = up_rgba[0];
		expected[1] = up_rgba[1];
		expected[2] = up_rgba[2];
		break;
	case GL_BGRA:
		expected[3] = up_rgba[3];
	case GL_BGR:
		expected[0] = up_rgba[2];
		expected[1] = up_rgba[1];
		expected[2] = up_rgba[0];
		break;
	case GL_ABGR_EXT:
		expected[0] = up_rgba[3];
		expected[1] = up_rgba[2];
		expected[2] = up_rgba[1];
		expected[3] = up_rgba[0];
		break;
	case GL_INTENSITY:
		expected[0] = up_rgba[0];
		expected[1] = up_rgba[0];
		expected[2] = up_rgba[0];
		expected[3] = up_rgba[0];
		break;
	case GL_LUMINANCE_ALPHA:
		expected[3] = up_rgba[1];
	case GL_LUMINANCE:
		expected[0] = up_rgba[0];
		expected[1] = up_rgba[0];
		expected[2] = up_rgba[0];
		break;
	default:
		assert(!"Invalid color format");
	}

	switch (format->format) {
	case GL_RED:
	case GL_RED_INTEGER:
		expected[1] = 0.0f;
	case GL_RG:
	case GL_RG_INTEGER:
		expected[2] = 0.0f;
	case GL_RGB:
	case GL_RGB_INTEGER:
		expected[3] = 1.0f;
		break;
	case GL_RGBA:
	case GL_RGBA_INTEGER:
		break;
	case GL_ALPHA:
		expected[0] = 0.0f;
		expected[1] = 0.0f;
		expected[2] = 0.0f;
		break;
	case GL_LUMINANCE:
		expected[3] = 1.0f;
	case GL_LUMINANCE_ALPHA:
		expected[0] = expected[0];
		expected[1] = expected[0];
		expected[2] = expected[0];
		break;
	default:
		assert(!"Invalid color format");
	}

	if (!is_format_signed(format->internal_format)) {
		if (expected[0] < 0.0f)
			expected[0] = 0.0f;
		if (expected[1] < 0.0f)
			expected[1] = 0.0f;
		if (expected[2] < 0.0f)
			expected[2] = 0.0f;
		if (expected[3] < 0.0f)
			expected[3] = 0.0f;
	}

	if (is_format_srgb(format->internal_format)) {
		expected[0] = srgb_to_linear(expected[0]);
		expected[1] = srgb_to_linear(expected[1]);
		expected[2] = srgb_to_linear(expected[2]);
	}
}
Beispiel #16
0
void* pnm_get_pixel(pnm_img* img, int x, int y){
    return ((char*)img->pixels)+(y*img->width+x)*num_channels(img->p);
}
Beispiel #17
0
enum piglit_result
run_test(GLenum test_format, GLenum test_type, float *time_out)
{
	bool pass = true;
	int64_t time;
	GLuint tex;
	int i, Bpp, channels;
	float *tmp, *expected, *observed;
	void *data;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	channels = num_channels(test_format);
	Bpp = bytes_per_pixel(test_format, test_type);

	if (test_type == GL_FLOAT) {
		/* Sanatize so we don't get invalid floating point values */
		tmp = malloc(texture_size * texture_size * channels * sizeof(float));
		for (i = 0; i < texture_size * texture_size * channels; ++i)
			tmp[i] = sn_to_float(32, ((GLint *)rand_data)[i]);
		data = tmp;
	} else {
		tmp = NULL;
		data = rand_data;
	}

	expected = malloc(texture_size * texture_size * 4 * sizeof(float));
	for (i = 0; i < texture_size * texture_size; ++i)
		to_expected(test_format, test_type, (GLubyte *)data + (i * Bpp),
			    expected + 4 * i);

	if (benchmark) {
		time = piglit_get_microseconds();
		for (i = 0; i < BENCHMARK_ITERATIONS; ++i)
			glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format,
				     texture_size, texture_size, 0,
				     test_format, test_type, data);
		time = piglit_get_microseconds() - time;
		*time_out = (double)time / (double)BENCHMARK_ITERATIONS;
	} else {
		glTexImage2D(GL_TEXTURE_2D, 0, format->internal_format,
			     texture_size, texture_size, 0,
			     test_format, test_type, data);
	}
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	if (is_format_signed(format->internal_format)) {
		glUseProgram(signed_prog);

		for (i = 0; i < texture_size * texture_size * 4; ++i)
			expected[i] = 0.5 + 0.5 * expected[i];
	} else {
		glUseProgram(unsigned_prog);
	}

	piglit_draw_rect_tex(0, 0, texture_size, texture_size, 0, 0, 1, 1);

	observed = malloc(texture_size * texture_size * 4 * sizeof(float));
	glReadPixels(0, 0, texture_size, texture_size,
		     GL_RGBA, GL_FLOAT, observed);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	pass &= piglit_compare_images_color(0, 0, texture_size, texture_size, 4,
					    tolerance, expected, observed);

	free(observed);
	free(expected);
	free(tmp);

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "%s texture with %s and %s",
				     piglit_get_gl_enum_name(format->internal_format),
				     piglit_get_gl_enum_name(test_format),
				     piglit_get_gl_enum_name(test_type));

	glDeleteTextures(1, &tex);

	return pass;
}