mirror of
https://github.com/RGBCube/serenity
synced 2025-10-17 22:52:27 +00:00

This compression (tag Compression=2) is not very popular on its own, but a base to implement CCITT3 2D and CCITT4 compressions. As the format has no real benefits, it is quite hard to find an app that accepts tho encode that for you. So I used the following program that calls `libtiff` directly: ```cpp #include <vector> #include <cstdlib> #include <iostream> #include <tiffio.h> // An array containing 0 and 1 of length width * height. extern std::vector<uint8_t> array; int main() { // From: https://stackoverflow.com/a/34257789 TIFF *image = TIFFOpen("input.tif", "w"); int const width = 400; int const height = 300; TIFFSetField(image, TIFFTAG_IMAGEWIDTH, width); TIFFSetField(image, TIFFTAG_IMAGELENGTH, height); TIFFSetField(image, TIFFTAG_PHOTOMETRIC, 0); TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE); TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1); TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 1); std::vector<uint8_t> scan_line(width / 8 + 8, 0); int count = 0; for (int i = 0; i < height; i++) { std::fill(scan_line.begin(), scan_line.end(), 0); for (int x = 0; x < width; ++x) { uint8_t eight_pixels = scan_line.at(x / 8); eight_pixels = eight_pixels << 1; eight_pixels |= !array.at(i * width + x); scan_line.at(x / 8) = eight_pixels; } int bytes = int(width / 8.0 + 0.5); if (TIFFWriteScanline(image, scan_line.data(), i, bytes) != 1) std::cerr << "Something went wrong\n"; } TIFFClose(image); } ```
102 lines
3 KiB
CMake
102 lines
3 KiB
CMake
set(SOURCES
|
|
AffineTransform.cpp
|
|
AntiAliasingPainter.cpp
|
|
Bitmap.cpp
|
|
BitmapMixer.cpp
|
|
ClassicStylePainter.cpp
|
|
ClassicWindowTheme.cpp
|
|
Color.cpp
|
|
CursorParams.cpp
|
|
DeltaE.cpp
|
|
EdgeFlagPathRasterizer.cpp
|
|
Filters/ColorBlindnessFilter.cpp
|
|
Filters/FastBoxBlurFilter.cpp
|
|
Filters/LumaFilter.cpp
|
|
Filters/StackBlurFilter.cpp
|
|
FontCascadeList.cpp
|
|
Font/BitmapFont.cpp
|
|
Font/Emoji.cpp
|
|
Font/Font.cpp
|
|
Font/FontDatabase.cpp
|
|
Font/OpenType/Cmap.cpp
|
|
Font/OpenType/Font.cpp
|
|
Font/OpenType/Glyf.cpp
|
|
Font/OpenType/Hinting/Opcodes.cpp
|
|
Font/OpenType/Tables.cpp
|
|
Font/ScaledFont.cpp
|
|
Font/Typeface.cpp
|
|
Font/WOFF/Font.cpp
|
|
Font/WOFF2/Font.cpp
|
|
GradientPainting.cpp
|
|
ICC/BinaryWriter.cpp
|
|
ICC/Enums.cpp
|
|
ICC/Profile.cpp
|
|
ICC/Tags.cpp
|
|
ICC/TagTypes.cpp
|
|
ICC/WellKnownProfiles.cpp
|
|
ImageFormats/BMPLoader.cpp
|
|
ImageFormats/BMPWriter.cpp
|
|
ImageFormats/BooleanDecoder.cpp
|
|
ImageFormats/CCITTDecoder.cpp
|
|
ImageFormats/DDSLoader.cpp
|
|
ImageFormats/GIFLoader.cpp
|
|
ImageFormats/ICOLoader.cpp
|
|
ImageFormats/ILBMLoader.cpp
|
|
ImageFormats/ImageDecoder.cpp
|
|
ImageFormats/ISOBMFF/Boxes.cpp
|
|
ImageFormats/ISOBMFF/Reader.cpp
|
|
ImageFormats/JPEGLoader.cpp
|
|
ImageFormats/JPEGXLLoader.cpp
|
|
ImageFormats/JPEGWriter.cpp
|
|
ImageFormats/PBMLoader.cpp
|
|
ImageFormats/PGMLoader.cpp
|
|
ImageFormats/PNGLoader.cpp
|
|
ImageFormats/PNGWriter.cpp
|
|
ImageFormats/PortableFormatWriter.cpp
|
|
ImageFormats/PPMLoader.cpp
|
|
ImageFormats/QOILoader.cpp
|
|
ImageFormats/QOIWriter.cpp
|
|
ImageFormats/TGALoader.cpp
|
|
ImageFormats/TIFFLoader.cpp
|
|
ImageFormats/TinyVGLoader.cpp
|
|
ImageFormats/WebPLoader.cpp
|
|
ImageFormats/WebPLoaderLossless.cpp
|
|
ImageFormats/WebPLoaderLossy.cpp
|
|
ImmutableBitmap.cpp
|
|
Painter.cpp
|
|
Palette.cpp
|
|
Path.cpp
|
|
Point.cpp
|
|
Rect.cpp
|
|
ShareableBitmap.cpp
|
|
Size.cpp
|
|
StylePainter.cpp
|
|
SystemTheme.cpp
|
|
TextDirection.cpp
|
|
TextLayout.cpp
|
|
Triangle.cpp
|
|
VectorGraphic.cpp
|
|
WindowTheme.cpp
|
|
)
|
|
|
|
serenity_lib(LibGfx gfx)
|
|
target_link_libraries(LibGfx PRIVATE LibCompress LibCore LibCrypto LibFileSystem LibTextCodec LibIPC LibUnicode)
|
|
|
|
set(generated_sources TIFFMetadata.h TIFFTagHandler.cpp)
|
|
list(TRANSFORM generated_sources PREPEND "ImageFormats/")
|
|
|
|
find_package(Python COMPONENTS Interpreter REQUIRED)
|
|
|
|
add_custom_command(
|
|
OUTPUT ${generated_sources}
|
|
COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/TIFFGenerator.py" -o "${CMAKE_CURRENT_BINARY_DIR}/ImageFormats"
|
|
DEPENDS "TIFFGenerator.py"
|
|
VERBATIM
|
|
)
|
|
target_sources(LibGfx PRIVATE ${generated_sources})
|
|
add_custom_target(generate_tiff_files_handler DEPENDS ${generated_sources})
|
|
add_dependencies(all_generated generate_tiff_files_handler)
|
|
add_dependencies(LibGfx generate_tiff_files_handler)
|
|
|
|
list(TRANSFORM generated_sources PREPEND "${CMAKE_CURRENT_BINARY_DIR}/")
|
|
install(FILES ${generated_sources} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/LibGfx/ImageFormats")
|