Skip to content

Commit

Permalink
Merge pull request #21 from djdt/color_image_fixes
Browse files Browse the repository at this point in the history
Color image fixes #2
  • Loading branch information
djdt authored Aug 8, 2024
2 parents 1596c94 + fdfde43 commit 294c2c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pewpew/graphics/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def generate_laser_image(
colorbar: bool = True,
raw: bool = False,
size: QtCore.QSize | None = None,
scale: float = 1.0,
dpi: int = 96,
) -> QtGui.QImage:
data = laser.get(element, calibrate=options.calibrate, flat=True)
Expand Down Expand Up @@ -219,7 +220,7 @@ def generate_laser_image(
# Draw the scale-bar
if scalebar_alignment is not None:
x0, x1, y0, y1 = laser.extent
scale = (x1 - x0) / pixmap.width()
scale = (x1 - x0) / pixmap.width() / scale
paint_scalebar(painter, xh * 10.0, text_bounds, scalebar_alignment, scale)

painter.end()
Expand All @@ -243,6 +244,7 @@ def generate_rgb_laser_image(
raw: bool = False,
subtractive: bool = False,
size: QtCore.QSize | None = None,
scale: float = 1.0,
dpi: int = 96,
) -> QtGui.QImage:
data = np.zeros((*laser.shape[:2], 3))
Expand Down Expand Up @@ -319,7 +321,7 @@ def generate_rgb_laser_image(
# Draw the scale-bar
if scalebar_alignment is not None:
x0, x1, y0, y1 = laser.extent
scale = (x1 - x0) / image.rect().width()
scale = (x1 - x0) / image.rect().width() / scale
paint_scalebar(painter, xh * 10.0, text_bounds, scalebar_alignment, scale)

# Draw the color Venn
Expand Down
13 changes: 11 additions & 2 deletions pewpew/widgets/exportdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ def updateSizeLabel(self) -> None:
def scale(self) -> int:
return self.spin_scale.value()

def imageSize(self) -> QtCore.QSize:
return QtCore.QSize(
self.base_size.width() * self.spin_scale.value(),
self.base_size.height() * self.spin_scale.value(),
)

def dpi(self) -> int:
return int(self.le_dpi.text())

Expand Down Expand Up @@ -494,7 +500,6 @@ def __init__(
apparent_size.setWidth(int(apparent_size.width() * aspect))
elif aspect < 1:
apparent_size.setHeight(int(apparent_size.height() / aspect))
print(aspect, apparent_size, item.imageSize())

if isinstance(item, RGBLaserImageItem):
options = [RBGOptionsBox(apparent_size, item.current_elements)]
Expand Down Expand Up @@ -614,6 +619,7 @@ def export(
assert graphics_options is not None
if isinstance(option, RBGOptionsBox):
size = option.imageSize()
scale = option.scale()
if any(x in laser.elements for x in option.elements()):
image = generate_rgb_laser_image(
laser,
Expand All @@ -626,14 +632,16 @@ def export(
venn_alignment=option.vennAlignment(),
raw=option.isRaw(),
size=size,
scale=scale,
dpi=option.dpi(),
)
image.setDotsPerMeterX(option.dpi() * 39.37007874)
image.setDotsPerMeterY(option.dpi() * 39.37007874)
image.save(str(path.absolute()))
else:
size = option.imageSize()
scale = option.scale()
if element is not None and element in laser.elements:
size = option.imageSize()
image = generate_laser_image(
laser,
element,
Expand All @@ -643,6 +651,7 @@ def export(
colorbar=option.useColorbar(),
raw=option.isRaw(),
size=size,
scale=scale,
dpi=option.dpi(),
)
image.setDotsPerMeterX(option.dpi() * 39.37007874)
Expand Down

0 comments on commit 294c2c6

Please sign in to comment.