## Purpose

Governs the format in which full-size page images are stored in the database: which formats are used for which image modes, how thumbnails are produced, and when the stored format is passed through unchanged when saving a PDF.

## ADDED Requirements

### Requirement: Compact storage for continuous-tone images
When a page with a continuous-tone image (e.g. 8-bit grayscale or colour) is imported, its full-size image SHALL be stored in the database as a JPEG image.

#### Scenario: Grayscale TIFF imported
- **WHEN** an 8-bit grayscale TIFF page is imported
- **THEN** the stored full-size image blob SHALL be a JPEG
- **AND** the stored image SHALL reproduce the source at a quality equivalent to JPEG quality ~92 or better

#### Scenario: Colour image imported
- **WHEN** an opaque colour (RGB/CMYK) page is imported
- **THEN** the stored full-size image blob SHALL be a JPEG

#### Scenario: Colour image with transparency imported
- **WHEN** a colour page with an alpha channel (RGBA/LA/PA) is imported
- **THEN** the stored full-size image blob SHALL be lossless (PNG)
- **AND** transparency SHALL be preserved

### Requirement: Lossless storage for bilevel images
When a page has a bilevel (1-bit) image, its full-size image SHALL be stored losslessly.

#### Scenario: Bilevel page imported
- **WHEN** a 1-bit page is imported
- **THEN** the stored full-size image blob SHALL be lossless (PNG)
- **AND** no quality shall be lost relative to the source

### Requirement: Imported compact files stored without re-encode
When an imported file is already in a compact format, the original bytes SHALL be stored without re-encoding.

#### Scenario: JPEG file imported
- **WHEN** a JPEG file is imported
- **THEN** the stored blob SHALL be the original JPEG bytes

#### Scenario: PNG file imported
- **WHEN** a PNG file is imported
- **THEN** the stored blob SHALL be the original PNG bytes

### Requirement: Thumbnails generated from downscaled images
Thumbnails SHALL be generated by scaling the image down before encoding, so that encoding a full-size image for the purpose of creating a thumbnail is not performed.

#### Scenario: Thumbnail created during import
- **WHEN** a page is imported and its thumbnail is generated
- **THEN** the thumbnail SHALL be produced from a downscaled version of the image rather than from a full-size re-encode

### Requirement: Stored images embedded without re-encode in PDF save
When saving a PDF and no downsampling or compression option requires re-encoding, the stored full-size image bytes SHALL be passed to the PDF writer directly.

#### Scenario: PDF save with no image options
- **WHEN** saving a PDF without downsampling or compression options
- **THEN** the stored image bytes SHALL be written to the PDF without re-encoding
- **AND** the PDF output SHALL embed the stored image stream natively

#### Scenario: PDF save with downsampling
- **WHEN** saving a PDF with downsampling or compression options enabled
- **THEN** the page SHALL be re-encoded according to those options as today

### Requirement: Existing PNG sessions remain readable
Sessions saved before this change store full-size images as PNG; those blobs SHALL remain readable.

#### Scenario: Open session with PNG blobs
- **WHEN** a session created before this change is opened
- **THEN** its PNG image blobs SHALL be loaded and displayed correctly
