Flip the image during conversion 45/103245/1 accepted/tizen/common/20161208.135359 accepted/tizen/mobile/20161209.004903 accepted/tizen/wearable/20161209.004923 submit/tizen/20161208.010648
authorVarun <tallytalwar@gmail.com>
Wed, 7 Dec 2016 20:42:21 +0000 (15:42 -0500)
committerVarun <tallytalwar@gmail.com>
Wed, 7 Dec 2016 20:42:21 +0000 (15:42 -0500)
saves an extra iteration over the entire image

Change-Id: I1eb2f4b59b11ec7f67fc14c5657ae86db76ed75a

src/mapzen/tangram_view.cpp

index fd09ffd..7945270 100644 (file)
@@ -595,29 +595,18 @@ mapzen_error_e TangramView::getBitmapMarkerImage(maps_view_object_h object, unsi
                        break;
                }
 
-               // convert data from rgba to bgra
+               // convert data from rgba to bgra (also flip the image)
                for (int i = 0; i < imgHeight; i++) {
                        for (int j = 0; j < imgWidth; j++) {
                                int offset = ((i * imgWidth) + j) * 4;
-                               *(imgData + offset)     = *(srcData + offset + 2);
-                               *(imgData + offset + 1) = *(srcData + offset + 1);
-                               *(imgData + offset + 2) = *(srcData + offset);
-                               *(imgData + offset + 3) = *(srcData + offset + 3);
+                               int offset_flip = (((imgHeight - 1 - i) * imgWidth) + j) * 4;
+                               *(imgData + offset_flip)        = *(srcData + offset + 2);
+                               *(imgData + offset_flip + 1)    = *(srcData + offset + 1);
+                               *(imgData + offset_flip + 2)    = *(srcData + offset);
+                               *(imgData + offset_flip + 3)    = *(srcData + offset + 3);
                        }
                }
 
-               // flip converted image
-               unsigned int *flippedImg = (unsigned int*)imgData;
-               unsigned int temp;
-               for (int i = 0; i < (imgHeight>>1); i++) {
-                       unsigned int* lower = flippedImg + (i * imgWidth);
-                       unsigned int* upper = flippedImg + ((imgHeight - i - 1) * imgWidth);
-                       for (int j = 0; j < imgWidth; j++) {
-                               temp = lower[j];
-                               lower[j] = upper[j];
-                               upper[j] = temp;
-                       }
-               }
        } while (0);
 
        return (mapzen_error_e)convert_maps_error_to_mapzen_error(error);