Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. std::vector<char> data;
  2. int where = 0;
  3.  
  4. int img_read(void *user, char *dat, int size) {
  5. //printf("r%d\n", size);
  6. int amount = size;
  7. memcpy(dat, data.data() + where, amount);
  8. where += amount;
  9. return amount;
  10. }
  11.  
  12.  
  13. void img_skip (void *user, int n) {
  14. printf("s%d\n", n);
  15. where += n;
  16. }
  17.  
  18. int img_eof (void *user) {
  19. printf("e\n");
  20. return 0;
  21. }
  22.  
  23. int main() {
  24. auto start = std::chrono::system_clock::now();
  25. int w = 0, h = 0;
  26. auto f = std::ifstream("big.jpg", std::ios::binary|std::ios::ate);
  27. data.resize(f.tellg());
  28. f.seekg(0);
  29. f.read(data.data(), data.size());
  30. printf("%ld\n", data.size());
  31.  
  32. //uint8_t *data = stbi_load("big.jpg", &w, &h, 0, 3);
  33. stbi_io_callbacks cb = {
  34. img_read, img_skip, img_eof
  35. };
  36.  
  37. uint8_t *res = stbi_load_from_callbacks(&cb, nullptr, &w, &h, nullptr, 3);
  38. printf("%p\n", res);
  39. auto end = std::chrono::system_clock::now();
  40. printf("%f\n", std::chrono::duration<double>(end-start).count());
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement