mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-25 02:17:03 +00:00
No need to use fmemopen
This commit is contained in:
parent
79f3692f1e
commit
c2b4df0666
4 changed files with 21 additions and 25 deletions
|
|
@ -344,6 +344,22 @@ print_png_read_error(png_read_data *d, const char *code, const char* msg) {
|
|||
d->error.used += snprintf(d->error.buf + d->error.used, d->error.capacity - d->error.used, "%s: %s ", code, msg);
|
||||
}
|
||||
|
||||
bool
|
||||
png_from_data(void *png_data, size_t png_data_sz, const char *path_for_error_messages, uint8_t** data, unsigned int* width, unsigned int* height, size_t* sz) {
|
||||
png_read_data d = {.err_handler=print_png_read_error};
|
||||
inflate_png_inner(&d, png_data, png_data_sz);
|
||||
if (!d.ok) {
|
||||
log_error("Failed to decode PNG image at: %s with error: %s", path_for_error_messages, d.error.used > 0 ? d.error.buf : "");
|
||||
free(d.decompressed); free(d.row_pointers); free(d.error.buf);
|
||||
return false;
|
||||
}
|
||||
*data = d.decompressed;
|
||||
free(d.row_pointers); free(d.error.buf);
|
||||
*sz = d.sz;
|
||||
*height = d.height; *width = d.width;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
png_from_file_pointer(FILE *fp, const char *path_for_error_messages, uint8_t** data, unsigned int* width, unsigned int* height, size_t* sz) {
|
||||
size_t capacity = 16*1024, pos = 0;
|
||||
|
|
@ -367,19 +383,9 @@ png_from_file_pointer(FILE *fp, const char *path_for_error_messages, uint8_t** d
|
|||
return false;
|
||||
}
|
||||
}
|
||||
png_read_data d = {.err_handler=print_png_read_error};
|
||||
inflate_png_inner(&d, buf, pos);
|
||||
bool ret = png_from_data(buf, pos, path_for_error_messages, data, width, height, sz);
|
||||
free(buf);
|
||||
if (!d.ok) {
|
||||
log_error("Failed to decode PNG image at: %s with error: %s", path_for_error_messages, d.error.used > 0 ? d.error.buf : "");
|
||||
free(d.decompressed); free(d.row_pointers); free(d.error.buf);
|
||||
return false;
|
||||
}
|
||||
*data = d.decompressed;
|
||||
free(d.row_pointers); free(d.error.buf);
|
||||
*sz = d.sz;
|
||||
*height = d.height; *width = d.width;
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -188,5 +188,6 @@ void grman_remove_all_cell_images(GraphicsManager *self);
|
|||
void gpu_data_for_image(ImageRenderData *ans, float left, float top, float right, float bottom);
|
||||
bool png_from_file_pointer(FILE* fp, const char *path, uint8_t** data, unsigned int* width, unsigned int* height, size_t* sz);
|
||||
bool png_path_to_bitmap(const char *path, uint8_t** data, unsigned int* width, unsigned int* height, size_t* sz);
|
||||
bool png_from_data(void *png_data, size_t png_data_sz, const char *path_for_error_messages, uint8_t** data, unsigned int* width, unsigned int* height, size_t* sz);
|
||||
bool scan_active_animations(GraphicsManager *self, const monotonic_t now, monotonic_t *minimum_gap, bool os_window_context_set);
|
||||
void scale_rendered_graphic(ImageRenderData*, float xstart, float ystart, float x_scale, float y_scale);
|
||||
|
|
|
|||
|
|
@ -1154,14 +1154,7 @@ pyset_background_image(PyObject *self UNUSED, PyObject *args) {
|
|||
if (!bgimage) return PyErr_NoMemory();
|
||||
bool ok;
|
||||
if (png_data) {
|
||||
FILE *fp = fmemopen(png_data, png_data_size, "r");
|
||||
if (fp == NULL) {
|
||||
PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
|
||||
free(bgimage);
|
||||
return NULL;
|
||||
}
|
||||
ok = png_from_file_pointer(fp, path, &bgimage->bitmap, &bgimage->width, &bgimage->height, &size);
|
||||
fclose(fp);
|
||||
ok = png_from_data(png_data, png_data_size, path, &bgimage->bitmap, &bgimage->width, &bgimage->height, &size);
|
||||
} else {
|
||||
ok = png_path_to_bitmap(path, &bgimage->bitmap, &bgimage->width, &bgimage->height, &size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,11 +66,7 @@ find_or_create_window_logo(WindowLogoTable *head, const char *path, void *png_da
|
|||
if (png_data == NULL) {
|
||||
ok = png_path_to_bitmap(path, &s->wl.bitmap, &s->wl.width, &s->wl.height, &size);
|
||||
} else {
|
||||
FILE *fp = fmemopen(png_data, png_data_size, "r");
|
||||
if (fp != NULL) {
|
||||
ok = png_from_file_pointer(fp, path, &s->wl.bitmap, &s->wl.width, &s->wl.height, &size);
|
||||
fclose(fp);
|
||||
}
|
||||
ok = png_from_data(png_data, png_data_size, path, &s->wl.bitmap, &s->wl.width, &s->wl.height, &size);
|
||||
}
|
||||
if (ok) s->wl.load_from_disk_ok = true;
|
||||
s->refcnt++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue