mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:42:43 +00:00 
			
		
		
		
	 75d87ccf5f
			
		
	
	
		75d87ccf5f
		
	
	
	
	
		
			
			We currently only support 1D Group 3, but that's a start. The test case was generated with GIMP (it happens to be 1D by chance).
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/ByteBuffer.h>
 | |
| 
 | |
| namespace Gfx::CCITT {
 | |
| 
 | |
| // You can find a great overview of CCITT compression schemes here:
 | |
| // https://www.fileformat.info/mirror/egff/ch09_05.htm
 | |
| 
 | |
| // The CCITT3 specification is accessible at this page:
 | |
| // https://www.itu.int/rec/T-REC-T.4/en
 | |
| 
 | |
| // The unidimensional scheme is originally described in:
 | |
| // 4.1 One-dimensional coding scheme
 | |
| // However, this function implements the TIFF variant (see TIFFLoader.h for a spec link),
 | |
| // differences are detailed in section:
 | |
| // Section 10: Modified Huffman Compression
 | |
| ErrorOr<ByteBuffer> decode_ccitt_rle(ReadonlyBytes bytes, u32 image_width, u32 image_height);
 | |
| 
 | |
| // While this is named for a CCITT context, this struct holds data like TIFF's T4Options tag
 | |
| struct Group3Options {
 | |
|     enum class Mode : u8 {
 | |
|         OneDimension,
 | |
|         TwoDimensions,
 | |
|     };
 | |
| 
 | |
|     enum class Compression : u8 {
 | |
|         Uncompressed,
 | |
|         Compressed,
 | |
|     };
 | |
| 
 | |
|     enum class UseFillBits : u8 {
 | |
|         No = 0,
 | |
|         Yes = 1,
 | |
|     };
 | |
| 
 | |
|     Mode dimensions = Mode::OneDimension;
 | |
|     Compression compression = Compression::Compressed;
 | |
|     UseFillBits use_fill_bits = UseFillBits::No;
 | |
| };
 | |
| 
 | |
| ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u32 image_height, Group3Options const& options);
 | |
| 
 | |
| }
 |