Skip to content

Commit 32fee4a

Browse files
committed
refactor: simplify file size estimate and drop unused param
1 parent 672d6ac commit 32fee4a

4 files changed

Lines changed: 17 additions & 26 deletions

File tree

src/components/features/Export/ExportProgress.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ export const ExportProgress = memo(function ExportProgress({
7070
exportInfo = null;
7171
}
7272

73+
const estimatedSize = exportInfo
74+
? exportInfo.fileSizeEstimates[format] ||
75+
exportInfo.fileSizeEstimates['png']
76+
: '';
77+
const fileSizeText =
78+
actualBytes != null
79+
? `File size: ${formatFileSize(actualBytes)}`
80+
: `File size estimate: ~${estimatedSize}`;
81+
7382
return (
7483
<ModalShell
7584
isOpen={isExporting}
@@ -89,17 +98,7 @@ export const ExportProgress = memo(function ExportProgress({
8998
{exportInfo && (
9099
<div className="text-xs text-text-muted bg-surface-elevated border border-border rounded-lg px-3 py-2 space-y-1">
91100
<div>Resolution: {exportInfo.displaySize}</div>
92-
<div>
93-
{actualBytes != null ? (
94-
<>File size: {formatFileSize(actualBytes)}</>
95-
) : (
96-
<>
97-
File size estimate: ~
98-
{exportInfo.fileSizeEstimates[format] ||
99-
exportInfo.fileSizeEstimates['png']}
100-
</>
101-
)}
102-
</div>
101+
<div>{fileSizeText}</div>
103102
{exportInfo.isLargeExport && (
104103
<div className="text-warning mt-1">
105104
Large export (RAM: {exportInfo.memoryEstimateMB} MB). May take

src/shared/utils/exportState.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ export function getExportInfo(config: ExportConfig): ExportInfo {
100100
const mode = getExportMode(exportQuality);
101101
const fileSizes = estimateFileSizes(
102102
exportSize.canvasWidth,
103-
exportSize.canvasHeight,
104-
exportQuality
103+
exportSize.canvasHeight
105104
);
106105

107106
return {

src/shared/utils/imageOptimizer.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ test('formatFileSize scales unit with magnitude', () => {
1010
});
1111

1212
test('estimateFileSizes stays positive and grows with resolution', () => {
13-
const small = estimateFileSizes(1000, 1000, 1);
14-
const large = estimateFileSizes(4000, 4000, 1);
13+
const small = estimateFileSizes(1000, 1000);
14+
const large = estimateFileSizes(4000, 4000);
1515

1616
assert.ok(small.pngBytes > 0);
1717
assert.ok(small.jpegBytes > 0);
@@ -20,8 +20,8 @@ test('estimateFileSizes stays positive and grows with resolution', () => {
2020
});
2121

2222
test('estimateFileSizes bytes-per-pixel falls as the image grows', () => {
23-
const small = estimateFileSizes(1000, 1000, 1);
24-
const large = estimateFileSizes(4000, 4000, 1);
23+
const small = estimateFileSizes(1000, 1000);
24+
const large = estimateFileSizes(4000, 4000);
2525

2626
const smallBpp = small.pngBytes / (1000 * 1000);
2727
const largeBpp = large.pngBytes / (4000 * 4000);

src/shared/utils/imageOptimizer.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,9 @@ export interface FileSizeEstimates {
166166

167167
export function estimateFileSizes(
168168
width: number,
169-
height: number,
170-
_exportQuality: number
169+
height: number
171170
): FileSizeEstimates {
172-
const pixels = width * height;
173-
// A chess diagram is mostly flat colour, so bytes-per-pixel falls as the
174-
// image grows (larger flat runs compress better). Modelling the encoded
175-
// size as proportional to sqrt(pixels) tracks that far more closely than a
176-
// fixed bytes-per-pixel factor. Coefficients fitted against real PNG/JPEG
177-
// (q=0.92) exports of coordinate boards across export sizes.
178-
const scale = Math.sqrt(pixels);
171+
const scale = Math.sqrt(width * height);
179172
const pngBytes = Math.round(scale * 90);
180173
const jpegBytes = Math.round(scale * 55);
181174
return {

0 commit comments

Comments
 (0)