Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<char> data;
- int where = 0;
- int img_read(void *user, char *dat, int size) {
- //printf("r%d\n", size);
- int amount = size;
- memcpy(dat, data.data() + where, amount);
- where += amount;
- return amount;
- }
- void img_skip (void *user, int n) {
- printf("s%d\n", n);
- where += n;
- }
- int img_eof (void *user) {
- printf("e\n");
- return 0;
- }
- int main() {
- auto start = std::chrono::system_clock::now();
- int w = 0, h = 0;
- auto f = std::ifstream("big.jpg", std::ios::binary|std::ios::ate);
- data.resize(f.tellg());
- f.seekg(0);
- f.read(data.data(), data.size());
- printf("%ld\n", data.size());
- //uint8_t *data = stbi_load("big.jpg", &w, &h, 0, 3);
- stbi_io_callbacks cb = {
- img_read, img_skip, img_eof
- };
- uint8_t *res = stbi_load_from_callbacks(&cb, nullptr, &w, &h, nullptr, 3);
- printf("%p\n", res);
- auto end = std::chrono::system_clock::now();
- printf("%f\n", std::chrono::duration<double>(end-start).count());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement