Пример #1
0
int main(int argc, char **argv)
{
    bmpfile_t *bmp;
    int i, j;
    char* infilename;
    FILE* infile;
    char* outfile;
    int width;
    int height;
    int depth;
    unsigned char red, green, blue; // 8-bits each
    //unsigned char pixel[3]; // 24-bits per pixel

    if (argc < 6) {
        printf("Usage: %s infile width height depth outfile.\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    infilename = argv[1];
    outfile = argv[5];

    infile = fopen(infilename, "rb");
    if (NULL == infile) {
        perror("Couldn't read infile");
        exit(EXIT_FAILURE);
    }

    width = atoi(argv[2]);
    height = atoi(argv[3]);
    depth = atoi(argv[4]);

    // should be depth/8 at 16-bit depth, but 32-bit depth works better
    char buffer[height * width * 3];
    printf("depth: %d\n", depth);
    if (fread(&buffer, 1, height * width * 3, infile) != height * width * 3) {
        fputs("infile dimensions don't match the size you supplied\n", stderr);
    }

    if ((bmp = bmp_create(width, height, depth)) == NULL) {
        printf("Invalid depth value: '%d'. Try 1, 4, 8, 16, 24, or 32.\n", depth);
        exit(EXIT_FAILURE);
    }

    for (i = 0; i < width; ++i) {
        for (j = 0; j < height; ++j) {

            red     = buffer[(width * j + i) * 3 + 0];
            green   = buffer[(width * j + i) * 3 + 1];
            blue    = buffer[(width * j + i) * 3 + 2];

            rgb_pixel_t bpixel = {blue, green, red, 0};
            bmp_set_pixel(bmp, i, j, bpixel);
        }
    }

    bmp_save(bmp, outfile);
    bmp_destroy(bmp);

    return 0;
}
Пример #2
0
int main (int argc, char **argv)
{
	if (argc < 2)
	{
		printf ("Usage : %s <binary> [output folder]\n", argv[0]);
		return 1;
	}

	FILE *bin = fopen (argv[1], "rb");
	if (!bin)
	{
		printf ("File %s cannot be opened.\n", argv[1]);
		return 2;
	}
	
	char *output_folder = (argc >= 3) ? argv[2] : "./";

	// LookUp table initialization
	sqrt_table = lookup_table_new (-0.1, (256 * 256) * 2, 0.1, sqrt);

	// Binary file related
	BinaryData binary = {
		.name = get_filename (argv[1]),
		.path = remove_ext (get_filename (argv[1])),
		.size = get_filesize (bin),
		.bmp  = bmp_create (256, 256, 8),
		.distance_curve = bmp_create (CURVE_WIDTH, CURVE_HEIGHT, 8),
		.intensity = bmp_create (256, 256, 8),
		.handler = bin,
		.frame = frame_new (256),
		.output_folder = output_folder
	};

	// Prepare folders
	char tmp[1024];
	_mkdir (binary.output_folder);
	sprintf(tmp, "%s/%s", binary.output_folder, binary.path);
	_mkdir (tmp);
	sprintf(tmp, "%s/curves", binary.output_folder);
	_mkdir (tmp);


	// Analyze
	analyze_2d (&binary);

	return 0;
}
Пример #3
0
int main(void) 
{
    struct bmp_t *bmp;
    printf("Pressure Sensor Test\n");
          
    /* Initialise the sensor */
    if(!bmp_create(&bmp,123)) {
        printf("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!\n");
        return -1;
    }
            
    /* Display some basic information on this sensor */
    displaySensorDetails(bmp);
    
    for (;;) {
        /* Get a new sensor event */ 
        sensors_event_t event;
        bmp_getEvent(bmp, &event);
         
        /* Display the results (barometric pressure is measure in hPa) */
        if (event.pressure){
            /* Display atmospheric pressue in hPa */
            printf("Pressure:  %f hPa\n", event.pressure);
                                    
            /* Calculating altitude with reasonable accuracy requires pressure    *
             * sea level pressure for your position at the moment the data is     *
             * converted, as well as the ambient temperature in degress           *
             * celcius.  If you don't have these values, a 'generic' value of     *
             * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA   *
             * in sensors.h), but this isn't ideal and will give variable         *
             * results from one day to the next.                                  *
             *
             * You can usually find the current SLP value by looking at weather   *
             * websites or from environmental information centers near any major  *
             * airport.                                                           *
             *
             * For example, for Paris, France you can check the current mean      *
             * pressure and sea level at: http://bit.ly/16Au8ol                   */
                                                 
            /* First we get the current temperature from the BMP085 */
            float temperature;
            bmp_getTemperature(bmp, &temperature);
            printf("Temperature: %f C\n",temperature);
            
            /* Then convert the atmospheric pressure, and SLP to altitude         */
            /* Update this next line with the current SLP for better results      */
            float seaLevelPressure = 1024.7f;
            printf("Altitude: %f m\n", bmp_pressureToAltitude(seaLevelPressure,event.pressure));
        }
        else {
            printf("Sensor error\n");
        }
        sleep(1);
    }
}
Пример #4
0
BMP *bmp_copy(BMP *image)
{
    int i,j;
    BMP *copy;

    copy = bmp_create(image->width, image->height);
    for(i=0; i < image->height;i++)
        for(j=0;j< image->width;j++)
            copy->data[i][j] = image->data[i][j];

    return copy;
}
Пример #5
0
static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
{	
	union content_msg_data msg_data;
	bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
		.bitmap_create = nsbmp_bitmap_create,
		.bitmap_destroy = guit->bitmap->destroy,
		.bitmap_get_buffer = guit->bitmap->get_buffer,
		.bitmap_get_bpp = guit->bitmap->get_bpp
	};

	bmp->bmp = calloc(sizeof(struct bmp_image), 1);
	if (bmp->bmp == NULL) {
		msg_data.error = messages_get("NoMemory");
		content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data);
		return NSERROR_NOMEM;
	}

	bmp_create(bmp->bmp, &bmp_bitmap_callbacks);

	return NSERROR_OK;
}

static nserror nsbmp_create(const content_handler *handler,
		lwc_string *imime_type, const struct http_parameter *params,
		llcache_handle *llcache, const char *fallback_charset,
		bool quirks, struct content **c)
{
	nsbmp_content *bmp;
	nserror error;

	bmp = calloc(1, sizeof(nsbmp_content));
	if (bmp == NULL)
		return NSERROR_NOMEM;

	error = content__init(&bmp->base, handler, imime_type, params,
			llcache, fallback_charset, quirks);
	if (error != NSERROR_OK) {
		free(bmp);
		return error;
	}

	error = nsbmp_create_bmp_data(bmp);
	if (error != NSERROR_OK) {
		free(bmp);
		return error;
	}

	*c = (struct content *) bmp;

	return NSERROR_OK;
}
Пример #6
0
int main(const int argc, const char **argv){
	initstdio();
	if(argc<2){
		fprintf(stderr,
			"codeiq124 in.bmp >out.txt\n"
			"codeiq124 io.bmp <in.txt\n"
		);
		return -1;
	}

	int pixels=0,count=0,color,last;
	if(isatty(fileno(stdin))){ //decode
		struct stat st;
		int x,y;
		FILE *in=fopen(argv[1],"rb");
		if(!in){
			fprintf(stderr,"cannot open %s\n",argv[2]);
			return 1;
		}
		fstat(fileno(in),&st);
		void *imgbuf=malloc(st.st_size);
		fread(imgbuf,1,st.st_size,in);
		fclose(in);

		bmp_image gif;
		bmp_bitmap_callback_vt vt={
			bitmap_create,
			bitmap_destroy,
			bitmap_set_suspendable,
			bitmap_get_buffer,
			bitmap_get_bpp
		};

		bmp_create(&gif,&vt);
		if(bmp_analyse(&gif, st.st_size, imgbuf)||bmp_decode(&gif)){fprintf(stderr,"decode error\n");bmp_finalise(&gif);free(imgbuf);return 1;}
		free(imgbuf);

		for(y=0;y<gif.height;y++){
			for(x=0;x<gif.width;x++){
				u32 coor=y*gif.width+x;
				u8 b=((((u32*)gif.bitmap)[coor]&0xff0000)>>16)&0xff;
				u8 g=((((u32*)gif.bitmap)[coor]&0x00ff00)>>8)&0xff;
				u8 r=((((u32*)gif.bitmap)[coor]&0x0000ff)>>0)&0xff;
				u8 mes=((r&7)<<5)|((g&3)<<3)|((b&7)<<0);
				if(!mes)break;
				putchar(mes);
			}
		}
		bmp_finalise(&gif);
	}else{ //encode
Пример #7
0
Файл: eyed.c Проект: texane/eyed
static void handle_request(cam_dev_t* dev, cio_handle_t* h, const char* l)
{
  cam_err_t err;
  struct capture_ctx capture_ctx;
  const uint8_t* data;
  uint32_t size;
  uint8_t hdr[256];

  capture_ctx.count = 0;
  capture_ctx.bmp = NULL;
  capture_ctx.has_captured = 0;

  if ((capture_ctx.bmp = bmp_create()) == NULL)
    goto on_error;

  err = cam_start_capture(dev,
			  CAM_FORMAT_YUV420_160_120,
			  on_frame,
			  &capture_ctx);

  if (err != CAM_ERR_SUCCESS)
    goto on_error;

  err = cam_wait_capture(dev);

  if (err != CAM_ERR_SUCCESS)
    goto on_error;

  if (!capture_ctx.has_captured)
    goto on_error;

  size = sizeof(hdr);

  if (bmp_get_header(capture_ctx.bmp, hdr, &size) == -1)
    goto on_error;

  if ((data = bmp_get_data(capture_ctx.bmp)) == NULL)
    goto on_error;

  cbuf_push_back(&h->buf_out, (void*)hdr, size);
  cbuf_push_back(&h->buf_out, (void*)data, 160 * 120 * 3);

 on_error:

  if (capture_ctx.bmp != NULL)
    bmp_destroy(capture_ctx.bmp);

  return ;
}
Пример #8
0
void binary_save_bmp (BinaryData *binary, unsigned long int start_offset, unsigned long int cur_offset)
{
	char bmp_filename[1024];
	static unsigned int frame_id = 0;

	sprintf (bmp_filename, "%s/%s/%d_%s_0x%lx-0x%lx.bmp", 
		binary->output_folder, binary->path, frame_id++, binary->name, start_offset, cur_offset);

	// Output to bmp
	bmp_save (binary->bmp, bmp_filename);
	
	// Cleaning
	bmp_destroy (binary->bmp);
	binary->bmp = bmp_create (256, 256, 8);
}
Пример #9
0
BMP *bmp_load(char *filename)
{
    BMP *bmp;
    int x, y, a;
    bmpFHEAD h1;
    bmpIHEAD h2;
    char swp;
    char octet;
    int nb_octet;

    FILE *fp = fopen(filename, "r");
    if(fp==NULL)
        printf("Le fichier ' %s ' n'a pu etre ouvert, verifiez qu'il existe bien dans le chemin spécifié !!!\n",filename);

    //FILEHEADER
    fread(&h1.bfType, sizeof(h1.bfType), 1, fp);
    fread(&h1.bfSize, sizeof(h1.bfSize), 1, fp);
    fread(&h1.bfReserved1, sizeof(h1.bfReserved1), 1, fp);
    fread(&h1.bfReserved2, sizeof(h1.bfReserved2), 1, fp);
    fread(&h1.bfOffBits, sizeof(h1.bfOffBits), 1, fp);

    //INFOHEADER
    fread(&h2, sizeof(h2), 1, fp);
    bmp = bmp_create(h2.biWidth, h2.biHeight);

    //decalage de 8 octect correspondant à la palette d'indexage des couleurs
    for(a=0;a<8;a++)
        fread (&swp, sizeof(char), 1, fp);

    for(y=0; y < bmp->height; y++)
    {
        for(x=0; x < bmp->width; x=x+8)
        {
            fread (&octet, sizeof(octet), 1, fp);
            bmp_setcolor(bmp, x, y, octet);
        }

        //La ligne doit avoir un multiple de 4 octets et est complétée par des 0
        nb_octet = (4 - ( (bmp->width+bmp->width%8) /8 )%4 ) %4;
        for (a=0; a<nb_octet; a++)
            fread (&swp, sizeof(char), 1, fp);
    }

    fclose(fp);
    return bmp;
}
void saveimage(){
    printf("Good hits: %llu\t Miss hits: %llu\t Bad hits: %llu\t %f\n", goodHits, missHits, badHits, (f32)goodHits/(badHits > 0 ? badHits : 1));

    bmpfile_t *bmp;

    f32 amax = __sec_reduce_max(h[0:hwid * hhei].a);
    amax = MAX(amax, 1);



    bmp = bmp_create(hwid, hhei, 24);

    printf("generating image");

    cilk_for(i32 i = 0; i < hwid * hhei; i++){
        const f32 a = log(h[i].a) / log(amax);

        f32 maxColor = MAX3(h[i].r, h[i].g, h[i].b);

        if(maxColor <= 0)
            maxColor = 1;

        const u8 r = (h[i].r / h[i].a) * 0xFF * a;
        const u8 g = (h[i].g / h[i].a) * 0xFF * a;
        const u8 b = (h[i].b / h[i].a) * 0xFF * a;

        const rgb_pixel_t pixel = {b, g, r, 0xFF};
        const u32 x = i % hwid;
        const u32 y = i / hwid;
        bmp_set_pixel(bmp, x, y, pixel);

        // progress bar
        if((i % ((hwid * hhei) / 20)) == 0)
            printf(".");
    }

    printf(" done\n");

    printf("saving image... ");
    bmp_save(bmp, "fractal.bmp");
    bmp_destroy(bmp);
    printf("done\n");
}
Пример #11
0
int main(int argc, char **argv) {

	bmpfile_t *bmp_resized = NULL;
	bmpfile_t *result = NULL;
	int width, height,num_threads, i, j;
	float scale;
	
	// Parse argv.
	scale = (float)atof(argv[2]);
	num_threads = atoi(argv[3]);
	
	omp_set_num_threads(num_threads);
	
	bmp_resized = bmp_scale( argv[1], scale, num_threads);
	width = bmp_get_dib(bmp_resized).width;
	height = bmp_get_dib(bmp_resized).height; 
	
	result = bmp_create(width, height, 8);	
	if( result != NULL){
	
	//printf(" about to make new file!\n");
	//#pragma omp parallel for private(j)
	for (i = 0; i < width; ++i) {
	
      for (j = 0; j < height; ++j) {
		int num = omp_get_thread_num();
		//printf("Thread %i has i = %i and j = %i\n", num, i, j);
		rgb_pixel_t *p = bmp_get_pixel(bmp_resized, i, j);
		bmp_set_pixel(result, i, j, *p);	
	  }

	}
	//printf("made new file!\n");
	bmp_save(result, "bmp_scale.bmp");
	}
	
	//printf("finished saving!\n");
    bmp_destroy(bmp_resized);
    return 0;
	

}
Пример #12
0
void test_bmpCreate(CuTest* tc)
{
	bmpfile_t* bmp;
	int i,j;
	int width = 64, height = 64, depth = 1; 
	bw_pixel_t pixel;
	pixel.uniColour = 128;
	CuAssertTrue(tc,NULL!=(bmp=bmp_create(64,64,1)));
	for (i = 10, j = 10; j < 64; ++i, ++j) {
		bmp_set_pixel(bmp, i, j, pixel);
		pixel.uniColour++;
		bmp_set_pixel(bmp, i + 1, j, pixel);
		bmp_set_pixel(bmp, i, j + 1, pixel);
	}	
	CuAssertTrue(tc,width==bmp_get_width(bmp));
	CuAssertTrue(tc,height==bmp_get_height(bmp));
	CuAssertTrue(tc,depth==bmp_get_depth(bmp));
	bmp_save(bmp, "testimage.bmp");
	bmp_destroy(bmp);
}
Пример #13
0
BMP* generador_constante(int filas, int columnas, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
    int i, j;
    BMP* res;
    BMPV5H* header;
    filas = filas + 4 - (filas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    columnas = columnas + 4 - (columnas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    header = get_BMPV5H(columnas, filas);

    res = bmp_create(header, 0);
    uint8_t* data = bmp_data(res);
    for(i = 0; i < filas; i++) {
        for(j = 0; j < columnas; j++) {
            data[j*filas*4 + 0] = b;
            data[j*filas*4 + 1] = g;
            data[j*filas*4 + 2] = r;
            data[j*filas*4 + 3] = a;
        }
    }
    return res;
}
Пример #14
0
BMP *bmp_select_car(BMP *bmp, int nb_car)
{
    // Attention aux valeurs numériques
    // Le premier caractère est le caractère numéro 0
    // Il y a 465 caractère par fichier (de 0 à 464)

    BMP *caractere;
    int n,p;
    int i,j;

    caractere = bmp_create(64, 64);

    n = nb_car /20;
    p = nb_car % 20;

    for(i=0;i<64;i++)
        for(j=0;j<64;j++)
            caractere->data[i][j] = bmp->data[64*n+i][64*p+j];

    return caractere;
}
Пример #15
0
void naCreateABmp(JNIEnv* env, jclass clazz, jint width, jint height, jint depth) {
	bmpfile_t *bmp;
	int i, j;
	rgb_pixel_t pixel = {128, 64, 0, 0};
	if (NULL == (bmp = bmp_create(width, height, depth))) {
		LOGE(1, "Invalid depth value: %d. (valid values include 1, 4, 8, 16, 24, 32)\n", depth);
		return;
	}

	for (i = 10, j = 10; j < height; ++i, ++j) {
		bmp_set_pixel(bmp, i, j, pixel);
		pixel.red++;
		pixel.green++;
		pixel.blue++;
		bmp_set_pixel(bmp, i + 1, j, pixel);
		bmp_set_pixel(bmp, i, j + 1, pixel);
	}

	bmp_save(bmp, "/sdcard/test_bs_static.bmp");
	bmp_destroy(bmp);
}
Пример #16
0
int draw_reconstruction_bitmap(PSIRT *psirt) {
	int i=0,j=0;
	double* pixel_intensity = reconstruction(psirt);
	// DESENHAR
	bmpfile_t *bmp = bmp_create(RES_X, RES_Y, 24);
	for (i = 0; i < RES_X; i++) {
		for (j = 0; j < RES_Y; j++) {
			double pixel = pixel_intensity[i + (j * RES_X)];

			// Alternativa 1: função linear simples
			int paint_of_choice = (pixel * 255);

			// Alternativa 2: função polinomial
			#ifdef REC_PAINT_POLY
			paint_of_choice = pow(pixel, 2) * 255;
			#endif

			// Alternativa 3: função exponencial
			#ifdef REC_PAINT_EXP
			paint_of_choice = pow(pixel, pixel) * 255;
			#endif

			// Alternativa 3: função customizada
			#ifdef REC_PAINT_CUSTOM
			paint_of_choice = 255;
			if (pixel < .2)
				paint_of_choice = 0;
			else if (pixel < .4)
				paint_of_choice = 255 / 4;
			#endif

			rgb_pixel_t pix = { paint_of_choice, paint_of_choice, paint_of_choice, 0 };
			bmp_set_pixel(bmp, i, j, pix);
		}
	}
	bmp_save(bmp, "psirt_output.bmp");
	bmp_destroy(bmp);
	free(pixel_intensity);
	return i;
}
Пример #17
0
int main(int argc, char *argv[])
{
    int i, j, g, ret;
    bmp_rgb *c;
    bmp_t *b1 = bmp_init();
    assert(b1 != NULL);

    int width = 997, height = 998;

    ret = bmp_create(b1, argv[1], width, height, BMP_BIT4);
    if (ret) {
        printf("%d:%s\n", ret, bmp_error(ret));
        return ret;
    }

    *bmp_get_pale_rgb(b1, 0) = bmp_make_rgb(255, 0, 0);
    *bmp_get_pale_rgb(b1, 1) = bmp_make_rgb(0, 255, 0);
    *bmp_get_pale_rgb(b1, 2) = bmp_make_rgb(0, 0, 255);

    int color = 0;
    for (i = 0; i < b1->info.height; i++) {
        for (j = 0; j < b1->info.width; j++) {
            bmp_set_bit4(b1, i, j, color);
            color = (color + 1) % 3;
        }
    }

    ret = bmp_write(b1);
    if (ret) {
        printf("%d:%s\n", ret, bmp_error(ret));
        return ret;
    }


    bmp_close(b1);

    printf("OK\n");
    return 0;
}
Пример #18
0
BMP* generador_aleatorio(int filas, int columnas) {
    int i, j;
    BMP* res;
    BMPV5H* header;
    filas = filas + 4 - (filas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    columnas = columnas + 4 - (columnas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    header = get_BMPV5H(columnas, filas);

    srand(time(NULL));
    res = bmp_create(header, 0);
    uint8_t* data = bmp_data(res);
    for(i = 0; i < filas; i++) {
        for(j = 0; j < columnas; j++) {
            data[j*filas*4 + 0] = rand() % 256;
            data[j*filas*4 + 1] = rand() % 256;
            data[j*filas*4 + 2] = rand() % 256;
            data[j*filas*4 + 3] = rand() % 256;
        }
    }
    return res;

}
Пример #19
0
bmpfile_t * complex_to_bmp (COMPLEX **c, int size)
{
	bmpfile_t *bmp = bmp_create (size, size, 8);

	for (int y = 0; y < size; y++)
	{
		for (int x = 0; x < size; x++)
		{
			unsigned char r = (c[y][x].real * 256.0 > 255.0) ? 
				255 : (unsigned char)(c[y][x].real * 256.0);
			unsigned char b = (c[y][x].imag * 256.0 > 255.0) ? 
				255 : (unsigned char)(c[y][x].imag * 256.0);
			unsigned char g = ((c[y][x].real * 128.0) + (c[y][x].imag * 128.0) > 255) ?
				255 : (unsigned char)(c[y][x].real * 128.0) + (c[y][x].imag * 128.0);

			rgb_pixel_t pixel = {r, g, b, 0};
			bmp_set_pixel (bmp, x, y, pixel);
		}
	}

	return bmp;
}
Пример #20
0
int main()
{
	int numFractals;    
    scanf("%d", &numFractals);
    
    int depth;
    double angle, heading;
    char axiom[MAX_CHARS];
    
    bmp = bmp_create(300 * numFractals, 300, 32);
    resetImage(300 * numFractals, 300);
    
    int i;
    for (i = 0; i < numFractals; i++)
    {
        scanf("%d", &depth);
        scanf("%lf", &angle); 
        scanf("%lf", &heading);
        
        angle = degreesToRadians(angle);
        currH = degreesToRadians(heading);
        
        scanf("%s", axiom);
        scanf("%d", &numRules);
        
        int j;
        for (j = 0; j < numRules; j++)
        {
            char tmp[2];
            scanf("%s -> %s\n", tmp, rules[j]);
            codes[j] = tmp[0];
        }
        
        drawFractal(axiom, heading, angle, depth, i);
    }
    
    bmp_save(bmp, "output.bmp");
	bmp_destroy(bmp);
}
Пример #21
0
BMP* generador_todoscolores() {
    int i, j, filas, columnas;
    BMP* res;
    BMPV5H* header;
    filas = 255*255;
    columnas = 255*255;

    filas = filas + 4 - (filas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    columnas = columnas + 4 - (columnas % 4); // Lo llevamos al multiplo de 4 mas cercano y mas grande.
    header = get_BMPV5H(columnas, filas);

    res = bmp_create(header, 0);
    uint8_t* data = bmp_data(res);
    for(i = 0; i < filas; i++) {
        for(j = 0; j < columnas; j++) {
            data[j*filas*4 + 0] = j % 256;
            data[j*filas*4 + 1] = j / 256;
            data[j*filas*4 + 2] = i % 256;
            data[j*filas*4 + 3] = i / 256;
        }
    }
    return res;
}
Пример #22
0
void draw_projection_bitmap(PSIRT* psirt)
{
	bmpfile_t *bmp_proj = bmp_create(RES_X, RES_Y, 24);

	int i, j;
	for (i = 0; i < psirt->n_projections; i++)
	{
		for (j = 0; j < psirt->n_trajectories; j++)
		{
			Trajectory* t = psirt->projections[i]->lista_trajetorias[j];

			Vector2D begin, end, d;
			sum_void(t->source, t->direction, &begin);
			d.x = t->direction->x;
			d.y = t->direction->y;

			mult_constant_void(&d, -1);
			sum_void(t->source, &d, &end);

			// Desenhar linha
			double delta = (begin.y-end.y)/(begin.x-end.x);
			double x, y;

			int k = 0;
			for (k = -1000; k < 1000; k++)
			{
				x = k*0.001f;
				y = ( delta*(x-begin.x) ) + begin.y;
				rgb_pixel_t pix = {0,0,255,0};
				bmp_set_pixel(bmp_proj, x*RES_X+RES_X/2, y*RES_Y+RES_Y/2, pix);
			}
		}
	}
	bmp_save(bmp_proj, "projections_output.bmp");
	bmp_destroy(bmp_proj);
}
Пример #23
0
int vista_fswc_grab()
{
	/* Allocate memory for the average bitmap buffer. */
	abitmap = calloc(config->width * config->height * 3, sizeof(avgbmp_t));
	if(!abitmap)
	{
		ERROR("Out of memory.");
		return(-1);
	}

	/* Grab (and do nothing with) the skipped frames. */
	for(frame = 0; frame < config->skipframes; frame++)
		if(src_grab(&src) == -1) break;

	/* Grab the requested number of frames. */
	for(frame = 0; frame < config->frames; frame++)
	{
		if(src_grab(&src) == -1) break;
		
		/* Add frame to the average bitmap. */
		switch(src.palette)
		{
		case SRC_PAL_PNG:
			fswc_add_image_png(&src, abitmap);
			break;
		case SRC_PAL_JPEG:
		case SRC_PAL_MJPEG:
			fswc_add_image_jpeg(&src, abitmap);
			break;
		case SRC_PAL_S561:
			fswc_add_image_s561(abitmap, src.img, src.length, src.width, src.height, src.palette);
			break;
		case SRC_PAL_RGB32:
			fswc_add_image_rgb32(&src, abitmap);
			break;
		case SRC_PAL_BGR32:
			fswc_add_image_bgr32(&src, abitmap);
			break;
		case SRC_PAL_RGB24:
			fswc_add_image_rgb24(&src, abitmap);
			break;
		case SRC_PAL_BGR24:
			fswc_add_image_bgr24(&src, abitmap);
			break;
		case SRC_PAL_BAYER:
		case SRC_PAL_SGBRG8:
		case SRC_PAL_SGRBG8:
			fswc_add_image_bayer(abitmap, src.img, src.length, src.width, src.height, src.palette);
			break;
		case SRC_PAL_YUYV:
		case SRC_PAL_UYVY:
			fswc_add_image_yuyv(&src, abitmap);
			break;
		case SRC_PAL_YUV420P:
			fswc_add_image_yuv420p(&src, abitmap);
			break;
		case SRC_PAL_NV12MB:
			fswc_add_image_nv12mb(&src, abitmap);
			break;
		case SRC_PAL_RGB565:
			fswc_add_image_rgb565(&src, abitmap);
			break;
		case SRC_PAL_RGB555:
			fswc_add_image_rgb555(&src, abitmap);
			break;
		case SRC_PAL_Y16:
			fswc_add_image_y16(&src, abitmap);
			break;
		case SRC_PAL_GREY:
			fswc_add_image_grey(&src, abitmap);
			break;
		}
	}
	
	/* Copy the average bitmap image to a gdImage. */
	original = gdImageCreateTrueColor(config->width, config->height);
	if(!original)
	{
		ERROR("Out of memory.");
		free(abitmap);
		return(-1);
	}
	
	pbitmap = abitmap;
	for(y = 0; y < config->height; y++)
		for(x = 0; x < config->width; x++)
		{
			int px = x;
			int py = y;
			int colour;
			
			colour  = (*(pbitmap++) / config->frames) << 16;
			colour += (*(pbitmap++) / config->frames) << 8;
			colour += (*(pbitmap++) / config->frames);
			
			gdImageSetPixel(original, px, py, colour);
		}
	
	free(abitmap);

        // scaling stuff just for Ian to learn the art of coding
        if((config->width != VISTA_WIDTH) ||
           (config->height != VISTA_HEIGHT)) {
		gdImage *im;	
		im = gdImageCreateTrueColor(VISTA_WIDTH, VISTA_HEIGHT);
		if(!im)
		{
			WARN("Out of memory.");
			return(-1);
		}
		gdImageCopyResampled(im, original, 0, 0, 0, 0,
	   		VISTA_WIDTH, VISTA_HEIGHT, gdImageSX(original), gdImageSY(original));
		gdImageDestroy(original);
        	original = im;
        }

	// convert the gdimage to a BMP
	bmp = bmp_create(VISTA_WIDTH, VISTA_HEIGHT, 24);
	rgb_pixel_t pixel = {128, 64, 0, 0};
	int c;
	for(y = 0; y < VISTA_HEIGHT; y++) {
		for(x = 0; x < VISTA_WIDTH; x++)
		{
			c = gdImageGetPixel(original, x, y);
			pixel.red = gdImageRed(original, c);
			pixel.green = gdImageGreen(original, c);
			pixel.blue = gdImageBlue(original, c);
			bmp_set_pixel(bmp, x, y, pixel);
		}
	}

	gdImageDestroy(original);
	bmp_save(bmp, "/tmp/hope.bmp");
	bmp_destroy(bmp);

	return 0;
}
Пример #24
0
int main(){

  /* ======================================================================= */
  /* === EJ 1 : crear un bmp de 24 bits de 100x100 y dibujar un patron bayer */

  // creo el header de una imagen de 100x100 de 24 bits
  BMPIH* imgh1 = get_BMPIH(100,100);

  // crea una imagen bmp inicializada
  BMP* bmp1 = bmp_create(imgh1,1);

  // obtengo la data y dibujo el patron bayer
  uint8_t* data1 = bmp_get_data(bmp1);
  int i,j;
  for(j=0;j<100;j=j+2) {
    for(i=0;i<100;i=i+2) {
      data1[j*300+3*i+1] = 0xff;
      data1[j*300+3*i+3] = 0xff;
    }
    for(i=0;i<100;i=i+2) {
      data1[j*300+300+3*i+2] = 0xff;
      data1[j*300+300+3*i+4] = 0xff;
    }
  }

  // guardo la imagen
  bmp_save(FILE1, bmp1);

  // borrar bmp
  bmp_delete(bmp1);

  /* ======================================================================= */
  /* === EJ 2 : crear un bmp de 32 bits de 100x100 y fondo blanco en degrade */

  // creo el encavezado de una imagen de 640x480 de 32 bits
  BMPV5H* imgh2 = get_BMPV5H(100,100);

  // crea una imagen bmp no inicializada
  BMP* bmp2 = bmp_create(imgh2,0);

  // obtengo la data y dibujo el degrade
  uint8_t* data2 = bmp_get_data(bmp2);
  for(j=0;j<100;j++) {
    for(i=0;i<100;i++) {
      data2[j*400+i*4+0] = (uint8_t)(((float)(i+j))*(256.0/200.0));
      data2[j*400+i*4+1] = 0xff;
      data2[j*400+i*4+2] = 0xff;
      data2[j*400+i*4+3] = 0xff;
    }
  }

  // guardo la imagen
  bmp_save(FILE2, bmp2);

  // borrar bmp
  bmp_delete(bmp2);

  /* ======================================================================= */
  /* === EJ 3 : crear un bmp con el mapa de bits de bmp1 y el alpha de bmp2  */

  // Abro los dos archivos
  BMP* bmp1n = bmp_read(FILE1);
  BMP* bmp2n = bmp_read(FILE2);

  // copio la imagen con transparecia sin datos
  BMP* bmpNEW = bmp_copy(bmp2n, 0);

  // obtengo datos de new y las combino
  uint8_t* data1n = bmp_get_data(bmp1n);
  uint8_t* data2n = bmp_get_data(bmp2n);
  uint8_t* dataNEW = bmp_get_data(bmpNEW);
  for(j=0;j<100;j++) {
    for(i=0;i<100;i++) {
      dataNEW[j*400+i*4+0] = data2n[j*400+i*4+0];
      dataNEW[j*400+i*4+1] = data1n[j*300+i*3+0];
      dataNEW[j*400+i*4+2] = data1n[j*300+i*3+1];
      dataNEW[j*400+i*4+3] = data1n[j*300+i*3+2];
    }
  }

  // guardo la imagen
  bmp_save(FILE3, bmpNEW);

  // borrar bmp
  bmp_delete(bmp1n);
  bmp_delete(bmp2n);
  bmp_delete(bmpNEW);

  return 0;
}
Пример #25
0
/**
 * Allocates memory for the next BMP in an ICO collection
 *
 * Sets proper structure values
 *
 * \param ico		the ICO collection to add the image to
 * \param image		a pointer to the ICO image to be initialised
 */
static bmp_result next_ico_image(ico_collection *ico, ico_image *image) {
	bmp_create(&image->bmp, &ico->bitmap_callbacks);
	image->next = ico->first;
	ico->first = image;
	return BMP_OK;
}
Пример #26
0
bmpfile_t* bilinear_resize(bmpfile_t* bmp_read, float scale, int num_threads){

	bmpfile_t *bmp_resize = NULL;
	int width, height;
	int en_width, en_height;
	int i, j;

	width = bmp_get_dib(bmp_read).width;
	height = bmp_get_dib(bmp_read).height; 
	
	en_width = (int)(width * scale);
	en_height = (int)(height * scale);
	
	float x_ratio = ((float)(width-1))/en_width ;
    float y_ratio = ((float)(height-1))/en_height ;
	
	int temp[en_width*en_height];
	int pixels[ width*height];
	
	bmp_to_array( pixels, bmp_read, width, height);
	
	//printf(" after to array\n");
	bmp_resize = bmp_create(en_width, en_height, 8);
	
	// do bilinear interpolatin to get new picture
	if( bmp_resize != NULL){
	
	#pragma omp parallel for private(j)
    for (i = 0; i < en_width; ++i) {
	 
      for (j = 0; j < en_height; ++j) {
	        
			int x = (int)(x_ratio * i) ;
            int y = (int)(y_ratio * j) ;
            float x_diff = (x_ratio * i) - x ;
            float y_diff = (y_ratio * j) - y ;
			int index = (x*height + y);
         		
			rgb_pixel_t *a = get_8bpp_color(bmp_read, pixels[index]);
			rgb_pixel_t *b = get_8bpp_color(bmp_read, pixels[index+height]);
			rgb_pixel_t *c = get_8bpp_color(bmp_read, pixels[index+1]);		
			rgb_pixel_t *d = get_8bpp_color(bmp_read, pixels[index+height+1]);
			
			int ared = a->red;
			int agreen = a->green;
			int ablue = a->blue;
			int bred = b->red;
			int bgreen = b->green;
			int bblue = b->blue;
			int cred = c->red;
			int cgreen = c->green;
			int cblue = c->blue;
			int dred = d->red;
			int dgreen = d->green;
			int dblue = d->blue;
					
			int red = ared*(1-x_diff)*(1-y_diff) + bred*(x_diff)*(1-y_diff) + cred*y_diff*(1-x_diff) + dred*(x_diff*y_diff);
			int green = agreen*(1-x_diff)*(1-y_diff) + bgreen*(x_diff)*(1-y_diff) + cgreen*y_diff*(1-x_diff) + dgreen*(x_diff*y_diff);
			int blue = ablue*(1-x_diff)*(1-y_diff) + bblue*(x_diff)*(1-y_diff) + cblue*y_diff*(1-x_diff) + dblue*(x_diff*y_diff);

			rgb_pixel_t curr_pixel;
			curr_pixel.red = (uint8_t)red;
			curr_pixel.green = (uint8_t)green;
			curr_pixel.blue = (uint8_t)blue;
			curr_pixel.alpha = 0;
	
			bmp_set_pixel(bmp_resize, i, j, curr_pixel);
					
      }
    }
	}
//	printf("still resizing!\n");
	return bmp_resize;
}