Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6163 in orxonox.OLD for branches/avi_play/src/lib/graphics


Ignore:
Timestamp:
Dec 19, 2005, 6:43:39 PM (19 years ago)
Author:
hdavid
Message:

branches\avi_play: added ability to get the frames in a list

Location:
branches/avi_play/src/lib/graphics/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/avi_play/src/lib/graphics/importer/media_container.cc

    r6160 r6163  
    4242  fps = 0;
    4343
    44   /* SDL interprets each pixel as a 32-bit number, so our masks must depend
    45      on the endianness (byte order) of the machine */
    46 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    47   rmask = 0xff000000;
    48   gmask = 0x00ff0000;
    49   bmask = 0x0000ff00;
    50 #else
    51   rmask = 0x000000ff;
    52   gmask = 0x0000ff00;
    53   bmask = 0x00ff0000;
    54 #endif
    55 
    5644  if (filename != NULL)
    5745    this->loadMedia(filename);
     
    6452MediaContainer::~MediaContainer()
    6553{
     54  // delete all surfaces in the list
     55  while(!this->surface_list.empty())
     56  {
     57    SDL_FreeSurface(this->surface_list.back());
     58    this->surface_list.pop_back();
     59  }
     60  SDL_FreeSurface(surface);
    6661
    6762  // Free the RGB image
     
    9792      int frame_finished;
    9893      // Decode video frame
    99       avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size);
     94      avcodec_decode_video(codec_context, frame, &frame_finished,
     95                           packet.data, packet.size);
    10096
    10197      // Did we get a video frame?
    10298      if(frame_finished)
    10399      {
    104         PRINTF(1)("frame_number: %i\n", codec_context->frame_number);
    105 
    106100        // Conversion from YUV to RGB
    107101        // Most codecs return images in YUV 420 format
    108102        // (one luminance and two chrominance channels, with the chrominance
    109103        // channels samples at half the spatial resolution of the luminance channel)
    110         img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame, codec_context->pix_fmt,
    111                                         codec_context->width, codec_context->height);
     104        img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame,
     105                    codec_context->pix_fmt, codec_context->width, codec_context->height);
    112106
    113107        picture = (AVPicture*)RGB_frame;
     
    119113          memcpy(&data[i*codec_context->width*3], picture->data[0]+i * picture->linesize[0],codec_context->width*sizeof(uint8_t)*3);
    120114
    121         surface = SDL_CreateRGBSurfaceFrom(data, codec_context->width, codec_context->height,
    122                                            24, codec_context->width*sizeof(uint8_t)*3, rmask, gmask, bmask, 0);
     115        surface = SDL_CreateRGBSurfaceFrom(data, codec_context->width,
     116                                           codec_context->height,24,
     117                                           codec_context->width*sizeof(uint8_t)*3,
     118#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
     119                                           0x000000FF,
     120                                           0x0000FF00,
     121                                           0x00FF0000,
     122                                           0
     123#else
     124                                           0xFF000000,
     125                                           0x00FF0000,
     126                                           0x0000FF00,
     127                                           0
     128#endif
     129                                            );
    123130
    124131        return surface;
     
    130137  else
    131138    return NULL;
     139}
     140
     141vector<SDL_Surface*> MediaContainer::getFrameList()
     142{
     143
     144  while((surface = this->getNextFrame()) != NULL)
     145    surface_list.push_back(surface);
     146
     147  return surface_list;
    132148}
    133149
     
    200216  // Allocate video frame
    201217  frame = avcodec_alloc_frame();
    202         RGB_frame = avcodec_alloc_frame();
     218  RGB_frame = avcodec_alloc_frame();
    203219
    204220  // Determine required buffer size and allocate buffer
  • branches/avi_play/src/lib/graphics/importer/media_container.h

    r6160 r6163  
    88#define _MEDIA_CONTAINER
    99
     10#include <SDL.h>
     11#include <vector>
    1012
    1113#ifdef HAVE_AVFORMAT_H
     
    1517#endif
    1618
    17 
    18 #include "glincl.h"
    19 
    2019/* include base_object.h since all classes are derived from this one */
    2120#include "base_object.h"
    22 
    23 #include <SDL.h>
    2421
    2522/* using namespace std is default, this needs to be here */
     
    3229
    3330  double fps;
    34   Uint32 rmask, gmask, bmask;
    35   SDL_Surface *surface;
     31  SDL_Surface* surface;
    3632  uint8_t* data;
    3733
     
    4137  AVFrame* frame;
    4238  AVPacket packet;
     39  AVFrame* RGB_frame;
    4340  AVPicture* picture;
    44   AVFrame* RGB_frame;
    4541
    4642  int num_bytes;
    4743  uint8_t *buffer;
    4844  int video_stream;
     45
     46  vector<SDL_Surface*>    surface_list;
    4947
    5048public:
     
    5553  SDL_Surface* getFrame(int frame_number);
    5654  SDL_Surface* getNextFrame();
     55  vector<SDL_Surface*> getFrameList();
    5756  void loadMedia(const char* filename);
    5857
     
    6261  double getFPS();
    6362
    64   /* prints some information about the
    65      media file for debug reasons */
     63  void saveCurrentFrame();
     64
    6665  void printMediaInformation();
    6766  void printPacketInformation();
    68   void saveCurrentFrame();
    6967
    7068};
    7169
    7270
    73 
    7471#endif /* _MEDIA_CONTAINER */
  • branches/avi_play/src/lib/graphics/importer/texture_sequence.cc

    r6149 r6163  
    150150  this->setAlpha(hasAlpha);
    151151
    152   //PRINTF(1)("added frame");
     152  return true;
     153}
    153154
    154   return true;
     155bool TextureSequence::addFrameList(std::vector<SDL_Surface*> surfaces)
     156{
     157  // add the surfaces to the list
     158  for(int i = 0; i < surfaces.size(); i++)
     159    this->addFrame(surfaces[i]);
    155160}
    156161
  • branches/avi_play/src/lib/graphics/importer/texture_sequence.h

    r6094 r6163  
    3030    bool addFrame(SDL_Surface* surface);
    3131    bool addFrame(GLuint texture);
     32    bool addFrameList(std::vector<SDL_Surface*> surfaces);
    3233
    3334    virtual bool rebuild();
Note: See TracChangeset for help on using the changeset viewer.