gcc 2.95.x fix.
[swftools.git] / avi2swf / videoreader_vfw.cc
index 2e0c787..b40c378 100644 (file)
@@ -62,7 +62,7 @@ static bool videoreader_vfw_eof(videoreader_t* vr)
     return (i->video_pos >= i->video_end);
 }
 
-static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width, const int dest_height)
+static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width, const int dest_height, int flip)
 {
     UCHAR*data = (UCHAR*)(bi+1); // actual bitmap data starts after the header
 
@@ -89,14 +89,14 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width
     int linex = ((bytesperpixel/8)+3)&~3;
     memset(dest, 255, dest_width*dest_height*4);//pre-fill alpha channel
 
-    int starty = i->flip? 0 : dest_height-1;
-    int endy   = i->flip? dest_height-1 : 0;
-    int yinc   = i->flip? 1 : -1;
+    const int starty = flip? 0 : dest_height-1;
+    const int endy   = flip? dest_height : -1;
+    const int yinc   = flip? 1 : -1;
 
     if(bi->biBitCount==1) {
        UCHAR*img = data;
        int y;
-       for(y=starty;y<=endy;y+=yinc) {
+       for(y=starty;y!=endy;y+=yinc) {
            UCHAR*line = &img[linex*y];
            int x;
            for(x=0;x<dest_width;x++) {
@@ -107,7 +107,7 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width
        UCHAR*img = &data[bi->biClrUsed*4];
        UCHAR*pal = data;
        int y;
-       for(y=starty;y<=endy;y+=yinc) {
+       for(y=starty;y!=endy;y+=yinc) {
            UCHAR*line = &img[linex*y];
            int x;
            for(x=0;x<dest_width/2;x++) {
@@ -120,7 +120,7 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width
        UCHAR*img = &data[bi->biClrUsed*4];
        UCHAR*pal = data;
        int y;
-       for(y=starty;y<=endy;y+=yinc) {
+       for(y=starty;y!=endy;y+=yinc) {
            UCHAR*line = &img[linex*y];
            int x;
            for(x=0;x<dest_width;x++) {
@@ -131,7 +131,7 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width
     } else if(bi->biBitCount==24) {
        UCHAR*img = data;
        int y;
-       for(y=starty;y<=endy;y+=yinc) {
+       for(y=starty;y!=endy;y+=yinc) {
            UCHAR*line = &img[linex*y];
            int x;
            for(x=0;x<dest_width;x++) {
@@ -142,7 +142,7 @@ static int bitmap_to_rgba(BITMAPINFOHEADER*bi, void*buffer, const int dest_width
     } else if(bi->biBitCount==32) {
        UCHAR*img = data;
        int y;
-       for(y=starty;y<=endy;y+=yinc) {
+       for(y=starty;y!=endy;y+=yinc) {
            UCHAR*line = &img[linex*y];
            int x;
            for(x=0;x<dest_width;x++) {
@@ -175,7 +175,7 @@ static int videoreader_vfw_getimage(videoreader_t* vr, void*buffer)
        return 0;
     }
     
-    if(!bitmap_to_rgba(bi, buffer, i->width, i->height)) {
+    if(!bitmap_to_rgba(bi, buffer, i->width, i->height, i->flip)) {
        fprintf(stderr, "couldn't convert bitmap to RGBA.\n");
        return 0;
     }