mirror of
https://github.com/elementary/gala.git
synced 2024-11-25 03:06:14 +01:00
I have no idea what i'm doing
This commit is contained in:
parent
3373f8ae4c
commit
ee6c1f20e3
@ -326,7 +326,7 @@ namespace Gala {
|
||||
}
|
||||
|
||||
try {
|
||||
var screenshot = Gdk.pixbuf_get_from_surface (image, 0, 0, image.get_width (), image.get_height ());
|
||||
var screenshot = ScreenshotUtils.pixbuf_from_surface (image, image.get_width (), image.get_height ());
|
||||
var file = File.new_for_path (used_filename);
|
||||
FileIOStream stream;
|
||||
if (file.query_exists ()) {
|
||||
@ -348,7 +348,7 @@ namespace Gala {
|
||||
unowned Gdk.Display display = Gdk.Display.get_default ();
|
||||
unowned Gtk.Clipboard clipboard = Gtk.Clipboard.get_default (display);
|
||||
|
||||
var screenshot = Gdk.pixbuf_get_from_surface (image, 0, 0, image.get_width (), image.get_height ());
|
||||
var screenshot = ScreenshotUtils.pixbuf_from_surface (image, image.get_width (), image.get_height ());
|
||||
if (screenshot == null) {
|
||||
warning ("could not save screenshot to clipboard: null pixbuf");
|
||||
return false;
|
||||
@ -388,15 +388,17 @@ namespace Gala {
|
||||
|
||||
try {
|
||||
if (GLib.ByteOrder.HOST == GLib.ByteOrder.LITTLE_ENDIAN) {
|
||||
warning ("first");
|
||||
wm.stage.paint_to_buffer (
|
||||
{x, y, width, height},
|
||||
scale,
|
||||
image.get_data (),
|
||||
image.get_stride (),
|
||||
Cogl.PixelFormat.BGRA_8888_PRE,
|
||||
Cogl.PixelFormat.CAIRO_ARGB32_COMPAT,
|
||||
paint_flags
|
||||
);
|
||||
} else {
|
||||
warning ("second");
|
||||
wm.stage.paint_to_buffer (
|
||||
{x, y, width, height},
|
||||
scale,
|
110
src/ScreenshotManager/ScreenshotUtils.vala
Normal file
110
src/ScreenshotManager/ScreenshotUtils.vala
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
|
||||
*/
|
||||
|
||||
namespace Gala.ScreenshotUtils {
|
||||
private Cairo.Format cairo_format_for_content (Cairo.Content content) {
|
||||
switch (content) {
|
||||
case Cairo.Content.COLOR:
|
||||
return Cairo.Format.RGB24;
|
||||
case Cairo.Content.ALPHA:
|
||||
return Cairo.Format.A8;
|
||||
case Cairo.Content.COLOR_ALPHA:
|
||||
default:
|
||||
return Cairo.Format.ARGB32;
|
||||
}
|
||||
}
|
||||
|
||||
private Cairo.ImageSurface cairo_surface_coerce_to_image (
|
||||
Cairo.Surface surface,
|
||||
Cairo.Content content,
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
var copy = new Cairo.ImageSurface (cairo_format_for_content (content), width, height);
|
||||
|
||||
var cr = new Cairo.Context (copy);
|
||||
cr.set_operator (Cairo.Operator.SOURCE);
|
||||
cr.set_source_surface (surface, 0, 0);
|
||||
cr.paint ();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Gdk.Pixbuf? pixbuf_from_surface (
|
||||
Cairo.ImageSurface surface,
|
||||
int width,
|
||||
int height
|
||||
) requires (surface != null && width > 0 && height > 0) {
|
||||
var content = surface.get_content () | Cairo.Content.COLOR;
|
||||
var has_alpha = (content & Cairo.Content.ALPHA) == Cairo.Content.ALPHA;
|
||||
var dest = new Gdk.Pixbuf (RGB, has_alpha, 8, width, height);
|
||||
|
||||
Cairo.ImageSurface new_surface;
|
||||
if (surface.get_format () == cairo_format_for_content (content)) {
|
||||
warning ("Same surface");
|
||||
new_surface = surface;
|
||||
} else {
|
||||
warning ("New surface");
|
||||
new_surface = cairo_surface_coerce_to_image (surface, content, width, height);
|
||||
}
|
||||
|
||||
// new_surface.flush ();
|
||||
if (new_surface.status () != Cairo.Status.SUCCESS || dest == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var dest_data = dest.get_pixels ();
|
||||
var dest_stride = dest.get_rowstride ();
|
||||
var src_data = surface.get_data ();
|
||||
var src_stride = surface.get_stride ();
|
||||
|
||||
warning ("%i", src_data.length);
|
||||
|
||||
if (has_alpha) {
|
||||
warning ("Here");
|
||||
for (var y = 0; y < height; y++) {
|
||||
// var src = (uint32[]) src_data;
|
||||
|
||||
for (var x = 0; x < width; x++) {
|
||||
// warning ("%i", src_data[x]);
|
||||
// warning ("%i", src_data[x] >> 24);
|
||||
// var alpha = (uint8) (((uint32) src_data[x]) >> 24);
|
||||
|
||||
// if (alpha == 0) {
|
||||
// dest_data[x * 4 + 0] = 0;
|
||||
// dest_data[x * 4 + 1] = 0;
|
||||
// dest_data[x * 4 + 2] = 0;
|
||||
// } else {
|
||||
// dest_data[x * 4 + 0] = (uint8) (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
|
||||
// dest_data[x * 4 + 1] = (uint8) (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
|
||||
// dest_data[x * 4 + 2] = (uint8) (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
|
||||
// }
|
||||
|
||||
// dest_data[x * 4 + 3] = alpha;
|
||||
}
|
||||
|
||||
// src_data += (uint8) src_stride;
|
||||
// dest_data += (uint8) dest_stride;
|
||||
}
|
||||
} else {
|
||||
for (var y = 0; y < height; y++) {
|
||||
var src = (uint32[]) src_data;
|
||||
|
||||
for (var x = 0; x < width; x++) {
|
||||
dest_data[x * 3 + 0] = (uint8) (src[x] >> 16);
|
||||
dest_data[x * 3 + 1] = (uint8) src[x] >> 8;
|
||||
dest_data[x * 3 + 2] = (uint8) src[x];
|
||||
}
|
||||
|
||||
src_data += (uint8) src_stride;
|
||||
dest_data += (uint8) dest_stride;
|
||||
}
|
||||
}
|
||||
|
||||
dest = new Gdk.Pixbuf.from_data (dest_data, RGB, has_alpha, 8, width, height, dest_stride);
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ gala_bin_sources = files(
|
||||
'PantheonShell.vala',
|
||||
'PluginManager.vala',
|
||||
'ScreenSaverManager.vala',
|
||||
'ScreenshotManager.vala',
|
||||
'SessionManager.vala',
|
||||
'WindowGrabTracker.vala',
|
||||
'WindowListener.vala',
|
||||
@ -40,6 +39,8 @@ gala_bin_sources = files(
|
||||
'HotCorners/Barrier.vala',
|
||||
'HotCorners/HotCorner.vala',
|
||||
'HotCorners/HotCornerManager.vala',
|
||||
'ScreenshotManager/ScreenshotManager.vala',
|
||||
'ScreenshotManager/ScreenshotUtils.vala',
|
||||
'ShellClients/CenteredWindow.vala',
|
||||
'ShellClients/HideTracker.vala',
|
||||
'ShellClients/ManagedClient.vala',
|
||||
|
Loading…
Reference in New Issue
Block a user