Installing CXImage on Ubuntu
To use CXImage on Ubuntu, start by updating your system packages:
sudo apt update && sudo apt upgrade -y
Install essential dependencies for compilation and image format support:
sudo apt install build-essential libpng-dev libjpeg-dev libtiff-dev libgif-dev -y
For most users, the easiest way to install CXImage is via APT (recommended for stability and ease of updates):
sudo apt install libcximage-dev -y
If you need a specific version or the latest development branch, compile from source:
git clone https://github.com/antaressoftware/cximage.git
cd cximage
mkdir build && cd build
cmake ..
make -j$(nproc) && sudo make install
Verify installation using pkg-config
to check for correct flags:
pkg-config --cflags --libs cximage
This should output include paths (e.g., -I/usr/local/include
) and linker flags (e.g., -lcximage
), confirming successful installation.
Configuring Your Project for CXImage
To integrate CXImage into a C++ project, include its headers in your source files:
#include <cximage.h>
Link the CXImage library during compilation. For example, compile your_program.cpp
with:
g++ your_program.cpp -o your_program -lcximage
If you compiled CXImage from source and placed it in a non-standard location (e.g., /usr/local
), set environment variables to help the compiler find its files. Add these lines to your ~/.bashrc
or ~/.profile
:
export CPLUS_INCLUDE_PATH=/usr/local/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
Reload the file to apply changes:
source ~/.bashrc
This ensures your project can locate CXImage’s headers and libraries without manual path specification.
Basic Usage Examples
Loading and Saving Images:
The most fundamental operations are loading an image from disk and saving it in a different format. The following example loads a JPEG, saves it as PNG, and checks for errors:
#include <cximage.h>
#include <iostream>
int main() {
CxImage image;
if (!image.Load("input.jpg", CXIMAGE_FORMAT_JPG)) {
std::cerr << "Failed to load input.jpg" << std::endl;
return 1;
}
if (!image.Save("output.png", CXIMAGE_FORMAT_PNG)) {
std::cerr << "Failed to save output.png" << std::endl;
return 1;
}
std::cout << "Image converted successfully!" << std::endl;
return 0;
}
Compile with:
g++ test_load_save.cpp -o test_load_save -lcximage
Run the program:
./test_load_save
Common Image Operations:
CXImage supports a range of basic manipulations:
image.Resize(800, 600, FILTER_BOX); // FILTER_BOX for fast resizing
image.Rotate(90);
image.Crop(100, 100, 400, 400); // (x1, y1, x2, y2)
image.Blur(3); // Gaussian blur
image.EdgeDetect(); // Sobel edge detection
These operations modify the image in-memory. Always call image.Save()
to persist changes to disk.
Performance Optimization Tips
SetLoadRawData(true)
before loading and SetOutputRawData(true)
before saving:CxImage image;
image.SetLoadRawData(true);
if (!image.Load("large_image.jpg", CXIMAGE_FORMAT_JPG)) {
std::cerr << "Failed to load image" << std::endl;
return 1;
}
// Process image (no data copied)
image.SetOutputRawData(true);
if (!image.Save("processed_image.jpg", CXIMAGE_FORMAT_JPG)) {
std::cerr << "Failed to save image" << std::endl;
return 1;
}
htop
to identify bottlenecks (e.g., high CPU usage during filtering).Troubleshooting Common Issues
CxImage::Load
”): Ensure you linked the CXImage library (-lcximage
). If using CMake, add target_link_libraries(your_target PRIVATE cximage)
.png.h
), install the corresponding development packages (libpng-dev
, libjpeg-dev
)./usr/local/lib
is in your system’s library path. Run sudo ldconfig
to update the cache, or add the path to /etc/ld.so.conf.d/local.conf
and run sudo ldconfig
.Maintenance Best Practices
git pull origin main
) to get bug fixes and security patches. Recompile and reinstall after pulling changes.libpng
, libjpeg
) updated to compatible versions. Use apt list --upgradable
to check for available updates and install them regularly.README.md
file in your project repository with details about your CXImage version, compilation steps, and known issues. This helps you (and others) quickly troubleshoot problems later.