Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <assert.h>
  3. #include <stdint.h>
  4.  
  5. uint16_t rgb888torgb565(uint8_t *rgb888Pixel)
  6. {
  7. uint8_t red = rgb888Pixel[0];
  8. uint8_t green = rgb888Pixel[1];
  9. uint8_t blue = rgb888Pixel[2];
  10.  
  11. uint16_t b = (blue >> 3) & 0x1f;
  12. uint16_t g = ((green >> 2) & 0x3f) << 5;
  13. uint16_t r = ((red >> 3) & 0x1f) << 11;
  14.  
  15. return (uint16_t) (r | g | b);
  16. }
  17.  
  18. int main(void) {
  19.  
  20. FILE *fb = fopen("input.rgb", "rb");
  21. assert(fb);
  22.  
  23. FILE *tmp = fopen("output.rgb565", "wb");
  24. assert(tmp);
  25.  
  26. uint8_t i[3];
  27. while (!feof(fb)) {
  28. fread(&i, sizeof(uint8_t), 3, fb);
  29. uint16_t x = rgb888torgb565(i);
  30. fwrite(&x, sizeof(uint16_t), 1, tmp);
  31. }
  32.  
  33. fclose(fb);
  34. fclose(tmp);
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement