mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
remove unused png mmap code
This commit is contained in:
parent
b2fb50fc39
commit
7ace56cee6
107
src/lib/png.c
107
src/lib/png.c
@ -1,7 +1,4 @@
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#ifndef __MINGW64__
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
@ -189,110 +186,6 @@ write_ihdr(int rows, int cols, unsigned char buf[static 25]){
|
|||||||
return CHUNK_DESC_BYTES + IHDR_DATA_BYTES; // 25
|
return CHUNK_DESC_BYTES + IHDR_DATA_BYTES; // 25
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __MINGW64__
|
|
||||||
// write 1+ IDAT chunks at |buf| from the deflated |dlen| bytes at |data|.
|
|
||||||
static size_t
|
|
||||||
write_idats(unsigned char* buf, const unsigned char* data, size_t dlen){
|
|
||||||
static const char ctype[] = "IDAT";
|
|
||||||
uint32_t written = 0;
|
|
||||||
uint32_t dwritten = 0;
|
|
||||||
while(dlen){
|
|
||||||
uint32_t thischunk = dlen;
|
|
||||||
if(thischunk > CHUNK_MAX_DATA){
|
|
||||||
thischunk = CHUNK_MAX_DATA;
|
|
||||||
}
|
|
||||||
uint32_t nclen = htonl(thischunk);
|
|
||||||
memcpy(buf + written, &nclen, 4);
|
|
||||||
memcpy(buf + written + 4, ctype, 4);
|
|
||||||
memcpy(buf + written + 8, data + dwritten, thischunk);
|
|
||||||
uint32_t crc = chunk_crc(buf + written);
|
|
||||||
memcpy(buf + written + 8 + thischunk, &crc, 4);
|
|
||||||
dlen -= thischunk;
|
|
||||||
dwritten += thischunk;
|
|
||||||
written += CHUNK_DESC_BYTES + thischunk;
|
|
||||||
}
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the constant 12B IEND chunk at |buf|. it contains no data.
|
|
||||||
static size_t
|
|
||||||
write_iend(unsigned char* buf){
|
|
||||||
memcpy(buf, IEND, CHUNK_DESC_BYTES);
|
|
||||||
return CHUNK_DESC_BYTES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write a PNG at the provided buffer |buf| using the ncvisual ncv, the
|
|
||||||
// deflated data |deflated| of |dlen| bytes. |buf| must be large enough to
|
|
||||||
// write all necessary data; it ought have been sized with compute_png_size().
|
|
||||||
static size_t
|
|
||||||
create_png(int rows, int cols, void* buf, const unsigned char* deflated,
|
|
||||||
size_t dlen){
|
|
||||||
size_t written = sizeof(PNGHEADER) - 1;
|
|
||||||
memcpy(buf, PNGHEADER, written);
|
|
||||||
size_t r = write_ihdr(rows, cols, (unsigned char*)buf + written);
|
|
||||||
written += r;
|
|
||||||
r = write_idats((unsigned char*)buf + written, deflated, dlen);
|
|
||||||
written += r;
|
|
||||||
r = write_iend((unsigned char*)buf + written);
|
|
||||||
written += r;
|
|
||||||
return written;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline size_t
|
|
||||||
mmap_round_size(size_t s){
|
|
||||||
const size_t pgsize = 4096; // FIXME get page size, round up s
|
|
||||||
return (s + pgsize - 1) / pgsize * pgsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write a PNG, creating the buffer ourselves. it must be munmapped. the
|
|
||||||
// resulting length is written to *bsize on success (the file/map might be
|
|
||||||
// larger than this, but the end is immaterial padding). returns MMAP_FAILED
|
|
||||||
// on a failure. if |fd| is negative, an anonymous map will be made. |rows|
|
|
||||||
// and |cols| are in pixels; |rowstride| is in bytes.
|
|
||||||
void* create_png_mmap(const void* data, int rows, int rowstride, int cols,
|
|
||||||
size_t* bsize, int fd){
|
|
||||||
void* deflated;
|
|
||||||
size_t dlen;
|
|
||||||
size_t mlen;
|
|
||||||
*bsize = compute_png_size(data, rows, rowstride, cols, &deflated, &dlen);
|
|
||||||
if(deflated == NULL){
|
|
||||||
logerror("Couldn't compress to %d\n", fd);
|
|
||||||
return MAP_FAILED;
|
|
||||||
}
|
|
||||||
mlen = mmap_round_size(*bsize);
|
|
||||||
if(mlen == 0){
|
|
||||||
return MAP_FAILED;
|
|
||||||
}
|
|
||||||
if(fd >= 0){
|
|
||||||
if(ftruncate(fd, mlen) < 0){
|
|
||||||
logerror("Couldn't set size of %d to %zuB (%s)\n", fd, mlen, strerror(errno));
|
|
||||||
free(deflated);
|
|
||||||
return MAP_FAILED;
|
|
||||||
}
|
|
||||||
loginfo("Set size of %d to %zuB\n", fd, mlen);
|
|
||||||
}
|
|
||||||
// FIXME hugetlb?
|
|
||||||
void* map = mmap(NULL, mlen, PROT_WRITE | PROT_READ, MAP_SHARED |
|
|
||||||
(fd >= 0 ? 0 : MAP_ANONYMOUS), fd, 0);
|
|
||||||
if(map == MAP_FAILED){
|
|
||||||
logerror("Couldn't get %zuB map for %d (%s)\n", mlen, fd, strerror(errno));
|
|
||||||
free(deflated);
|
|
||||||
return MAP_FAILED;
|
|
||||||
}
|
|
||||||
size_t w = create_png(rows, cols, map, deflated, dlen);
|
|
||||||
free(deflated);
|
|
||||||
loginfo("Wrote %zuB PNG to %d\n", w, fd);
|
|
||||||
if(fd >= 0){
|
|
||||||
if(ftruncate(fd, w) < 0){
|
|
||||||
logerror("Couldn't set size of %d to %zuB (%s)\n", fd, w, strerror(errno));
|
|
||||||
munmap(map, mlen);
|
|
||||||
return MAP_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct b64ctx {
|
struct b64ctx {
|
||||||
unsigned char src[3]; // try to convert three at a time
|
unsigned char src[3]; // try to convert three at a time
|
||||||
size_t srcidx; // how many src bytes we have
|
size_t srcidx; // how many src bytes we have
|
||||||
|
@ -6,13 +6,9 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
struct ncvisual;
|
struct ncvisual;
|
||||||
|
|
||||||
void* create_png_mmap(const void* data, int rows, int rowstride, int cols,
|
|
||||||
size_t* bsize, int fd);
|
|
||||||
|
|
||||||
// create the PNG, encode it using base64, and write it to |fp|
|
// create the PNG, encode it using base64, and write it to |fp|
|
||||||
int write_png_b64(const void* data, int rows, int rowstride, int cols,
|
int write_png_b64(const void* data, int rows, int rowstride, int cols,
|
||||||
FILE* fp);
|
FILE* fp);
|
||||||
|
@ -198,6 +198,7 @@ void free_terminfo_cache(tinfo* ti){
|
|||||||
ncinputlayer_stop(&ti->input);
|
ncinputlayer_stop(&ti->input);
|
||||||
free(ti->termversion);
|
free(ti->termversion);
|
||||||
free(ti->esctable);
|
free(ti->esctable);
|
||||||
|
#ifdef __linux__
|
||||||
if(ti->linux_fb_fd >= 0){
|
if(ti->linux_fb_fd >= 0){
|
||||||
close(ti->linux_fb_fd);
|
close(ti->linux_fb_fd);
|
||||||
}
|
}
|
||||||
@ -205,6 +206,7 @@ void free_terminfo_cache(tinfo* ti){
|
|||||||
if(ti->linux_fbuffer != MAP_FAILED){
|
if(ti->linux_fbuffer != MAP_FAILED){
|
||||||
munmap(ti->linux_fbuffer, ti->linux_fb_len);
|
munmap(ti->linux_fbuffer, ti->linux_fb_len);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare one terminal version against another. numerics, separated by
|
// compare one terminal version against another. numerics, separated by
|
||||||
@ -652,6 +654,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
|
|||||||
int* cursor_y, int* cursor_x, ncsharedstats* stats){
|
int* cursor_y, int* cursor_x, ncsharedstats* stats){
|
||||||
queried_terminals_e qterm = TERMINAL_UNKNOWN;
|
queried_terminals_e qterm = TERMINAL_UNKNOWN;
|
||||||
memset(ti, 0, sizeof(*ti));
|
memset(ti, 0, sizeof(*ti));
|
||||||
|
#ifdef __linux__
|
||||||
ti->linux_fb_fd = -1;
|
ti->linux_fb_fd = -1;
|
||||||
ti->linux_fbuffer = MAP_FAILED;
|
ti->linux_fbuffer = MAP_FAILED;
|
||||||
// we might or might not program quadrants into the console font
|
// we might or might not program quadrants into the console font
|
||||||
@ -661,6 +664,7 @@ int interrogate_terminfo(tinfo* ti, int fd, const char* termname, unsigned utf8,
|
|||||||
// FIXME set up pixel-drawing API for framebuffer #1369
|
// FIXME set up pixel-drawing API for framebuffer #1369
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if(fd >= 0){
|
if(fd >= 0){
|
||||||
bool minimal = (qterm != TERMINAL_UNKNOWN);
|
bool minimal = (qterm != TERMINAL_UNKNOWN);
|
||||||
if(send_initial_queries(fd, minimal)){
|
if(send_initial_queries(fd, minimal)){
|
||||||
|
Loading…
Reference in New Issue
Block a user