# libimagequant—Image Quantization Library
Small, portable C library for high-quality conversion of RGBA images to 8-bit indexed-color (palette) images.
It's powering [pngquant2](https://pngquant.org).
## License
Libimagequant is dual-licensed:
* For Free/Libre Open Source Software it's available under [GPL v3 or later](https://raw.github.com/ImageOptim/libimagequant/master/COPYRIGHT) with additional copyright notices for older parts of the code.
* For use in non-GPL software (e.g. closed-source or App Store distribution) please ask kornel@pngquant.org for a commercial license.
## Download
The [library](https://pngquant.org/lib) is currently a part of the [pngquant2 project](https://pngquant.org). [Repository](https://github.com/ImageOptim/libimagequant).
## Compiling and Linking
The library can be linked with ANSI C, C++, [Rust](https://github.com/pornel/libimagequant-rust) and [Java](https://github.com/ImageOptim/libimagequant/tree/master/org/pngquant) programs. It has no external dependencies.
To build on Unix-like systems run:
make static
it will create `libimagequant.a` which you can link with your program.
gcc yourprogram.c /path/to/libimagequant.a
On BSD, use `gmake` (GNU make) rather than the native `make`.
Alternatively you can compile the library with your program simply by including all `.c` files (and define `NDEBUG` to get a fast version):
gcc -std=c99 -O3 -DNDEBUG libimagequant/*.c yourprogram.c
### Rust
In [Rust](https://www.rust-lang.org/) you can use Cargo to build the library. Add [`imagequant`](https://crates.io/crates/imagequant) to dependencies of Rust programs, or `cargo build` [`imagequant-sys`](https://crates.io/crates/imagequant-sys) to build `libimagequant.a` for any language.
### Java JNI
To build Java JNI interface, ensure `JAVA_HOME` is set to your JDK directory, and run:
# export JAVA_HOME=$(locate include/jni.h) # you may need to set JAVA_HOME first
make java
It will create `libimagequant.jnilib` and classes in `org/pngquant/`.
On Windows run `make java-dll` and it'll create `libimagequant.dll` instead.
### Compiling on Windows/Visual Studio
The library can be compiled with any C compiler that has at least basic support for C99 (GCC, clang, ICC, C++ Builder, even Tiny C Compiler), but Visual Studio 2012 and older are not up to date with the 1999 C standard. There are 2 options for using `libimagequant` on Windows:
* Use Visual Studio **2015** and an [MSVC-compatible branch of the library](https://github.com/ImageOptim/libimagequant/tree/msvc)
* Or use GCC from [MinGW](http://www.mingw.org) or [MSYS2](http://www.msys2.org/). Use GCC to build `libimagequant.a` (using the instructions above for Unix) and add it along with `libgcc.a` (shipped with the MinGW compiler) to your VC project.
## Overview
The basic flow is:
1. Create attributes object and configure the library.
2. Create image object from RGBA pixels or data source.
3. Perform quantization (generate palette).
4. Store remapped image and final palette.
5. Free memory.
Please note that libimagequant only handles raw uncompressed arrays of pixels in memory and is completely independent of any file format.
<p>
#include "libimagequant.h"
liq_attr *attr = liq_attr_create();
liq_image *image = liq_image_create_rgba(attr, example_bitmap_rgba, width, height, 0);
liq_result *res;
liq_image_quantize(image, attr, &res);
liq_write_remapped_image(res, image, example_bitmap_8bpp, example_bitmap_size);
const liq_palette *pal = liq_get_palette(res);
// Save the image and the palette now.
for(int i=0; i < pal->count; i++) {
example_copy_palette_entry(pal->entries[i]);
}
// You'll need a PNG library to write to a file.
example_write_image(example_bitmap_8bpp);
liq_result_destroy(res);
liq_image_destroy(image);
liq_attr_destroy(attr);
Functions returning `liq_error` return `LIQ_OK` (`0`) on success and non-zero on error.
It's safe to pass `NULL` to any function accepting `liq_attr`, `liq_image`, `liq_result` (in that case the error code `LIQ_INVALID_POINTER` will be returned). These objects can be reused multiple times.
There are 3 ways to create image object for quantization:
* `liq_image_create_rgba()` for simple, contiguous RGBA pixel arrays (width×height×4 bytes large bitmap).
* `liq_image_create_rgba_rows()` for non-contiguous RGBA pixel arrays (that have padding between rows or reverse order, e.g. BMP).
* `liq_image_create_custom()` for RGB, ABGR, YUV and all other formats that can be converted on-the-fly to RGBA (you have to supply the conversion function).
Note that "image" here means raw uncompressed pixels. If you have a compressed image file, such as PNG, you must use another library (e.g. libpng or lodepng) to decode it first.
## Functions
----
liq_attr* liq_attr_create(void);
Returns object that will hold initial settings (attributes) for the library. The object should be freed using `liq_attr_destroy()` after it's no longer needed.
Returns `NULL` in the unlikely case that the library cannot run on the current machine (e.g. the library has been compiled for SSE-capable x86 CPU and run on VIA C3 CPU).
----
liq_error liq_set_max_colors(liq_attr* attr, int colors);
Specifies maximum number of colors to use. The default is 256. Instead of setting a fixed limit it's better to use `liq_set_quality()`.
The first argument is attributes object from `liq_attr_create()`.
Returns `LIQ_VALUE_OUT_OF_RANGE` if number of colors is outside the range 2-256.
----
int liq_get_max_colors(liq_attr* attr);
Returns the value set by `liq_set_max_colors()`.
----
liq_error liq_set_quality(liq_attr* attr, int minimum, int maximum);
Quality is in range `0` (worst) to `100` (best) and values are analoguous to JPEG quality (i.e. `80` is usually good enough).
Quantization will attempt to use the lowest number of colors needed to achieve `maximum` quality. `maximum` value of `100` is the default and means conversion as good as possible.
If it's not possible to convert the image with at least `minimum` quality (i.e. 256 colors is not enough to meet the minimum quality), then `liq_image_quantize()` will fail. The default minumum is `0` (proceeds regardless of quality).
Quality measures how well the generated palette fits image given to `liq_image_quantize()`. If a different image is remapped with `liq_write_remapped_image()` then actual quality may be different.
Regardless of the quality settings the number of colors won't exceed the maximum (see `liq_set_max_colors()`).
The first argument is attributes object from `liq_attr_create()`.
Returns `LIQ_VALUE_OUT_OF_RANGE` if target is lower than minimum or any of them is outside the 0-100 range.
Returns `LIQ_INVALID_POINTER` if `attr` appears to be invalid.
liq_attr *attr = liq_attr_create();
liq_set_quality(attr, 50, 80); // use quality 80 if possible. Give up if quality drops below 50.
----
int liq_get_min_quality(liq_attr* attr);
Returns the lower bound set by `liq_set_quality()`.
----
int liq_get_max_quality(liq_attr* attr);
Returns the upper bound set by `liq_set_quality()`.
----
liq_image *liq_image_create_rgba(liq_attr *attr, void* pixels, int width, int height, double gamma);
Creates an object that represents the image pixels to be used for quantization and remapping. The pixel array must be contiguous run of RGBA pixels (alpha is the last component, 0 = transparent, 255 = opaque).
The first argument is attributes object from `liq_attr_create()`. The same `attr` object should be used for the entire process, from creation of images to quantization.
The `pixels` array must not be modified or freed until this object is freed with `liq_image_destroy()`. See also `liq_image_set_memory_ownership()`.
`width` and `height` are dimensions in pixels. An image 10x10 pixel large will need a 400-byte array.
`gamma` can be `0` for images with the typical 1
(一)NCL的安装 Cygwin中NCL的安装
需积分: 0 95 浏览量
更新于2023-09-26
收藏 765.83MB ZIP 举报
NCL,全称为NCAR Command Language,是一种专门用于科学数据处理和可视化的脚本语言,由美国国家大气研究中心(NCAR)开发。在Windows系统上,我们通常借助Cygwin这个开源工具来模拟Linux环境来安装和运行NCL。下面将详细介绍如何在Cygwin中安装NCL。
1. **Cygwin是什么**
Cygwin是一个在Windows系统上提供类Unix环境的开源软件项目。它允许用户在Windows上运行许多原本只能在Linux或Unix环境下执行的程序,包括NCL。
2. **下载Cygwin**
你需要访问Cygwin的官方网站(https://www.cygwin.com/)并下载Cygwin的安装程序setup.exe。这个程序会引导你选择需要安装的软件包,包括那些支持NCL的依赖项。
3. **运行Cygwin安装程序**
运行setup.exe,按照向导指示进行。在“选择软件包”环节,你需要搜索并添加以下关键包:
- `ncurses`:提供终端控制功能,NCL需要这个库。
- `gcc-g++`:编译器,用于编译NCL源代码。
- `make`:构建工具,用于管理编译过程。
- `curl`:网络工具,用于下载NCL的安装文件。
- `zlib`:压缩库,NCL处理数据时可能会用到。
- `bzip2`:另一个压缩库,同样可能被NCL依赖。
- `openblas`:高性能线性代数库,对于科学计算很重要。
4. **下载NCL**
NCL的最新版本可以从其官方网站(https://ncl.ucar.edu/Download/)获取。使用Cygwin的`curl`命令下载NCL的源代码包,例如:
```
curl -O https://www.ucar.edu/sites/default/files/downloads/ncl/6.x.x/ncl-6.x.x-source.tar.gz
```
5. **解压NCL源代码**
使用Cygwin的`tar`命令解压下载的文件,例如:
```
tar -xzf ncl-6.x.x-source.tar.gz
```
6. **配置、编译和安装NCL**
进入解压后的目录,配置、编译和安装NCL:
```
cd ncl-6.x.x
./configure --prefix=/usr/local
make
sudo make install
```
7. **设置环境变量**
安装完成后,你需要将NCL的路径添加到系统路径中,这样可以在任何目录下运行NCL。在Cygwin的bash shell中,编辑`~/.bash_profile`文件,添加以下行:
```
export PATH=$PATH:/usr/local/bin
```
然后运行`source ~/.bash_profile`使更改生效。
8. **验证安装**
安装成功后,你可以通过运行`ncl`命令来测试NCL是否可以正常工作。如果一切顺利,你应该能看到NCL的版本信息。
9. **使用NCL**
现在你已经可以在Cygwin环境中编写和运行NCL脚本了。NCL支持处理气象、气候、地球科学等领域的数据,你可以通过编写简单的脚本来进行数据处理和可视化。
以上就是在Cygwin中安装NCL的详细步骤。请确保每个步骤都按照说明正确执行,以确保NCL能够顺利安装和运行。如果你在安装过程中遇到任何问题,可以查阅NCL的官方文档或者在线社区寻求帮助。
momo_aa
- 粉丝: 104
- 资源: 3
最新资源
- 西门子828D 840Dsl数控程序PLC西门子数控程序中文注释,详细解释介绍 对于维修人员,或者想学习PLC编程的工程师,初学者 西门子828D和840Dsl是西门子公司生产的数控系统,用于控
- 数字化旅社管理:客房收费系统的构建
- HTML5足球运动赛事网站模板源码.zip
- 基于IEEE33节点的配电网重构,采用最优流法开展了配电网重构工作,得到重构方案,应打开的开关数等,同时对比了重构前后的网损和电压结果 -以下内容来源于第三方解读,仅供参考 这段代码是一个用于电力
- 课程设计-基于单片机的单相电度表设计
- asdjhfjsnlkdmv
- 基于python的二手房数据分析完整源码+说明文档+分析报告+数据(高分项目)
- Matlab基于BP神经网络的气象预测,天气预测 BP神经网络具有任意复杂的模式分类能力和优良的多维函数映射能力,解决了简单感知器不能解决的异或(Exclusive OR,XOR)和一些其他问题
- bzzzhsjfsjlg;g;df''d'ffgg
- 跨平台古诗词展演:新媒体系统开发
- SpringCloudAlibaba技术栈-Dubbo
- BIOS刷新工具,笔记本BIOS工具
- 英国电站13台变压器冷却油中溶解气体分析数据数(2010-2015)
- 文化探索:深入了解各地风土人情
- 中国智慧工地行业市场研究(2023)Word(63页).docx
- 智慧建管&智慧工地PPT(33页).pptx