Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Thu Oct 23, 2014 11:40 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Feb 11, 2013 4:56 am 
Prolific Poster

Joined: Mon Mar 19, 2012 5:59 am
Posts: 19
Hi everyone, I need to scale an image and due to the lack of CPU/RAM I need it to be done the lesser consumming resources task as it possible (just a 500MB RAM and 1Gb as hard disk).
I planned to do it with SDL_DisplayOverlay in order to scale it, if it is possible.

I am working around with a simple code, but I can't see the the whole bmp, I see a green rectangle. The green is just part of the whole bmp file
I appreciate any suggestion on this.

Thanks and regards

kovi

Here is the code:


Code:
 SDL_Surface* screen = SDL_SetVideoMode(800, 400, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);

        // load an image
        SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
        if (!bmp)
        {
            printf("Unable to load bitmap: %s\n", SDL_GetError());
            return 1;
        }

        SDL_Overlay *overlay = NULL;

        // centre the bitmap on screen
        SDL_Rect dstrect;
        dstrect.x = 0;
        dstrect.y = 0;

        // program main loop
        bool done = false;
        while (!done)
        {
            // message processing loop
            SDL_Event event;
            while (SDL_PollEvent(&event))
            {
                // check for messages
                switch (event.type)
                {
                    // exit if the window is closed
                case SDL_QUIT:
                    done = true;
                    break;

                    // check for keypresses
                case SDL_KEYDOWN:
                    {
                        // exit if ESCAPE is pressed
                        if (event.key.keysym.sym == SDLK_ESCAPE)
                            done = true;
                        break;
                    }
                } // end switch
            } // end of message processing

            // DRAWING STARTS HERE

            // clear screen
            SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

            // draw bitmap
            SDL_BlitSurface(bmp, 0, screen, &dstrect);       

            overlay = SDL_CreateYUVOverlay(bmp->w,bmp->h, SDL_IYUV_OVERLAY , screen);

            SDL_Rect video_rect;

            video_rect.x = 0;
            video_rect.y = 0;
            video_rect.w = screen->w;
            video_rect.h = screen->h;

            SDL_DisplayYUVOverlay(overlay, &video_rect);

            // DRAWING ENDS HERE
         
        } // end main loop


Top
 Profile  
 
PostPosted: Tue Feb 12, 2013 6:48 pm 
Bytewise
User avatar

Joined: Sun Aug 05, 2012 9:32 pm
Posts: 268
have you tried to setVideoMode with SDL_ANYFORMAT flag?
Code:
SDL_Surface* screen = SDL_SetVideoMode(800, 400, 16,SDL_ANYFORMAT|SDL_HWSURFACE|SDL_DOUBLEBUF);


I never actually used YUV in SDL so I am not sure, but i think you have to have this flag set to scale it properly

_________________
Did you ever wonder, how time works?


Top
 Profile  
 
PostPosted: Tue Feb 12, 2013 6:52 pm 
Prolific Poster

Joined: Mon Mar 19, 2012 5:59 am
Posts: 19
Hi, thanks for your response. No , I didn't try it, but Iĺl follow your suggestion. I am thinking I have to do some RGB -> YUV conversion as well.

Regards

kovi


Top
 Profile  
 
PostPosted: Tue Feb 12, 2013 8:44 pm 
Prolific Poster

Joined: Mon Mar 19, 2012 5:59 am
Posts: 19
well, I finally try to put the SDL_ANYFORMAT, it didn't work. Thanks anyway.
I'll be working on this.

Regards, kovi


Top
 Profile  
 
PostPosted: Wed Mar 06, 2013 8:33 pm 
Prolific Poster

Joined: Mon Mar 19, 2012 5:59 am
Posts: 19
Well finally I could display an image using SDL_DisolayYUVOverlay, but I guessed well I had to do the RGB->YUV pixel conversion.
I based the conversion on which I read here: http://www.fourcc.org/fccyvrgb.php (the one based on the "Video Demystified" book).

There are another formulas, I have no clear why this one works for me and why others do not. I could gess it has to do with the YUV scheme selected.

Besides that I had to the sheme conversion:


Code:
inline void ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o)
{
   int x,y;
   int yuv[3];
   Uint8 *p,*op[3];

   SDL_LockSurface(s);
   SDL_LockYUVOverlay(o);

      /* Convert */
   for(y=0; y < s->h && y < o->h; y++)
   {
      p = ((Uint8 *)s->pixels) + s->pitch*y;

      op[0]=o->pixels[0]+o->pitches[0]*y;
      op[1]=o->pixels[1]+o->pitches[1]*(y/2);
      op[2]=o->pixels[2]+o->pitches[2]*(y/2);

      for(x=0; x<s->w && x<o->w; x++)
      {
         RGBtoYUV(p,yuv);
         *(op[0]++)=yuv[0];
         if(x%2==0 && y%2==0)
         {
            *(op[1]++)=yuv[1];
            *(op[2]++)=yuv[2];
         }
         p+=s->format->BytesPerPixel;
      }
   }

   SDL_UnlockYUVOverlay(o);
   SDL_UnlockSurface(s);
}


Then I scale the bmp to display:

Code:
SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
   
    SDL_Overlay *overlay = NULL;
    :
    :
    :
    overlay = SDL_CreateYUVOverlay(bmp->w,bmp->h, SDL_IYUV_OVERLAY , screen);

    ConvertRGBtoIYUV(bmp, overlay);

    SDL_Rect video_rect;

        video_rect.x = 200;
        video_rect.y = 0;
        video_rect.w = bmp->w*3;  // I scaled it by 3 times from its original length
        video_rect.h = bmp->h*3;

        SDL_DisplayYUVOverlay(overlay, &video_rect);

        // DRAWING ENDS HERE
       
        SDL_Flip(screen);


Maybe there are better ways to do these, any suggestions are welcome. Thanks

Regards
Kovi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group