/**
 * Save texture to file. 
 * @param name - name of the file
 * @param data - smart array containing data of the file
 * @param width - width of the data
 * @param height - height of the data
 * @return 0 if no error occurs
 * @note: Can only be used with 32-Bit per Pixel data (RGBA).
 */
int nrCTextureLoader::save(const string& name,const shared_array<byte>& data,int width,int height) {
	if(strcmp(name.c_str(),".tga")) return save_tga(name,data,width,height);
	if(strcmp(name.c_str(),".jpg")) return save_jpeg(name,data,width,height,80);
	
	nrLog.Log(NR_LOG_ENGINE, "nrCTextureLoader::save():unknown format of '%s' file",name.c_str());
	return 0;
}
Пример #2
0
void recover(unsigned char data[], int size) 
{
    int beginning_picture = 0;
    int counter = 1;
    int card_length;
    unsigned char *card = read_card("card.raw", &card_length);
    // 10,200,224 bytes


    for (long i = 0; i < size; i++) // 27 pictures
    {   
        if ((data[i] == 0xff) &&
           (data[(i + 1)] == 0xd8) &&   
           (data[(i + 2)] == 0xff) &&
           ((data[(i + 3)] == 0xe0) || data[(i + 3)] == 0xe1))
        {
                printf("ffd8ffe0(e1) begins in file %ld\n", i);
                printf("#%d\n", counter);
                counter++;
        }
        
        if ((data[i] == 0xff) && (data[i + 1] == 0xd9))
        {
            printf("ffd9 begins in file %ld\n", i);
        }
    }
    
// while (i < size) for entire array, while loop to find beginning of jpg, while loop to find end of of jpg. 


    for(long i = 3109376; i < 3353077; i++)
    {
        save_jpeg(card, (3353077 - 3109376) + 1, "jpeg01");
    }
}
Пример #3
0
void on_frame(unsigned char *ptr, int len) {

    if (jpeg_frame_index % jpeg_every == 0) {
        decode_into_current(ptr, len);
    }

    if ((fps_frame % 50) == 49) {
        int t = (int)time(NULL);
        float fps = (float)jpeg_frame_index / ((float)(t - fps_start));
        printf("%1.1f FPS after %d frames.\n", fps, fps_frame);
    }
    fps_frame ++;

    if ((jpeg_frame_index % 100) == 30) {
        // sprintf(jpeg_filename, "output/frame%04d.jpg", debug_output_frame % 50);
        sprintf(jpeg_filename, "output/frame.jpg");
        printf("FRAME: Saving input: %s\n", jpeg_filename);
        FILE *f = fopen(jpeg_filename, "wb");
        fwrite(ptr, 1, len, f);
        fclose(f);
    }

    if ((jpeg_frame_index % 100) == 60) {
        // sprintf(jpeg_filename, "output/frame%04d-diff.jpg", debug_output_frame % 50);
        sprintf(jpeg_filename, "output/frame-diff.jpg");
        printf("FRAME: Saving diff: %s\n", jpeg_filename);
        highlight_areas(diff_frame);
        save_jpeg(diff_frame, jpeg_filename);
    }

    if ((jpeg_frame_index % 100) == 90) {
        // sprintf(jpeg_filename, "output/frame%04d-avg.jpg", debug_output_frame % 50);
        sprintf(jpeg_filename, "output/frame-avg.jpg");
        printf("FRAME: Saving average: %s\n", jpeg_filename);
        highlight_areas(average_frame);
        save_jpeg(average_frame, jpeg_filename);

        // debug_output_frame ++;
    }

    jpeg_frame_index ++;
}
Пример #4
0
//=================================================================================
// pkl_output
//=================================================================================
PKLExport int pkl_output(PKLImage pkl, FILE *out, PKL_FORMAT format)
{
	switch(format){
		case PKL_FORMAT_JPEG:
			return save_jpeg(pkl, out);
		case PKL_FORMAT_PNG:
			return save_png(pkl, out);
		case PKL_FORMAT_BITMAP:
			return save_bitmap(pkl, out);
		default:
			return(1);
	}
	return(1);
}
Пример #5
0
static void new_frame(void *ctx, webcam_t *cam, unsigned char *pixels, size_t bpl, size_t size)
{
	unsigned char *buf = NULL;
	size_t len = 0;

	if (save_jpeg(&buf, &len, 75, pixels, cam->width, cam->height, bpl)) {
		fprintf(stderr, "Error: can't save frame!\n");
		return;
	}

	LOCK();
		free(FRAME);
		FRAME = buf;
		FRAME_SZ = len;
	UNLOCK();
}
Пример #6
0
void check_frame_motion() {
    // printf("FRAME: check motion...\n");
    for(int i=0; i<num_areas; i++) {
        Area *area = (Area *)&areas[i];
        check_area_motion(area);
    }

    if (!debug_image_written) {
        printf("DEBUG: Writing zone debug jpeg.\n");
        // write a debug image containing the loaded zones.
        unsigned char *temp = (unsigned char *)malloc(frame_width * frame_height * 3);
        memcpy(temp, average_frame, frame_width * frame_height * 3);
        highlight_areas(temp);
        save_jpeg(temp, (char *)"output/debug.jpg");
        free(temp);
        debug_image_written = true;
    }
}
Пример #7
0
/*----------------------------------------------------------------------------*/
void save_jpeg( const claw::graphic::image& img, const std::string& filename )
{
  std::cout << "non progressive, quality=1" << std::endl;
  save_jpeg( img, filename, false, 1 );
  std::cout << "non progressive, quality=50" << std::endl;
  save_jpeg( img, filename, false, 50 );
  std::cout << "non progressive, quality=80" << std::endl;
  save_jpeg( img, filename, false, 80 );
  std::cout << "non progressive, quality=100" << std::endl;
  save_jpeg( img, filename, false, 100 );

  std::cout << "progressive, quality=1" << std::endl;
  save_jpeg( img, filename, true, 1 );
  std::cout << "progressive, quality=50" << std::endl;
  save_jpeg( img, filename, true, 50 );
  std::cout << "progressive, quality=80" << std::endl;
  save_jpeg( img, filename, true, 80 );
  std::cout << "progressive, quality=100" << std::endl;
  save_jpeg( img, filename, true, 100 );
}
Пример #8
0
void snap(BITMAP *bmp, RGB * pal)
{
    DIR * dd;
    FILE * fp;
    char filename[80];
    int counter = 0;
    int done = 0;

    // first check if the directory exists.
    dd = opendir(SNAPDIR);
    if (dd)
	closedir(dd); // yup
    else 
	mkdir(SNAPDIR, S_IRUSR | S_IWUSR);

    while (!done && counter <= 9999)
    {
#ifdef SNAP_JPEG
	sprintf(filename, "%s/%s%04d.jpg", SNAPDIR, SNAPBASE, counter);
#else
	sprintf(filename, "%s/%s%04d.pcx", SNAPDIR, SNAPBASE, counter);
#endif
	fp = fopen(filename, "rb");
	if (fp)
	{
	    fclose(fp);
	    counter++;
	} else {
	    done = 1;
	}
    }

    if (counter <= 9999) // just in case...
    {
#ifdef SNAP_JPEG
	save_jpeg(filename, bmp, pal);
#else
done = // GN: returns -1
	save_pcx(filename, bmp, pal);
if (done != 0)
  return;
#endif
    }
}
Пример #9
0
/*----------------------------------------------------------------------------*/
void save( const claw::graphic::image& img, const std::string& filename )
{
  std::cout << "== Saving pcx files ==" << std::endl;
  save_pcx( img, filename );

  std::cout << "== Saving jpg files ==" << std::endl;
  save_jpeg( img, filename );

  std::cout << "== Saving png files ==" << std::endl;
  save_png( img, filename );

  std::cout << "== Saving bitmap files ==" << std::endl;
  save_bitmap( img, filename );

  std::cout << "== Saving targa files ==" << std::endl;
  save_targa( img, filename );

  std::cout << "== Saving xbm files ==" << std::endl;
  save_xbm( img, filename );
}
Пример #10
0
int main()
{
    int card_length;
    unsigned char *card = read_card("card.raw", &card_length);
    
// 3109376, 3633664, 3895808, 4157952, 4420096, 4682240, 4911616, 5173760, 5435904, 5698048, 5960192, 6222336, 6484480
// 6746624, 7008768, 7270912, 7533056, 7795200, 8057344, 8319488, 8581632, 8843776, 9105920, 9368064, 9630208, 9892352

    // recover(card, card_length);  
    save_jpeg(&card[3109376], (3353077-3109376)+1, "jpeg01");
    save_jpeg(&card[3371520], (3621114-3371520)+1, "jpeg02");
    save_jpeg(&card[3633664], (3887298-3633664)+1, "jpeg03");
    save_jpeg(&card[3895808], (4136893-3895808)+1, "jpeg04");
    save_jpeg(&card[4157952], (4412860-4157952)+1, "jpeg05");        
    
    save_jpeg(&card[4420096], (4671886-4420096)+1, "jpeg06");
    save_jpeg(&card[4682240], (4910537-4682240)+1, "jpeg07");
    save_jpeg(&card[4911616], (5157123-4911616)+1, "jpeg08");
    save_jpeg(&card[5173760], (5408874-5173760)+1, "jpeg09");
    save_jpeg(&card[5435904], (5684621-5435904)+1, "jpeg10");

    save_jpeg(&card[5698048], (5937804-5698048)+1, "jpeg11");
    save_jpeg(&card[5960192], (6204898-5960192)+1, "jpeg12");
    save_jpeg(&card[6222336], (6464235-6222336)+1, "jpeg13");
    save_jpeg(&card[6484480], (6728616-6484480)+1, "jpeg14");
    save_jpeg(&card[6746624], (6994343-6746624)+1, "jpeg15");
    
    save_jpeg(&card[7008768], (7263145-7008768)+1, "jpeg16");        
    save_jpeg(&card[7270912], (7517331-7270912)+1, "jpeg17");
    save_jpeg(&card[7533056], (7770019-7533056)+1, "jpeg18");
    save_jpeg(&card[7795200], (8041577-7795200)+1, "jpeg19");
    save_jpeg(&card[8057344], (8302006-8057344)+1, "jpeg20");

    save_jpeg(&card[8319488], (8564074-8319488)+1, "jpeg21");        
    save_jpeg(&card[8581632], (8824826-8581632)+1, "jpeg22");
    save_jpeg(&card[8843776], (9087563-8843776)+1, "jpeg23");
    save_jpeg(&card[9105920], (9346565-9105920)+1, "jpeg24");
    save_jpeg(&card[9368064], (9613420-9368064)+1, "jpeg25");
    save_jpeg(&card[9630208], (9868563-9630208)+1, "jpeg26");
    save_jpeg(&card[9892352], (10134695-982352)+1, "jpeg27");        
}