Exemplo n.º 1
0
static void 
writeMS_Ico(MS_Ico       const MSIconData, 
            const char * const outFname) {
    int x,y;
   
    ofp = pm_openw(outFname);

    writeU2(MSIconData->reserved);
    writeU2(MSIconData->type);
    writeU2(MSIconData->count);
    for (x=0;x<MSIconData->count;x++) writeIC_Entry(MSIconData->entries[x]);
    for (x=0;x<MSIconData->count;x++) {
        writeIC_InfoHeader(MSIconData->entries[x]->ih);
        for (y=0;y<(MSIconData->entries[x]->color_count);y++) {
            writeIC_Color(MSIconData->entries[x]->colors[y]);
        }
        if (verbose) pm_message("writing xor bitmap");
        writeBitmap(MSIconData->entries[x]->xorBitmapOut,
                    MSIconData->entries[x]->xBytesXor,
                    MSIconData->entries[x]->height);
        if (verbose) pm_message("writing and bitmap");
        writeBitmap(MSIconData->entries[x]->andBitmapOut,
                    MSIconData->entries[x]->xBytesAnd,
                    MSIconData->entries[x]->height);
    }
    fclose(ofp);
}
Exemplo n.º 2
0
void FractalCreator::run(string name) {
	calculateIteration();
	calculateTotalIterations();
	drawFractal();
	writeBitmap("test.bmp");

}
Exemplo n.º 3
0
void writeBitmap(const char *sectionStr, uint32 resId) {
	char nameBuffer[256];
	sprintf(nameBuffer, "%s/%u", sectionStr, resId);

	Common::File *file = res.getResource(getResId(sectionStr),
		Common::WinResourceID(resId));
	assert(file);
	writeBitmap(nameBuffer, file);
}
Exemplo n.º 4
0
void writeBitmap(const char *sectionStr, uint32 resId, bool isEnglish = true) {
	char nameBuffer[256];
	sprintf(nameBuffer, "%s/%u%s", sectionStr, resId,
		isEnglish ? "" : "/DE");

	Common::PEResources &res = isEnglish ? resEng : resGer;
	Common::File *file = res.getResource(getResId(sectionStr),
		Common::WinResourceID(resId));
	assert(file);
	writeBitmap(nameBuffer, file);
}
Exemplo n.º 5
0
void FractalCreator::run(string filename)
{
    addZoom(Zoom(_width/2, _height/2, 4.0/_width));
    addZoom(Zoom(295, _height - 202, 0.1));
    addZoom(Zoom(312, _height - 304, 0.1));

    calculateIteration();
    calculateRangeTotal();
    drawFractal();
    writeBitmap(filename);
}
Exemplo n.º 6
0
void GLXGraphicsystem::saveScreenShotOfFramebuffer(std::string fileToSave)
{
    LOG_DEBUG("GLXGraphicsystem","taking screenshot and saving it to:" << fileToSave);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height

    int WINDOW_WIDTH= viewport[2];
    int WINDOW_HEIGHT= viewport[3];
    LOG_DEBUG("GLXGraphicsystem","Screenshot: " << WINDOW_WIDTH << " * " << WINDOW_HEIGHT);
    char *buffer = (char *)malloc(WINDOW_WIDTH * WINDOW_HEIGHT * 3 * sizeof(unsigned char));
    glReadPixels(0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_BGR,GL_UNSIGNED_BYTE, buffer);

    writeBitmap(fileToSave,buffer,WINDOW_WIDTH,WINDOW_HEIGHT);
    free(buffer);
    LOG_DEBUG("GLXGraphicsystem","done taking screenshot");
}
Exemplo n.º 7
0
EDLL int AoscMessage::getBytes(byte *data, int sizemax)
{
    int size=0;
    memset(data, 0, sizemax);
    size+=writeString(pattern, data, sizemax);
    format[0]=',';
    {
        Anode	*n=lchild;
        char	*f=&format[1];
        while(n)
        {
            if(n->isCI(&AoscString::CI))
                *(f++)='s';
            else if(n->isCI(&AoscInteger::CI))
                *(f++)='i';
            else if(n->isCI(&AoscFloat::CI))
                *(f++)='f';
            else if(n->isCI(&AoscColor::CI))
                *(f++)='r';
            else if(n->isCI(&AoscBitmap::CI))
                *(f++)='j';
            n=n->prev;
        }
        *f=0;
    }
    size+=writeString(format, data+size, sizemax-size);
    {
        Anode	*n=lchild;
        while(n)
        {
            if(n->isCI(&AoscString::CI))
                size+=writeString(((AoscString *)n)->value, data+size, sizemax-size);
            else if(n->isCI(&AoscInteger::CI))
                size+=writeInt(((AoscInteger *)n)->value, data+size, sizemax-size);
            else if(n->isCI(&AoscFloat::CI))
                size+=writeFloat(((AoscFloat *)n)->value, data+size, sizemax-size);
            else if(n->isCI(&AoscColor::CI))
                size+=writeInt(((AoscColor *)n)->value, data+size, sizemax-size);
            else if(n->isCI(&AoscBitmap::CI))
                size+=writeBitmap(((AoscBitmap *)n)->value, data+size, sizemax-size);
            n=n->prev;
        }
    }
    return size;
}
Exemplo n.º 8
0
void writeData() {
	for (int idx = 0; idx < (resGer.empty() ? 1 : 2); ++idx) {
		bool isEnglish = idx == 0;

		writeBitmap("Bitmap", "BACKDROP", isEnglish);
		writeBitmap("Bitmap", "EVILTWIN", isEnglish);
		writeBitmap("Bitmap", "RESTORED", isEnglish);
		writeBitmap("Bitmap", "RESTOREF", isEnglish);
		writeBitmap("Bitmap", "RESTOREU", isEnglish);
		writeBitmap("Bitmap", "STARTD", isEnglish);
		writeBitmap("Bitmap", "STARTF", isEnglish);
		writeBitmap("Bitmap", "STARTU", isEnglish);
		writeBitmap("Bitmap", "TITANIC", isEnglish);
		writeBitmap("Bitmap", 133, isEnglish);
		writeBitmap("Bitmap", 164, isEnglish);
		writeBitmap("Bitmap", 165, isEnglish);
	}

	writeResource("STFONT", 149);
	writeResource("STFONT", 151);
	writeResource("STFONT", 152);
	writeResource("STFONT", 153);

	writeResource("STARFIELD", 132);
	writeStarfieldPoints();
	writeStarfieldPoints2();

	writeResource("TEXT", "STVOCAB.TXT");
	writeResource("TEXT", "JRQUOTES.TXT");
	writeResource("TEXT", 155);

	writeStringArray("TEXT/ITEM_DESCRIPTIONS", ITEM_DESCRIPTIONS, 46);
	writeStringArray("TEXT/ITEM_NAMES", ITEM_NAMES, 46);
	writeStringArray("TEXT/ITEM_IDS", ITEM_IDS, 40);
	writeStringArray("TEXT/ROOM_NAMES", ROOM_NAMES, 34);
	writeStringArray("TEXT/STRINGS", STRINGS_EN, 58);
	writeStringArray("TEXT/STRINGS/DE", STRINGS_DE, 104);
	const int TEXT_PHRASES[3] = { 0x61D3C8, 0x618340, 0x61B1E0 };
	const int TEXT_REPLACEMENTS1[3] = { 0x61D9B0, 0x61C788, 0x61B7C8 };
	const int TEXT_REPLACEMENTS2[3] = { 0x61DD20, 0x61CAF8, 0x61BB38 };
	const int TEXT_REPLACEMENTS3[3] = { 0x61F5C8, 0x61E3A0, 0x61D3E0 };
	const int TEXT_PRONOUNS[3] = { 0x631318, 0x6300F8, 0x62F138 };
	writeStringArray("TEXT/PHRASES", TEXT_PHRASES[_version], 376);
	writeStringArray("TEXT/REPLACEMENTS1", TEXT_REPLACEMENTS1[_version], 218);
	writeStringArray("TEXT/REPLACEMENTS2", TEXT_REPLACEMENTS2[_version], 1576);
	writeStringArray("TEXT/REPLACEMENTS3", TEXT_REPLACEMENTS3[_version], 82);
	writeStringArray("TEXT/PRONOUNS", TEXT_PRONOUNS[_version], 15);

	const int SENTENCES_DEFAULT[3] = { 0x5C0130, 0x5BEFC8, 0x5BE008 };
	const int SENTENCES_BARBOT[2][3] = {
		{ 0x5ABE60, 0x5AACF8, 0x5A9D38 }, { 0x5BD4E8, 0x5BC380, 0x5BB3C0 }
	};
	const int SENTENCES_BELLBOT[20][3] = {
		{ 0x5C2230, 0x5C10C8, 0X5C0108 }, { 0x5D1670, 0x5D0508, 0x5CF548 },
		{ 0x5D1A80, 0x5D0918, 0x5CF958 }, { 0x5D1AE8, 0x5D0980, 0x5CF9C0 },
		{ 0x5D1B88, 0x5D0A20, 0x5CFA60 }, { 0x5D2A60, 0x5D18F8, 0x5D0938 },
		{ 0x5D2CD0, 0x5D1B68, 0x5D0BA8 }, { 0x5D3488, 0x5D2320, 0x5D1360 },
		{ 0x5D3900, 0x5D2798, 0x5D17D8 }, { 0x5D3968, 0x5D2800, 0x5D1840 },
		{ 0x5D4668, 0x5D3500, 0x5D2540 }, { 0x5D47A0, 0x5D3638, 0x5D2678 },
		{ 0x5D4EC0, 0x5D3D58, 0x5D2D98 }, { 0x5D5100, 0x5D3F98, 0x5D2FD8 },
		{ 0x5D5370, 0x5D4208, 0x5D3248 }, { 0x5D5548, 0x5D43E0, 0x5D3420 },
		{ 0x5D56B8, 0x5D4550, 0x5D3590 }, { 0x5D57C0, 0x5D4658, 0x5D3698 },
		{ 0x5D5B38, 0x5D49D0, 0x5D3A10 }, { 0x5D61B8, 0x5D5050, 0x5D4090 }
	};
	writeSentenceEntries("Sentences/Default", SENTENCES_DEFAULT[_version]);
	writeSentenceEntries("Sentences/Barbot", SENTENCES_BARBOT[0][_version]);
	writeSentenceEntries("Sentences/Barbot2", SENTENCES_BARBOT[1][_version]);
	writeSentenceEntries("Sentences/Bellbot", SENTENCES_BELLBOT[0][_version]);
	writeSentenceEntries("Sentences/Bellbot/1", SENTENCES_BELLBOT[1][_version]);
	writeSentenceEntries("Sentences/Bellbot/2", SENTENCES_BELLBOT[2][_version]);
	writeSentenceEntries("Sentences/Bellbot/3", SENTENCES_BELLBOT[3][_version]);
	writeSentenceEntries("Sentences/Bellbot/4", SENTENCES_BELLBOT[4][_version]);
	writeSentenceEntries("Sentences/Bellbot/5", SENTENCES_BELLBOT[5][_version]);
	writeSentenceEntries("Sentences/Bellbot/6", SENTENCES_BELLBOT[6][_version]);
	writeSentenceEntries("Sentences/Bellbot/7", SENTENCES_BELLBOT[7][_version]);
	writeSentenceEntries("Sentences/Bellbot/8", SENTENCES_BELLBOT[8][_version]);
	writeSentenceEntries("Sentences/Bellbot/9", SENTENCES_BELLBOT[9][_version]);
	writeSentenceEntries("Sentences/Bellbot/10", SENTENCES_BELLBOT[10][_version]);
	writeSentenceEntries("Sentences/Bellbot/11", SENTENCES_BELLBOT[11][_version]);
	writeSentenceEntries("Sentences/Bellbot/12", SENTENCES_BELLBOT[12][_version]);
	writeSentenceEntries("Sentences/Bellbot/13", SENTENCES_BELLBOT[13][_version]);
	writeSentenceEntries("Sentences/Bellbot/14", SENTENCES_BELLBOT[14][_version]);
	writeSentenceEntries("Sentences/Bellbot/15", SENTENCES_BELLBOT[15][_version]);
	writeSentenceEntries("Sentences/Bellbot/16", SENTENCES_BELLBOT[16][_version]);
	writeSentenceEntries("Sentences/Bellbot/17", SENTENCES_BELLBOT[17][_version]);
	writeSentenceEntries("Sentences/Bellbot/18", SENTENCES_BELLBOT[18][_version]);
	writeSentenceEntries("Sentences/Bellbot/19", SENTENCES_BELLBOT[19][_version]);

	const int SENTENCES_DESKBOT[3][3] = {
		{ 0x5DCD10, 0x5DBBA8, 0x5DABE8 }, { 0x5E8E18, 0x5E7CB0, 0x5E6CF0 },
		{ 0x5E8BA8, 0x5E7A40, 0x5E6A80 }
	};
	writeSentenceEntries("Sentences/Deskbot", SENTENCES_DESKBOT[0][_version]);
	writeSentenceEntries("Sentences/Deskbot/2", SENTENCES_DESKBOT[1][_version]);
	writeSentenceEntries("Sentences/Deskbot/3", SENTENCES_DESKBOT[2][_version]);

	const int SENTENCES_DOORBOT[12][3] = {
		{ 0x5EC110, 0x5EAFA8, 0x5E9FE8 }, { 0x5FD930, 0x5FC7C8, 0x5FB808 },
		{ 0x5FDD0C, 0x5FCBA4, 0x5FBBE4 }, { 0x5FE668, 0x5FD500, 0x5FC540 },
		{ 0x5FDD40, 0x5FCBD8, 0X5FBC18 }, { 0x5FFF08, 0x5FEDA0, 0x5FDDE0 },
		{ 0x5FE3C0, 0x5FD258, 0x5FC298 }, { 0x5FF0C8, 0x5FDF60, 0x5FCFA0 },
		{ 0x5FF780, 0x5FE618, 0x5FD658 }, { 0x5FFAC0, 0x5FE958, 0x5FD998 },
		{ 0x5FFC30, 0x5FEAC8, 0x5FDB08 }, { 0x6000E0, 0x5FEF78, 0x5FDFB8 }
	};
	writeSentenceEntries("Sentences/Doorbot", SENTENCES_DOORBOT[0][_version]);
	writeSentenceEntries("Sentences/Doorbot/2", SENTENCES_DOORBOT[1][_version]);
	writeSentenceEntries("Sentences/Doorbot/100", SENTENCES_DOORBOT[2][_version]);
	writeSentenceEntries("Sentences/Doorbot/101", SENTENCES_DOORBOT[3][_version]);
	writeSentenceEntries("Sentences/Doorbot/102", SENTENCES_DOORBOT[4][_version]);
	writeSentenceEntries("Sentences/Doorbot/107", SENTENCES_DOORBOT[5][_version]);
	writeSentenceEntries("Sentences/Doorbot/110", SENTENCES_DOORBOT[6][_version]);
	writeSentenceEntries("Sentences/Doorbot/111", SENTENCES_DOORBOT[7][_version]);
	writeSentenceEntries("Sentences/Doorbot/124", SENTENCES_DOORBOT[8][_version]);
	writeSentenceEntries("Sentences/Doorbot/129", SENTENCES_DOORBOT[9][_version]);
	writeSentenceEntries("Sentences/Doorbot/131", SENTENCES_DOORBOT[10][_version]);
	writeSentenceEntries("Sentences/Doorbot/132", SENTENCES_DOORBOT[11][_version]);

	const int SENTENCES_LIFTBOT[3] = { 0x6026B0, 0x601548, 0x600588 };
	const int SENTENCES_MAITRED[2][3] = {
		{ 0x60CFD8, 0x60BE70, 0x60AEB0 }, { 0x614288, 0x613120, 0x612160 }
	};
	const int SENTENCES_PARROT[3] = { 0x615858, 0x6146F0, 0x613730 };
	const int SENTENCES_SUCCUBUS[3] = { 0x616698, 0x615530, 0x614570 };
	const int MAPPINGS_BARBOT[3] = { 0x5B28A0, 0x5B173E, 0x5B0778 };
	const int MAPPINGS_BELLBOT[3] = { 0x5CD830, 0x5CC6C8, 0x5CB708 };
	const int MAPPINGS_DESKBOT[3] = { 0x5E2BB8, 0x5E1A50, 0x5E0A90 };
	const int MAPPINGS_DOORBOT[3] = { 0x5F7950, 0x5F67E8, 0x5F5828 };
	const int MAPPINGS_LIFTBOT[3] = { 0x608660, 0x6074F8, 0x606538 };
	const int MAPPINGS_MAITRED[3] = { 0x6125C8, 0x611460, 0x6104A0 };
	const int MAPPINGS_PARROT[3] = { 0x615B68, 0x614A00, 0x613A40 };
	const int MAPPINGS_SUCCUBUS[3] = { 0x6189F0, 0x617888, 0x6168C8 };
	const int WORDS_BARBOT[3] = { 0x5BE2E0, 0x5BD178, 0x5BC1B8 };
	const int WORDS_BELLBOT[3] = { 0x5D8230, 0x5D70C8, 0x5D6108 };
	const int WORDS_DESKBOT[3] = { 0x5EAAA8, 0x5E9940, 0x5E8980 };
	const int WORDS_DOORBOT[3] = { 0x601098, 0x5FFF30, 0x5FEF70 };
	const int WORDS_LIFTBOT[3] = { 0x60C788, 0x60B620, 0x60A660 };
	writeSentenceEntries("Sentences/Liftbot", SENTENCES_LIFTBOT[_version]);
	writeSentenceEntries("Sentences/MaitreD", SENTENCES_MAITRED[0][_version]);
	writeSentenceEntries("Sentences/MaitreD/1", SENTENCES_MAITRED[1][_version]);
	writeSentenceEntries("Sentences/Parrot", SENTENCES_PARROT[_version]);
	writeSentenceEntries("Sentences/SuccUBus", SENTENCES_SUCCUBUS[_version]);
	writeSentenceMappings("Mappings/Barbot", MAPPINGS_BARBOT[_version], 8);
	writeSentenceMappings("Mappings/Bellbot", MAPPINGS_BELLBOT[_version], 1);
	writeSentenceMappings("Mappings/Deskbot", MAPPINGS_DESKBOT[_version], 4);
	writeSentenceMappings("Mappings/Doorbot", MAPPINGS_DOORBOT[_version], 4);
	writeSentenceMappings("Mappings/Liftbot", MAPPINGS_LIFTBOT[_version], 4);
	writeSentenceMappings("Mappings/MaitreD", MAPPINGS_MAITRED[_version], 1);
	writeSentenceMappings("Mappings/Parrot", MAPPINGS_PARROT[_version], 1);
	writeSentenceMappings("Mappings/SuccUBus", MAPPINGS_SUCCUBUS[_version], 1);
	writeWords("Words/Barbot", WORDS_BARBOT[_version]);
	writeWords("Words/Bellbot", WORDS_BELLBOT[_version]);
	writeWords("Words/Deskbot", WORDS_DESKBOT[_version]);
	writeWords("Words/Doorbot", WORDS_DOORBOT[_version], 3);
	writeWords("Words/Liftbot", WORDS_LIFTBOT[_version]);
	writePhrases("Phrases/Bellbot", BELLBOT_COMMON_PHRASES);

	writeResponseTree();
	writeNumbers();
	writeAllScriptQuotes();
	writeAllScriptResponses();
	writeAllScriptRanges();

	writeAllTagMappings();
	writeAllUpdateStates();
	writeAllScriptPreResponses();
	writeBarbotFrameRanges();
	writeMissiveOMatMessages();
	writeBedheadData();
	writeParrotLobbyLinkUpdaterEntries();
}
Exemplo n.º 9
0
bool vpFFMPEG::openEncoder(const char *filename, unsigned int w, unsigned int h, AVCodecID codec)
#endif
{
  av_register_all();

  /* find the mpeg1 video encoder */
  pCodec = avcodec_find_encoder(codec);
  if (pCodec == NULL) {
    fprintf(stderr, "codec not found\n");
    return false;
  }

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,5,0) // libavcodec 53.5.0
  pCodecCtx = avcodec_alloc_context();
#else
  pCodecCtx = avcodec_alloc_context3(NULL);
#endif

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,34,0)
  pFrame = avcodec_alloc_frame();
  pFrameRGB = avcodec_alloc_frame();
#else
  pFrame = av_frame_alloc(); // libavcodec 55.34.1
  pFrameRGB = av_frame_alloc(); // libavcodec 55.34.1
#endif

  /* put sample parameters */
  pCodecCtx->bit_rate = (int)bit_rate;
  /* resolution must be a multiple of two */
  pCodecCtx->width = (int)w;
  pCodecCtx->height = (int)h;
  this->width = (int)w;
  this->height = (int)h;
  /* frames per second */
  pCodecCtx->time_base.num = 1;
  pCodecCtx->time_base.den = framerate_encoder;
  pCodecCtx->gop_size = 10; /* emit one intra frame every ten frames */
  pCodecCtx->max_b_frames=1;
  pCodecCtx->pix_fmt = PIX_FMT_YUV420P;

  /* open it */
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,35,0) // libavcodec 53.35.0
  if (avcodec_open (pCodecCtx, pCodec) < 0) {
#else
  if (avcodec_open2 (pCodecCtx, pCodec, NULL) < 0) {
#endif
    fprintf(stderr, "could not open codec\n");
    return false;
  }

  /* the codec gives us the frame size, in samples */

  f = fopen(filename, "wb");
  if (!f) {
    fprintf(stderr, "could not open %s\n", filename);
    return false;
  }

  outbuf_size = 100000;
  outbuf = new uint8_t[outbuf_size];

  numBytes = avpicture_get_size (PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height);
  picture_buf = new uint8_t[numBytes];
  avpicture_fill((AVPicture *)pFrame, picture_buf, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);

  numBytes = avpicture_get_size (PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
  buffer = new uint8_t[numBytes];
  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);

  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
  
  encoderWasOpened = true;

  return true;
}


/*!
  Saves the image I as frame of the video.
  
  \param I : the image to save.
  
  \return It returns true if the image could be saved.
*/
bool vpFFMPEG::saveFrame(vpImage<vpRGBa> &I)
{
  if (encoderWasOpened == false)
  {
    vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
    return false;
  }
  
  writeBitmap(I);
  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,2,100) // libavcodec 54.2.100
  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
  fwrite(outbuf, 1, (size_t)out_size, f);
#else
  AVPacket pkt;
  av_init_packet(&pkt);
  pkt.data = NULL;    // packet data will be allocated by the encoder
  pkt.size = 0;

  int got_output;
  int ret = avcodec_encode_video2(pCodecCtx, &pkt, pFrame, &got_output);
  if (ret < 0) {
    std::cerr << "Error encoding frame in " << __FILE__ << " " << __LINE__ << " " << __FUNCTION__ << std::endl;
    return false;
  }
  if (got_output) {
    fwrite(pkt.data, 1, pkt.size, f);
    av_free_packet(&pkt);
  }
#endif
  fflush(stdout);
  return true;
}


/*!
  Saves the image I as frame of the video.
  
  \param I : the image to save.
  
  \return It returns true if the image could be saved.
*/
bool vpFFMPEG::saveFrame(vpImage<unsigned char> &I)
{
  if (encoderWasOpened == false)
  {
    vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
    return false;
  }
  
  writeBitmap(I);
  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);  
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,2,100) // libavcodec 54.2.100
  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
  fwrite(outbuf, 1, (size_t)out_size, f);
#else
  AVPacket pkt;
  av_init_packet(&pkt);
  pkt.data = NULL;    // packet data will be allocated by the encoder
  pkt.size = 0;

  int got_output;
  int ret = avcodec_encode_video2(pCodecCtx, &pkt, pFrame, &got_output);
  if (ret < 0) {
    std::cerr << "Error encoding frame in " << __FILE__ << " " << __LINE__ << " " << __FUNCTION__ << std::endl;
    return false;
  }
  if (got_output) {
    fwrite(pkt.data, 1, pkt.size, f);
    av_free_packet(&pkt);
  }
#endif

  fflush(stdout);
  return true;
}

/*!
  Ends the writing of the video and close the file.
  
  \return It returns true if the file was closed without problem
*/
bool vpFFMPEG::endWrite()
{
  if (encoderWasOpened == false)
  {
    vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
    return false;
  }
  
  int ret = 1;
  while (ret != 0)
  {

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,2,100) // libavcodec 54.2.100
    ret = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, NULL);
    fwrite(outbuf, 1, (size_t)out_size, f);
#else
    AVPacket pkt;
    av_init_packet(&pkt);
    pkt.data = NULL;    // packet data will be allocated by the encoder
    pkt.size = 0;
    int got_output;
    ret = avcodec_encode_video2(pCodecCtx, &pkt, NULL, &got_output);
    if (ret < 0) {
      std::cerr << "Error encoding frame in " << __FILE__ << " " << __LINE__ << " " << __FUNCTION__ << std::endl;
      return false;
    }
    if (got_output) {
      fwrite(pkt.data, 1, pkt.size, f);
      av_free_packet(&pkt);
    }
#endif
  }

  /*The end of a mpeg file*/
  outbuf[0] = 0x00;
  outbuf[1] = 0x00;
  outbuf[2] = 0x01;
  outbuf[3] = 0xb7;
  fwrite(outbuf, 1, 4, f);
  fclose(f);
  f = NULL;
  return true;
}

/*!
  This method enables to fill the frame bitmap thanks to the vpImage bitmap.
*/
void vpFFMPEG::writeBitmap(vpImage<vpRGBa> &I)
{
  unsigned char* beginInput = (unsigned char*)I.bitmap;
  unsigned char* input = NULL;
  unsigned char* beginOutput = (unsigned char*)pFrameRGB->data[0];
  int widthStep = pFrameRGB->linesize[0];
  
  for(int i=0 ; i < height ; i++)
  {
    input = beginInput + 4 * i * width;
    unsigned char *output = beginOutput + i * widthStep;
    for(int j=0 ; j < width ; j++)
    {
      *(output++) = *(input);
      *(output++) = *(input+1);
      *(output++) = *(input+2);

      input+=4;
    }
  }
}