I have a program I use to manipulate various image files. Currently it only works with static images. I want to provide support for gifs and I've been looking through the lackluster documentation but cannot find any reference to how to manipulate gifs frame by frame.
Ideally I'd like to work through the gif one frame at a time, using my other functions to manipulate each of the frames in a file and then repackage the image.
If you look carefully to the source code, you can easily find a weak implementation when using animated frames.
The code does not lie: when you call gdImageCreateFromGif(FILE *fdFile) or gdImageCreateFromGifPtr (int size, void *data), it calls directly to gdImageCreateFromGifCtx(gdIOCtxPtr fd), so you must read'n'search in that function where is the mess. The documentation has no info about it, because this library is very, very old.
In the source code (fd06f7f on 22 Jun) line 258 (gdImageCreateFromGifCtx(gdIOCtxPtr fd)):
for (;;) {
int top, left;
int width, height;
if(!ReadOK(fd, &c, 1)) {
return 0;
}
if (c == ';') { /* GIF terminator */
goto terminated;
}
if(c == '!') { /* Extension */
if(!ReadOK(fd, &c, 1)) {
return 0;
}
DoExtension(fd, c, &Transparent, &ZeroDataBlock);
continue;
}
if(c != ',') { /* Not a valid start character */
continue;
}
/*1.4//++imageCount; */
if(!ReadOK(fd, buf, 9)) {
return 0;
}
useGlobalColormap = !BitSet(buf[8], LOCALCOLORMAP);
bitPixel = 1 << ((buf[8] & 0x07) + 1);
left = LM_to_uint(buf[0], buf[1]);
top = LM_to_uint(buf[2], buf[3]);
width = LM_to_uint(buf[4], buf[5]);
height = LM_to_uint(buf[6], buf[7]);
if(((left + width) > screen_width) || ((top + height) > screen_height)) {
if(VERBOSE) {
printf("Frame is not confined to screen dimension.\n");
}
return 0;
}
if(!(im = gdImageCreate(width, height))) {
return 0;
}
im->interlace = BitSet(buf[8], INTERLACE);
if(!useGlobalColormap) {
if(ReadColorMap(fd, bitPixel, localColorMap)) {
gdImageDestroy(im);
return 0;
}
ReadImage(im, fd, width, height, localColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock);
} else {
if(!haveGlobalColormap) {
gdImageDestroy(im);
return 0;
}
ReadImage(im, fd, width, height, ColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock);
}
if(Transparent != (-1)) {
gdImageColorTransparent(im, Transparent);
}
goto terminated;
}
That goto finishes the loop without attempt to read another frame, even.
That's because this implementation is intended to read explicitly one frame from a gif. Only one.
I worked with this library. Has other flaws, too. The transparency for PNG files are 7 bits, not 8 bits (one of the main reasons I used it and discard it later).
You can pack animated gifs with gdImageGifAnimBegin(gdImagePtr im, FILE *outFile, int GlobalCM, int Loops)
[TL;DR]: libgd has no multiple frames option when loading. It's not intended to load animated gifs.
Related
I am super new to creating efi application. My aim is to create a small application in efi, that displays some text on a background. But I am stuck with trying to display text on the display (Great would be to have a custom font, but that is not necessary at this stage). I want the app (also) to run on apple systems (to boot from a usb)
How do I find good documentation on the EFI functions? It seems super hard to find good examples etc.
How can I display a text on a background with EFI?
This is what I got so far. I change the background to a color using the graphics protocol. How do I display a text on it. The Output String doesn't seem to work.
#include "efibind.h"
#include "efidef.h"
#include "efidevp.h"
#include "eficon.h"
#include "efiapi.h"
#include "efierr.h"
#include "efiprot.h"
static EFI_GUID GraphicsOutputProtocolGUID = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
/**
* efi_main - The entry point for the EFI application
* #image: firmware-allocated handle that identifies the image
* #SystemTable: EFI system table
*/
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable) {
EFI_BOOT_SERVICES *bs = systemTable->BootServices;
EFI_STATUS status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *graphicsProtocol;
SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
UINTN SizeOfInfo, sWidth, sHeight;
status = bs->LocateProtocol(&GraphicsOutputProtocolGUID, NULL,
(void**)&graphicsProtocol);
if (EFI_ERROR(status) || graphicsProtocol == NULL) {
conOut->OutputString(conOut, L"Failed to init gfx!\r\n");
return status;
}
conOut->ClearScreen(conOut);
//Switch to current mode so gfx is started.
status = graphicsProtocol->SetMode(graphicsProtocol, graphicsProtocol->Mode->Mode);
if (EFI_ERROR(status)) {
conOut->OutputString(conOut, L"Failed to set default mode!\r\n");
return status;
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL p;
p.Red = 200;
p.Green = 77;
p.Blue = 13;
graphicsProtocol->QueryMode(graphicsProtocol, graphicsProtocol->Mode->Mode, &SizeOfInfo, &info);
sWidth = info->HorizontalResolution;
sHeight = info->VerticalResolution;
status = graphicsProtocol->Blt(graphicsProtocol, &p, EfiBltVideoFill, 0, 0, 0, 0, sWidth, sHeight, 0);
while (1) {
conOut->OutputString(conOut, L"Some text that I want to display\r\n");
bs->Stall(500000);
}
return EFI_SUCCESS;
}
UEFI supports graphics output. It also supports text output (which can mean either output to a serial console, or text rendered to a graphical console, or both). But there is no defined way to interact between these in a controlled manner.
Applications that provide a graphical environment with text elements (BIOS configuration menu, GRUB) generally do this using their own frameworks to draw text on the graphical console using GRAPHICS_OUTPUT_PROTOCOL.
This is a short example of a text renderer using the font module from LVGL (which can be used standalone, replace #include "../../lv_conf.h" in the lv_font.h file with #define USE_LV_FONT_DEJAVU_20 8) and the Blt method from the GRAPHICS_OUTPUT_PROTOCOL
#include <Uefi.h>
#include <Library\UefiLib.h>
#include <Protocol\GraphicsOutput.h>
#include "lv_font.h"
#define LETTER_SPACE 2
#define WAIT_SECONDS 10
#define FONT &lv_font_dejavu_20
static EFI_BOOT_SERVICES *gBS;
static EFI_RUNTIME_SERVICES *gRT;
static EFI_GRAPHICS_OUTPUT_PROTOCOL *gGOP = (EFI_GRAPHICS_OUTPUT_PROTOCOL *)NULL;
static EFI_GRAPHICS_OUTPUT_BLT_PIXEL gWhite = { 255,255,255,0 };
static void _util_render_glyph(UINT32 x, UINT32 y, CHAR8 letter)
{
UINT32 height;
UINT32 width;
UINT32 pm_x;
UINT32 pm_y;
UINT32 index;
const UINT8* bitmap;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixelmap;
if (gGOP == NULL) {
return;
}
height = lv_font_get_height(FONT);
width = lv_font_get_width(FONT, letter);
// glyph is not defined in this font
if (width == 0) {
return;
}
bitmap = lv_font_get_bitmap(FONT, letter);
// using 8 bpp for simplicity
if (EFI_ERROR(gBS->AllocatePool(EfiLoaderData, height * width * sizeof(*pixelmap), (VOID**)&pixelmap))) {
return;
}
gBS->SetMem((VOID*)pixelmap, height * width * sizeof(*pixelmap), 0);
// get the current content of the framebuffer to allow 'transparent' blt operations
gGOP->Blt(gGOP, pixelmap, EfiBltVideoToBltBuffer, x, y, 0, 0, width, height, 0);
for (pm_y = 0; pm_y < height; pm_y++) {
for (pm_x = 0; pm_x < width; pm_x++) {
index = width * pm_y + pm_x;
if (bitmap[index] > 200) {
pixelmap[index].Red = 0;
pixelmap[index].Blue = 0;
pixelmap[index].Green = 0;
pixelmap[index].Reserved = 0;
}
else if (bitmap[index] > 100) {
pixelmap[index].Red = 105;
pixelmap[index].Blue = 105;
pixelmap[index].Green = 105;
pixelmap[index].Reserved = 0;
}
}
}
gGOP->Blt(gGOP, pixelmap, EfiBltBufferToVideo, 0, 0, x, y, width, height, 0);
gBS->FreePool(pixelmap);
}
static void _util_render_text(UINT32 x, UINT32 y, const CHAR8 *string)
{
UINT32 index;
UINTN length;
UINT32 scr_w;
UINT32 scr_h;
UINT32 str_x;
UINT32 gly_w;
UINT32 gly_h;
if (string == NULL) {
return;
}
if (gGOP == NULL) {
return;
}
scr_w = gGOP->Mode->Info->HorizontalResolution;
scr_h = gGOP->Mode->Info->VerticalResolution;
length = AsciiStrnLenS(string, 32);
gly_h = lv_font_get_height(FONT);
// check if the string can be printed
if ((y + gly_h) > scr_h) {
return;
}
if (x > scr_w) {
return;
}
// print the string glyph by glyph
str_x = x;
for (index = 0; index < length; index++) {
// check if the glyph can be printed
gly_w = lv_font_get_width(FONT, string[index]);
if ((str_x + gly_w) > scr_w) {
break;
}
// print the glyph
_util_render_glyph(str_x, y, string[index]);
// calculate the position of the next glyph
str_x += gly_w + LETTER_SPACE;
}
}
static void _util_fill_screen(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *color)
{
if (gGOP == NULL) {
return;
}
gGOP->Blt(gGOP, color, EfiBltVideoFill, 0, 0, 0, 0, gGOP->Mode->Info->HorizontalResolution, gGOP->Mode->Info->VerticalResolution, 0);
}
static void _util_wait(UINT32 seconds)
{
EFI_TIME time;
UINT8 current_second = 255;
UINT32 elapsed_seconds = 0;
//wait for some seconds
while (elapsed_seconds <= WAIT_SECONDS) {
if (!EFI_ERROR(gRT->GetTime(&time, (EFI_TIME_CAPABILITIES*)NULL))) {
if (current_second != time.Second) {
elapsed_seconds++;
current_second = time.Second;
}
}
else {
break;
}
CpuPause();
}
}
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS eRc;
gBS = SystemTable->BootServices;
gRT = SystemTable->RuntimeServices;
eRc = gBS->LocateProtocol(
&gEfiGraphicsOutputProtocolGuid,
NULL,
(VOID**)&gGOP);
if (EFI_ERROR(eRc) || gGOP == NULL) {
return EFI_SUCCESS;
}
_util_fill_screen(&gWhite);
_util_render_text(0, 0, "HELLO WORLD!");
_util_wait(WAIT_SECONDS);
return EFI_SUCCESS;
}
I tested it on a pc and on a mac it runs on both. Using the tools provided by LVGL on their website you can use any font you want.
If you target MacEFI specifically, you'll need an additional protocol call to force the console into text mode, like this.
I am trying to write some filters for FFMPEG and I would like to use some already created filters for preprocessing planes. How can one do that? I have a standard loop for plane processing:
int p;
if (av_frame_is_writable(in)) {
out = in;
} else {
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out) {
av_frame_free(&in);
return AVERROR(ENOMEM);
}
av_frame_copy_props(out, in);
}
// processing planes
for (p = 0; p < filter->nb_planes; p++) {
pad_plane();
transpose_plane(); // etc...
apply_my_filter();
}
if (out != in)
av_frame_free(&in);
return ff_filter_frame(outlink, out);
I do believe padding and transposing is already possible in FFMPEG's other libraries. What is a common way to do it so I would be able to use them inside mine filter code?
i am programming my differential drive mobile robot (e-puck) to move to a certain coordinate with specific orientation. the robot has no problem reaching the coordinate, however when it reaches the coordinate, it cannot settle on the specific orientation and keeping "spinning" on the spot searching for the orientation, do anyone have any prior experience in this? i am stuck in this issue for very long and really hope someone knows why. the relevant part of the code is pasted below.
static void step() {
if (wb_robot_step(TIME_STEP)==-1) {
wb_robot_cleanup();
exit(EXIT_SUCCESS);
}
}
.
.
.
.
.
static void set_speed(int l, int r)
{
speed[LEFT] = l;
speed[RIGHT] = r;
if (pspeed[LEFT] != speed[LEFT] || pspeed[RIGHT] != speed[RIGHT]) {
wb_differential_wheels_set_speed(speed[LEFT], speed[RIGHT]);
}
}
.
.
.
.
static void goto_position1(float x, float y, float theta)
{
if (VERBOSE > 0) printf("Going to (%f, %f, %f)\n",x,y,theta);
// Set a target position
odometry_goto_set_goal(&og, x, y, theta);
// Move until the robot is close enough to the target position
while (og.result.atgoal == 0) {
// Update position and calculate new speeds
odometry_track_step(og.track);
odometry_goto_step(&og);
// Set the wheel speed
set_speed(og.result.speed_left, og.result.speed_right);
printf("%f",ot.result.theta);
print_position();
step();
} //after exiting while loop speed will be zero
og.result.speed_left = 0;
og.result.speed_right = 0;
if (((og.result.speed_left == 0) && (og.result.speed_right == 0)) )
og.result.atgoal = 1;
return;
}
.
.
.
int main(){
//initialisation
while (wb_robot_step(TIME_STEP) != -1) {
goto_position1(0.0000000001,0.00000000001,PI/4);
}
return 0;
}
I do not have the benefit of knowing what the contents of your og struct are, so assuming there are members that provide current position information, (I will assume they are posx & posy), you should should have a test statement sometime just after having read the latest position, something like this:
[EDIT] re-positioned set_speed()
while (og.result.atgoal == 0)
{
// Update position and calculate new speeds
odometry_track_step(og.track);
odometry_goto_step(&og);
if(((og.result.posx - x) > 3) || (og.result.posy - y) > 3) //(distance assumed in mm)
{
//then report position, continue to make adjustments and navigate
printf("%f",ot.result.theta);
print_position();
// Set the wheel speed
set_speed(og.result.speed_left, og.result.speed_right);
step();
}
else
{
//set all speeds to 0
//report position.
//clear appropriate struct members and leave loop
}
} //after exiting while loop speed will be zero
i finally figured out what is wrong, it is because i could not get out of the while loop and the robot cannot stop searching for the orientation. Thanks for the inspiration.
I am trying to manipulate pixel using sdl and manage to read them up now. Below is my sample code. When I print I this printf("\npixelvalue is is : %d",MyPixel); I get values like this
11275780
11275776
etc
I know these are not in hex form but how to manipulate say I want to filter just the blue colors out? Secondly after manipulation how to generate the new image?
#include "SDL.h"
int main( int argc, char* argv[] )
{
SDL_Surface *screen, *image;
SDL_Event event;
Uint8 *keys;
int done = 0;
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
printf("Can't init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
SDL_WM_SetCaption("sample1", "app.ico");
/* obtain the SDL surfance of the video card */
screen = SDL_SetVideoMode(640, 480, 24, SDL_HWSURFACE);
if (screen == NULL)
{
printf("Can't set video mode: %s\n", SDL_GetError());
exit(1);
}
printf("Loading here");
/* load BMP file */
image = SDL_LoadBMP("testa.bmp");
Uint32* pixels = (Uint32*)image->pixels;
int width = image->w;
int height = image->h;
printf("Widts is : %d",image->w);
for(int iH = 1; iH<=height; iH++)
for(int iW = 1; iW<=width; iW++)
{
printf("\nIh is : %d",iH);
printf("\nIw is : %d",iW);
Uint32* MyPixel = pixels + ( (iH-1) + image->w ) + iW;
printf("\npixelvalue is is : %d",MyPixel);
}
if (image == NULL) {
printf("Can't load image of tux: %s\n", SDL_GetError());
exit(1);
}
/* Blit image to the video surface */
SDL_BlitSurface(image, NULL, screen, NULL);
SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
/* free the image if it is no longer needed */
SDL_FreeSurface(image);
/* process the keyboard event */
while (!done)
{
// Poll input queue, run keyboard loop
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{
done = 1;
break;
}
}
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_q])
{
done = 1;
}
// Release CPU for others
SDL_Delay(100);
}
// Release memeory and Quit SDL
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}
Use SDL_MapRGB and SDL_MapRGBA to sort colors out. SDL will filter it out for you, based on surface format.
Just like this:
Uint32 rawpixel = getpixel(surface, x, y);
Uint8 red, green, blue;
SDL_GetRGB(rawpixel, surface->format, &red, &green, &blue);
You are printing the value of the pointer MyPixel. To get the value you have to dereference the pointer to the pixel value like this: *MyPixel
Then the printf would look like this:
printf("\npixelvalue is : %d and the address of that pixel is: %p\n",*MyPixel , MyPixel);
Other errors:
Your for loops are incorrect. You should loop from 0 to less than width or height, or else you will read uninitialized memory.
You didn't lock the surface. Although you are only reading the pixels and nothing should go wrong it is still not correct.
Test for correctness if the image pointer comes after you are already using the pointer. Put the test right after the initialization.
If I recall correctly I used sdl_gfx for pixel manipulation.
It also contains function like drawing a circle, oval etc.
I am writing a gif decoder, This image is an animated image.When I write the first frame, it displays fine. When, I display the second frame, it displays only the changed pixels. Other pixels are automatically changed to black. I don't know why?.
My first frame has the complete picture.
The second frame has again only the pixel changed and it contains the rest of the unchanged pixels.
Now, when I draw the second buffer, it redraws the unchanged pixels also. And the unchanged pixels are drawn as black ( or precisely in monitor I see these unchanged pixels are absent). That's when it has to draw the second frame.It draws the changed pixels( which is correct), but it re-draws the unchanged pixel as well. And this unchanged pixel are seen as a black ( that is no color). I feel it is a refreshing issue. Or It could be something else. Help is appreciated.
Required: It should redraw the complete image.
In short, this is the snippet of my function.
Unfortunately, it clears off the previous display - linux framebuffer.
I want to stop clearning the linux framebuffer.
here is the complete file.
/** This is using the Direct Fb calls here; and is tightly coupled with Linux Framebuffer **/
static int fbfd = 0;
static struct fb_var_screeninfo vinfo;
static struct fb_fix_screeninfo finfo;
static long int screensize = 0;
static char *fbp = 0;
static int x = 0, y = 0;
static long int location = 0;
/** This is a clone to linux Frame buffer, and will be called to dump on Framebuffer **/
char *local_display_mem;
/** local functions **/
static void SetBackground(FrameData *tempInfo);
static void SetPixel(char *fbp, unsigned int x, unsigned int y, Byte red, Byte green, Byte blue);
/** This is the entry function to initialize the display **/
void display_init()
{
// Open the file for reading and writing
fbfd = open("/dev/fb0", O_RDWR);
if (fbfd == -1)
{
perror("cannot open framebuffer device");
exit(1);
}
#ifdef DEBUG
printf("The framebuffer device was opened successfully.\n");
#endif
/** Read the Screen Information **/
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1)
{
perror("Driver error-- reading fixed information");
exit(1);
}
// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1)
{
perror("Error reading variable information");
exit(1);
}
#ifdef DEBUG
printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
#endif
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
local_display_mem = (char*)malloc(screensize);
if ((int)fbp == -1)
{
perror("Error: mmap failed\r\n");
exit(1);
}
#ifdef DEBUG
printf("The framebuffer device was mapped to memory successfully.\n");
#endif
printf("Shreyas..Display Initialized..\r\n");
//munmap(fbp, screensize);
//close(fbfd);
}
/** This function is called by gif_read to display the Image **/
void Display(FrameData *FrameInfo)
{
short int ImageStartX = 0;
short int ImageStartY = 0;
int Index = 0;
printf("\r\n INFO: Display Called.\r\n");
while(1)
{
Index = 0;
ImageStartX = (FrameInfo->frameScreenInfo.LeftPosition);
ImageStartY = (FrameInfo->frameScreenInfo.TopPosition);
while(ImageStartY < ((FrameInfo->frameScreenInfo.ImageHeight)+(FrameInfo->frameScreenInfo.TopPosition)))
{
while(ImageStartX < ((FrameInfo->frameScreenInfo.ImageWidth)+(FrameInfo->frameScreenInfo.LeftPosition)))
{
if(FrameInfo->frame[Index] != FrameInfo->transperencyindex)
{
SetPixel(local_display_mem,ImageStartX,ImageStartY,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue);
}
Index++;
ImageStartX++;
}
ImageStartY++;
ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
}
printf("INFO:..Dumping Framebuffer\r\n");
memcpy(fbp,local_display_mem,screensize);
/** Tune this multiplication to meet the right output on the display **/
usleep((FrameInfo->InterFrameDelay)*100000);
if( FrameInfo->DisposalMethod == 2)
{
printf("set the Background\r\n");
SetBackground(FrameInfo);
}
FrameInfo = FrameInfo->Next;
}
}
static void SetBackground(FrameData *tempInfo)
{
unsigned int ImageStartX=0;
unsigned int ImageStartY=0;
ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
ImageStartY=(tempInfo->frameScreenInfo.TopPosition);
while(ImageStartY<(tempInfo->frameScreenInfo.ImageHeight))
{
while(ImageStartX<(tempInfo->frameScreenInfo.ImageWidth))
{
SetPixel(local_display_mem,ImageStartX,ImageStartY,255,255,255);
ImageStartX++;
}
ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
ImageStartY++;
}
}
static void SetPixel(char *fbp_lc, unsigned int x, unsigned int y, Byte red, Byte green, Byte blue)
{
//printf("Shreyas..set pixel called\r\n");
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
if (vinfo.bits_per_pixel == 32)
{
*(fbp_lc + location) = blue; // Some blue
*(fbp_lc + location + 1) = green; // A little green
*(fbp_lc + location + 2) = red; // A lot of red
*(fbp_lc + location + 3) = 0; // No transparency
//location += 4;
}
else
{ //assume 16bpp
unsigned short int t = red<<11 | green << 5 | blue;
*((unsigned short int*)(fbp_lc + location)) = t;
}
//printf("Shreyas..set pixel exit called\r\n");
}
/** This is windows version of display function, and it works correctly.
void Display(FrameData *FrameInfo)
{
short int ImageStartX=0;
short int ImageStartY=0;
int Index=0;
DisplayCntrl=GetDC(hWnd);
printf("Shreyas.. Display Init is called\r\n");
//display_init();
while(1)
{
Index=0;
ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
ImageStartY=(FrameInfo->frameScreenInfo.TopPosition);
while(ImageStartY<((FrameInfo->frameScreenInfo.ImageHeight)+(FrameInfo->frameScreenInfo.TopPosition)))
{
while(ImageStartX<((FrameInfo->frameScreenInfo.ImageWidth)+(FrameInfo->frameScreenInfo.LeftPosition)))
{
if(FrameInfo->frame[Index]!=FrameInfo->transperencyindex)
SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue));
Index++;
ImageStartX++;
}
ImageStartY++;
ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
}
Sleep((FrameInfo->InterFrameDelay*10));
WaitForSingleObject(hWnd,10);
if( FrameInfo->DisposalMethod==2)
{
SETBACKGROUND(FrameInfo);
}
FrameInfo=FrameInfo->Next;
}
}
This is the windows version of the same code.
extern hWnd;
HDC DisplayCntrl;
void SETBACKGROUND(FrameData *tempInfo)
{
unsigned int ImageStartX=0;
unsigned int ImageStartY=0;
ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
ImageStartY=(tempInfo->frameScreenInfo.TopPosition);
while(ImageStartY<(tempInfo->frameScreenInfo.ImageHeight))
{
while(ImageStartX<(tempInfo->frameScreenInfo.ImageWidth))
{
SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(255,255,255));
ImageStartX++;
}
ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
ImageStartY++;
}
}
void Display(FrameData *FrameInfo)
{
short int ImageStartX=0;
short int ImageStartY=0;
int Index=0;
DisplayCntrl=GetDC(hWnd);
printf("the size of short int is %d",sizeof(short int));
while(1)
{
Index=0;
ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
ImageStartY=(FrameInfo->frameScreenInfo.TopPosition);
while(ImageStartY<((FrameInfo->frameScreenInfo.ImageHeight)+(FrameInfo->frameScreenInfo.TopPosition)))
{
while(ImageStartX<((FrameInfo->frameScreenInfo.ImageWidth)+(FrameInfo->frameScreenInfo.LeftPosition)))
{
if(FrameInfo->frame[Index]!=FrameInfo->transperencyindex)
{
SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue));
}
Index++;
ImageStartX++;
}
ImageStartY++;
ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
}
Sleep((FrameInfo->InterFrameDelay*10));
WaitForSingleObject(hWnd,10);
if( FrameInfo->DisposalMethod==2)
{
SETBACKGROUND(FrameInfo);
}
FrameInfo=FrameInfo->Next;
}
}
Since you use a local memory buffer local_display_mem, it doesn't matter if somebody would clear the framebuffer - the memcpy will overwrite every pixel.
This means that the condition FrameInfo->frame[Index] != FrameInfo->transperencyindex is always true for some reason since that would cause the algorithm to set each pixel again instead of only updating the changed pixels.