|
简单的jpeg转成avi的类(10) { for (int j = 0; j < 4; ++j) { fputc (i % 0x0100, file); i /= 0x100; } } int AviGenerator::initalize_header () { frames = this->jpeg_list.size (); if (frames <= 0) return -1; /* getting image, and hence, riff sizes */ jpg_sz_64 = this->files_size (); if (-1 == jpg_sz_64) { cerr << "couldn't determine size of images" << endl; return -2; } riff_sz_64 = sizeof (struct AVI_list_hdrl) + 4 + 4 + jpg_sz_64 + 8 * frames + 8 + 8 + 16 * frames; if (riff_sz_64 >= MAX_RIFF_SZ) { cerr << "RIFF would exceed 2 Gb limit" << endl; return -3; } jpg_sz = (long) jpg_sz_64; riff_sz = (DWORD) riff_sz_64; //update the struct AVI_list_hdrl this->list_hdrl.avih.usec_per_frame = LILEND4(usec_per_frame); this->list_hdrl.avih.max_bytes_per_sec = LILEND4((int)1000000 * (jpg_sz / frames) / usec_per_frame); this->list_hdrl.avih.flags = LILEND4(AVIF_HASINDEX); this->list_hdrl.avih.tot_frames = LILEND4(frames); this->list_hdrl.avih.width = LILEND4(width); this->list_hdrl.avih.height = LILEND4(height); this->list_hdrl.strh.scale = LILEND4(usec_per_frame); this->list_hdrl.strh.rate = LILEND4(1000000); this->list_hdrl.strh.length = LILEND4(frames); this->list_hdrl.strf.width = LILEND4(width); this->list_hdrl.strf.height = LILEND4(height); this->list_hdrl.strf.image_sz = LILEND4(width * height * 3); this->list_hdrl.list_odml.frames = LILEND4(frames); return 0; } int AviGenerator::generate_avi () { if (this->initalize_header () != 0) return -1; //open the file FILE* fdest = fopen (this->avi_name_.c_str (), "wb");
|