Skip to content

Support IPython retina display metadata in notebook image outputs#13883

Open
rodrigosf672 wants to merge 1 commit into
mainfrom
fix/retina-image-metadata
Open

Support IPython retina display metadata in notebook image outputs#13883
rodrigosf672 wants to merge 1 commit into
mainfrom
fix/retina-image-metadata

Conversation

@rodrigosf672
Copy link
Copy Markdown
Member

@rodrigosf672 rodrigosf672 commented May 29, 2026

Fixes #8383

Summary

  • Propagate display_data metadata (width/height) from Jupyter messages through the kernel supervisor and cell execution pipeline
  • Notebook images rendered with retina=True now display at the correct half-size dimensions instead of full pixel size

When IPython's display(Image("file.png", retina=True)) is called, the kernel sends image dimensions metadata ({"image/png": {"width": W, "height": H}}). Previously this metadata was discarded at two points in the pipeline: RuntimeMessageEmitter.onDisplayData() only forwarded transport metadata, and runtimeNotebookCellExecution didn't include message metadata in the cell output. Now it flows through to the <img> tag as width/height attributes.

Changes

  1. RuntimeMessageEmitter.ts: merge display metadata (data.metadata) into the emitted message
  2. runtimeNotebookCellExecution.ts: spread message.metadata into cell output metadata
  3. getOutputContents.ts: accept optional metadata param, extract width/height for image/png
  4. IPositronNotebookCell.ts: add optional width/height to the ParsedOutput image variant
  5. PositronNotebookCodeCell.ts: pass output.metadata to parseOutputData()
  6. NotebookCodeCell.tsx: render width/height attributes on the <img> element

Test plan

  • Two new unit tests added to notebookOutputUtils.vitest.ts (both passing):
    • parses image/png with retina metadata into an image with width and height
    • parses image/png without metadata into an image with no dimensions
  • Open a notebook, run from IPython.display import display, Image; display(Image("file.png", retina=True)) — image renders at half pixel dimensions
  • Same without retina=True — image renders at full size (no width/height attributes)
  • Non-image outputs (text, HTML, plots) unaffected
image

@:positron-notebooks @:notebooks @:win @:web

Propagate display_data metadata (width/height) from the Jupyter message
through the kernel supervisor and cell execution pipeline so notebook
images rendered with retina=True display at the correct half-size
dimensions.

Fixes #8383
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 29, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks @:notebooks @:win @:web

readme  valid tags

@rodrigosf672 rodrigosf672 changed the title Support IPython retina display metadata in notebook image outputs Support IPython retina display metadata in notebook image outputs May 29, 2026
@rodrigosf672 rodrigosf672 requested a review from Copilot May 29, 2026 14:21
@rodrigosf672 rodrigosf672 requested review from nstrayer and seeM May 29, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR plumbs Jupyter display metadata through the Positron notebook output pipeline so IPython retina image outputs can render with explicit dimensions.

Changes:

  • Forwards display metadata from the runtime supervisor into notebook cell output metadata.
  • Passes output metadata into image parsing and adds optional image dimensions to parsed output.
  • Renders parsed image dimensions on notebook <img> elements and adds unit coverage for PNG metadata parsing.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
extensions/positron-supervisor/src/RuntimeMessageEmitter.ts Includes Jupyter display metadata in emitted runtime output messages.
src/vs/workbench/contrib/runtimeNotebookKernel/browser/runtimeNotebookCellExecution.ts Adds runtime message metadata to notebook cell output metadata.
src/vs/workbench/contrib/positronNotebook/browser/getOutputContents.ts Extracts PNG width/height metadata while parsing outputs.
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts Extends parsed image outputs with optional dimensions.
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCodeCell.ts Supplies output metadata to the parser.
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/NotebookCodeCell.tsx Applies parsed dimensions to rendered image elements.
src/vs/workbench/contrib/positronNotebook/test/browser/notebookOutputUtils.vitest.ts Adds tests for PNG parsing with and without retina metadata.

outputId: generateNotebookCellOutputId(),
outputs: outputItems,
metadata: { outputType, [outputIdKey]: message.output_id, executionCount },
metadata: { outputType, [outputIdKey]: message.output_id, executionCount, ...message.metadata },
}

if (mime === 'image/png') {
const imgMeta = (metadata?.[mime] ?? metadata) as { width?: number; height?: number } | undefined;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipython retina display does not work in notebooks

2 participants