Commits

Leonard Ritter committed 3b18738

simplified stbi_flip_y

  • Participants
  • Parent commits 83619b6

Comments (0)

Files changed (1)

File stbimage/defs/stb_image.c

 
 void stbi_flip_y(int w, int h, int comp, stbi_uc *data)
 {
-   int y;
+   stbi_uc t;
+   size_t y;
+   size_t i;
    size_t stride = w * comp;
-   stbi_uc *row = malloc(stride * h);
-   stbi_uc *data_end = &data[(h-1) * stride];
-
-   for (y = 0; y < (h/2); ++y) {
-      memcpy(row, data, stride);
-      memcpy(data, data_end, stride);
-      memcpy(data_end, row, stride);
-      data += stride;
-      data_end -= stride;
+   uint8 *out = data;
+
+   for (y = 0; y < (h>>1); ++y) {
+      stbi_uc *p1 = out + y * stride;
+      stbi_uc *p2 = out + (h-1-y) * stride;
+      for (i = 0; i < stride; ++i) {
+         t = p1[i];
+         p1[i] = p2[i];
+         p2[i] = t;       
+      } 
    }
-   free(row);
 }
 
 #endif // STBI_HEADER_FILE_ONLY