mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
CMake: demand Zlib
This commit is contained in:
parent
60c953b77b
commit
c1e419fd9d
@ -80,6 +80,8 @@ find_package(PkgConfig REQUIRED)
|
|||||||
# feature_summary + set_package_properties to fail in one fell swoop.
|
# feature_summary + set_package_properties to fail in one fell swoop.
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
set_package_properties(Threads PROPERTIES TYPE REQUIRED)
|
set_package_properties(Threads PROPERTIES TYPE REQUIRED)
|
||||||
|
find_package(ZLIB)
|
||||||
|
set_package_properties(ZLIB PROPERTIES TYPE REQUIRED)
|
||||||
# platform-specific logics
|
# platform-specific logics
|
||||||
if(NOT MSYS AND NOT APPLE)
|
if(NOT MSYS AND NOT APPLE)
|
||||||
find_library(LIBM m REQUIRED)
|
find_library(LIBM m REQUIRED)
|
||||||
|
@ -12,11 +12,11 @@ prepackaged on many distributions. Otherwise, acquire the current source via
|
|||||||
|
|
||||||
On an APT-based distribution, run:
|
On an APT-based distribution, run:
|
||||||
|
|
||||||
`apt-get install build-essential cmake doctest-dev libavformat-dev libavutil-dev libncurses-dev libreadline-dev libqrcodegen-dev libswscale-dev libunistring-dev pandoc pkg-config`
|
`apt-get install build-essential cmake doctest-dev zlib1g-dev libavformat-dev libavutil-dev libncurses-dev libreadline-dev libqrcodegen-dev libswscale-dev libunistring-dev pandoc pkg-config`
|
||||||
|
|
||||||
If you only intend to build core Notcurses (without multimedia support), run:
|
If you only intend to build core Notcurses (without multimedia support), run:
|
||||||
|
|
||||||
`apt-get install build-essential cmake doctest-dev libncurses-dev libreadline-dev libqrcodegen-dev libunistring-dev pandoc pkg-config`
|
`apt-get install build-essential cmake doctest-dev zlib1g-dev libncurses-dev libreadline-dev libqrcodegen-dev libunistring-dev pandoc pkg-config`
|
||||||
|
|
||||||
If you want to build the Python wrappers, you'll also need:
|
If you want to build the Python wrappers, you'll also need:
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include <sys/mman.h>
|
#include <zlib.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "visual-details.h"
|
#include "visual-details.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
@ -16,19 +16,26 @@
|
|||||||
static const unsigned char PNGHEADER[] = "\x89PNG\x0d\x0a\x1a\x0a";
|
static const unsigned char PNGHEADER[] = "\x89PNG\x0d\x0a\x1a\x0a";
|
||||||
|
|
||||||
// number of bytes necessary to encode (uncompressed) the visual specified by
|
// number of bytes necessary to encode (uncompressed) the visual specified by
|
||||||
// |ncv|. if alphap is non-zero, an alpha channel will be used, increasing the
|
// |ncv|. on error, *|deflated| will be NULL.
|
||||||
// size of the data by 1/3.
|
size_t compute_png_size(const ncvisual* ncv, void** deflated, size_t* dlen){
|
||||||
size_t compute_png_size(const ncvisual* ncv, unsigned alphap,
|
uint64_t databytes = ncv->pixx * ncv->pixy * 4;
|
||||||
char** deflated, size_t* dlen){
|
unsigned long bound = compressBound(databytes);
|
||||||
// FIXME need to do the deflation here
|
*deflated = malloc(bound);
|
||||||
*deflated = NULL;
|
if(*deflated == NULL){
|
||||||
*dlen = 0;
|
return 0;
|
||||||
uint64_t databytes = ncv->pixx * ncv->pixy * (3 + !!alphap);
|
}
|
||||||
uint64_t fullchunks = databytes / CHUNK_MAX_DATA; // full 2GB IDATs
|
int cret = compress(*deflated, &bound, (const unsigned char*)ncv->data, databytes);
|
||||||
|
if(cret != Z_OK){
|
||||||
|
free(*deflated);
|
||||||
|
logerror("Error compressing %zuB (%d)\n", databytes, cret);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*dlen = bound;
|
||||||
|
uint64_t fullchunks = *dlen / CHUNK_MAX_DATA; // full 2GB IDATs
|
||||||
return (sizeof(PNGHEADER) - 1) + // PNG header
|
return (sizeof(PNGHEADER) - 1) + // PNG header
|
||||||
CHUNK_DESC_BYTES + IHDR_DATA_BYTES + // mandatory IHDR chunk
|
CHUNK_DESC_BYTES + IHDR_DATA_BYTES + // mandatory IHDR chunk
|
||||||
(CHUNK_DESC_BYTES + CHUNK_MAX_DATA) * fullchunks +
|
(CHUNK_DESC_BYTES + CHUNK_MAX_DATA) * fullchunks +
|
||||||
(CHUNK_DESC_BYTES + databytes % CHUNK_MAX_DATA) +
|
(CHUNK_DESC_BYTES + *dlen % CHUNK_MAX_DATA) +
|
||||||
CHUNK_DESC_BYTES; // mandatory IEND chunk
|
CHUNK_DESC_BYTES; // mandatory IEND chunk
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +61,7 @@ chunk_crc(const char* buf){
|
|||||||
|
|
||||||
// write the ihdr at |buf|, which is guaranteed to be large enough (25B).
|
// write the ihdr at |buf|, which is guaranteed to be large enough (25B).
|
||||||
static size_t
|
static size_t
|
||||||
write_ihdr(const ncvisual* ncv, char* buf, unsigned alphap){
|
write_ihdr(const ncvisual* ncv, char* buf){
|
||||||
uint32_t length = htonl(IHDR_DATA_BYTES);
|
uint32_t length = htonl(IHDR_DATA_BYTES);
|
||||||
memcpy(buf, &length, 4);
|
memcpy(buf, &length, 4);
|
||||||
static const char ctype[] = "IHDR";
|
static const char ctype[] = "IHDR";
|
||||||
@ -65,7 +72,7 @@ write_ihdr(const ncvisual* ncv, char* buf, unsigned alphap){
|
|||||||
memcpy(buf + 12, &height, 4);
|
memcpy(buf + 12, &height, 4);
|
||||||
uint8_t depth = 8; // 8 bits per channel
|
uint8_t depth = 8; // 8 bits per channel
|
||||||
memcpy(buf + 16, &depth, 1);
|
memcpy(buf + 16, &depth, 1);
|
||||||
uint8_t color = 2 + alphap ? 4 : 0; // RGB with possible alpha
|
uint8_t color = 6; // RGBA
|
||||||
memcpy(buf + 17, &color, 1);
|
memcpy(buf + 17, &color, 1);
|
||||||
uint8_t compression = 0; // deflate, max window 32768
|
uint8_t compression = 0; // deflate, max window 32768
|
||||||
memcpy(buf + 18, &compression, 1);
|
memcpy(buf + 18, &compression, 1);
|
||||||
@ -106,11 +113,10 @@ write_iend(char* buf){
|
|||||||
// deflated data |deflated| of |dlen| bytes. |buf| must be large enough to
|
// 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().
|
// write all necessary data; it ought have been sized with compute_png_size().
|
||||||
static size_t
|
static size_t
|
||||||
create_png(const ncvisual* ncv, void* buf, unsigned alphap,
|
create_png(const ncvisual* ncv, void* buf, const char* deflated, size_t dlen){
|
||||||
const char* deflated, size_t dlen){
|
|
||||||
size_t written = sizeof(PNGHEADER) - 1;
|
size_t written = sizeof(PNGHEADER) - 1;
|
||||||
memcpy(buf, PNGHEADER, written);
|
memcpy(buf, PNGHEADER, written);
|
||||||
size_t r = write_ihdr(ncv, (char*)buf + written, alphap);
|
size_t r = write_ihdr(ncv, (char*)buf + written);
|
||||||
written += r;
|
written += r;
|
||||||
r = write_idats((char*)buf + written, deflated, dlen);
|
r = write_idats((char*)buf + written, deflated, dlen);
|
||||||
written += r;
|
written += r;
|
||||||
@ -130,11 +136,14 @@ mmap_round_size(size_t s){
|
|||||||
// larger than this, but the end is immaterial padding). returns MMAP_FAILED
|
// 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.
|
// on a failure. if |fd| is negative, an anonymous map will be made.
|
||||||
void* create_png_mmap(const ncvisual* ncv, size_t* bsize, int fd){
|
void* create_png_mmap(const ncvisual* ncv, size_t* bsize, int fd){
|
||||||
const unsigned alphap = 1; // FIXME 0 if no alpha used, for smaller output
|
void* deflated;
|
||||||
char* deflated;
|
|
||||||
size_t dlen;
|
size_t dlen;
|
||||||
size_t mlen;
|
size_t mlen;
|
||||||
*bsize = compute_png_size(ncv, alphap, &deflated, &dlen);
|
*bsize = compute_png_size(ncv, &deflated, &dlen);
|
||||||
|
if(deflated == NULL){
|
||||||
|
logerror("Couldn't compress to %d\n", fd);
|
||||||
|
return MAP_FAILED;
|
||||||
|
}
|
||||||
mlen = mmap_round_size(*bsize);
|
mlen = mmap_round_size(*bsize);
|
||||||
if(mlen == 0){
|
if(mlen == 0){
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
@ -155,7 +164,7 @@ void* create_png_mmap(const ncvisual* ncv, size_t* bsize, int fd){
|
|||||||
logerror("Couldn't get %zuB map for %d\n", mlen, fd);
|
logerror("Couldn't get %zuB map for %d\n", mlen, fd);
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
size_t w = create_png(ncv, map, alphap, deflated, dlen);
|
size_t w = create_png(ncv, map, deflated, dlen);
|
||||||
loginfo("Wrote %zuB PNG to %d\n", w, fd);
|
loginfo("Wrote %zuB PNG to %d\n", w, fd);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user