È solo una questione di comprensione del formato di file binario. I formati compressi saranno più difficili.
Dando per scontato che vogliono una bitmap/DIB, questo codice:
#incremental_write_bmp.py
import binascii
data='''
0h -2 -42 4D -"BM" -Magic Number (unsigned integer 66, 77)
2h -4 -46 00 00 00 -70 Bytes -Size of the BMP file
6h -2 -00 00 -Unused -Application Specific
8h -2 -00 00 -Unused -Application Specific
Ah -4 -36 00 00 00 -54 bytes -The offset where the bitmap data (pixels) can be found.
Eh -4 -28 00 00 00 -40 bytes -The number of bytes in the header (from this point).
12h -4 -02 00 00 00 -2 pixels -The width of the bitmap in pixels
16h -4 -02 00 00 00 -2 pixels -The height of the bitmap in pixels
1Ah -2 -01 00 -1 plane -Number of color planes being used.
1Ch -2 -18 00 -24 bits -The number of bits/pixel.
1Eh -4 -00 00 00 00 -0 -BI_RGB, No compression used
22h -4 -10 00 00 00 -16 bytes -The size of the raw BMP data (after this header)
26h -4 -13 0B 00 00 -2,835 pixels/meter -The horizontal resolution of the image
2Ah -4 -13 0B 00 00 -2,835 pixels/meter -The vertical resolution of the image
2Eh -4 -00 00 00 00 -0 colors -Number of colors in the palette
32h -4 -00 00 00 00 -0 important colors -Means all colors are important
36h -3 -00 00 FF -0 0 255 -Red, Pixel (1,0)
39h -3 -FF FF FF -255 255 255 -White, Pixel (1,1)
3Ch -2 -00 00 -0 0 -Padding for 4 byte alignment (Could be a value other than zero)
3Eh -3 -FF 00 00 -255 0 0 -Blue, Pixel (0,0)
41h -3 -00 FF 00 -0 255 0 -Green, Pixel (0,1)
44h -2 -00 00 -0 0 -Padding for 4 byte alignment (Could be a value other than zero)
'''.strip().split('\n')
open('test.bmp','wb')
for l in data:
b = l.split('-')[2].strip()
d = ''.join(b.split())
x = binascii.a2b_hex(d)
# this re-opens the file and appends each iteration
open('test.bmp','ab').write(x)
... sarà incrementale scrivere il bitmap esempio 2x2 trovato here. Ora si tratta solo di impostare le intestazioni sulla dimensione desiderata e di leggere (e talvolta rileggere) le tessere nel giusto ordine. Ho provato con un file molto grande e non ho visto picchi di memoria di Python. Presumo che il sistema operativo può aggiungere a un file senza leggere tutto.
Le immagini devono essere in modalità RGB? –
Sì, sono immagini a colori. Anche il 25000x25000 è in realtà solo una piccola parte dell'immagine intera, che probabilmente sarà 175.000x325.000. Anche se le immagini erano in scala di grigi, immagino un'immagine di quelle dimensioni che non si adattano ancora alla RAM. – meatvest
Di solito aiuta a rispondere a tali domande per sapere come verrà utilizzato l'output. Quale programma/sistema consumerà questi dati (e/o per quali scopi)? La risposta a ciò potrebbe indicare la strada. –