Pixel Width: 1
Pixel Height:4294967295
Python Tiff Chunk Code:
from PIL import Image
import os
MAX_HEIGHT = 2**32 - 1
CHUNK_HEIGHT = 1000000
WIDTH = 1
GRAY_COLOR = (127, 127, 127)
def create_chunk(height, filename):
chunk = Image.new("RGB", (WIDTH, height), GRAY_COLOR)
chunk.save(filename, compression="tiff_lzw")
def create_chunks(output_folder):
if os.path.exists(output_folder):
proceed = input(f"The directory '{output_folder}' already exists. Do you want to proceed and possibly overwrite existing files? (yes/no): ")
if proceed.lower() != 'yes':
print("Exiting without creating chunks.")
return
os.makedirs(output_folder, exist_ok=True)
remaining_height = MAX_HEIGHT
chunk_number = 0
while remaining_height > 0:
if remaining_height >= CHUNK_HEIGHT:
height = CHUNK_HEIGHT
else:
height = remaining_height
chunk_filename = os.path.join(output_folder, f"chunk_{chunk_number}.tiff")
create_chunk(height, chunk_filename)
remaining_height -= height
chunk_number += 1
print(f"Chunk {chunk_number} created. Remaining height: {remaining_height}")
if name == "main":
create_chunks("tiff_chunks_4294mil")
C Stich Code:
#include <tiffio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h> // For uint32_t
#define MAX_HEIGHT 4294967295 // 2^32 - 1
int main() {
const int MAX_CHUNKS = 4295; // Adjust based on your number of chunks
const char *output_filename = "longest.tiff";
uint32_t row, width, height; // Changed to uint32_t
tdata_t buf;
TIFF *out_tif, *in_tif;
uint32_t config; // Changed to uint32_t
// Open output TIFF for writing
out_tif = TIFFOpen(output_filename, "w");
if (!out_tif) {
fprintf(stderr, "Cannot open %s for writing\n", output_filename);
return 1;
}
for (int chunk_num = 0; chunk_num < MAX_CHUNKS; chunk_num++) {
char chunk_filename[256];
sprintf(chunk_filename, "tiff_chunks_4294mil/chunk_%d.tiff", chunk_num); // Updated directory name
// Print progress
fprintf(stdout, "Processing chunk %d of %d\n", chunk_num + 1, MAX_CHUNKS);
// Open chunk TIFF for reading
in_tif = TIFFOpen(chunk_filename, "r");
if (!in_tif) {
fprintf(stderr, "Cannot open %s for reading\n", chunk_filename);
TIFFClose(out_tif);
return 1;
}
// Get image dimensions and configuration
TIFFGetField(in_tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(in_tif, TIFFTAG_IMAGELENGTH, &height);
TIFFGetField(in_tif, TIFFTAG_PLANARCONFIG, &config);
buf = _TIFFmalloc(TIFFScanlineSize(in_tif));
// Set TIFF fields for the output TIFF based on the first chunk
if (chunk_num == 0) {
TIFFSetField(out_tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(out_tif, TIFFTAG_IMAGELENGTH, MAX_HEIGHT); // Use the exact MAX_HEIGHT
TIFFSetField(out_tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField(out_tif, TIFFTAG_PLANARCONFIG, config);
// Add other necessary TIFF fields as needed
}
// Read and write scanlines
for (row = 0; row < height; row++) {
if (TIFFReadScanline(in_tif, buf, row, 0) == -1) {
fprintf(stderr, "Error reading scanline %u from %s\n", row, chunk_filename);
_TIFFfree(buf);
TIFFClose(in_tif);
TIFFClose(out_tif);
return 1;
}
if (TIFFWriteScanline(out_tif, buf, row + chunk_num * height, 0) == -1) {
fprintf(stderr, "Error writing scanline %u to %s\n", row + chunk_num * height, output_filename);
_TIFFfree(buf);
TIFFClose(in_tif);
TIFFClose(out_tif);
return 1;
}
}
_TIFFfree(buf);
TIFFClose(in_tif);
}
TIFFClose(out_tif);
fprintf(stdout, "Stitching complete!\n");
return 0;
}