Skip to content

Instantly share code, notes, and snippets.

@paniq
Created August 27, 2019 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/803b18998c1b94d77d294e895ac4c68c to your computer and use it in GitHub Desktop.
Save paniq/803b18998c1b94d77d294e895ac4c68c to your computer and use it in GitHub Desktop.
#ifndef STBI_INCLUDE_STB_IMAGE_EX_H
#define STBI_INCLUDE_STB_IMAGE_EX_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned char stbi_uc;
extern void stbi_flip_y(int w, int h, int comp, stbi_uc *data);
extern void stbi_flip_y_f(int w, int h, int comp, float *data);
#ifdef __cplusplus
}
#endif
//
//
//// end header file /////////////////////////////////////////////////////
#endif // STBI_INCLUDE_STB_IMAGE_EX_H
#ifndef STBI_HEADER_EX_FILE_ONLY
#include <stdlib.h>
void stbi_flip_y(int w, int h, int comp, stbi_uc *data)
{
stbi_uc t;
size_t y;
size_t i;
size_t stride = w * comp;
stbi_uc *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;
}
}
}
void stbi_flip_y_f(int w, int h, int comp, float *data)
{
float t;
size_t y;
size_t i;
size_t stride = w * comp;
float *out = data;
for (y = 0; y < (h>>1); ++y) {
float *p1 = out + y * stride;
float *p2 = out + (h-1-y) * stride;
for (i = 0; i < stride; ++i) {
t = p1[i];
p1[i] = p2[i];
p2[i] = t;
}
}
}
#endif // STBI_HEADER_EX_FILE_ONLY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment