Does XGetImage ever return a 32-bit depth XImage? - xlib

I am using XGetImage to read the pixels of an OpenGL window. The XImage that is returned shows a depth of 24-bits, but my OpenGL context has alpha values that I would like to be returned. Is there any way to get a 32-bit XImage from XGetImage, or does X already flatten the image to 24-bits?
Function call:
::XImage *winImage = XGetImage(dpy_i->dpy, wnd_i->wnd,
x, y, width, height, 0xffffffff, ZPixmap);
GDB output:
(gdb) print *winImage
$2 = {width = 640, height = 512, xoffset = 0, format = 2,
data = 0x7fffe72fd010 "\377\377\377", byte_order = 0,
bitmap_unit = 32, bitmap_bit_order = 0, bitmap_pad = 32,
depth = 24, bytes_per_line = 2560, bits_per_pixel = 32,
red_mask = 16711680, green_mask = 65280, blue_mask = 255,
obdata = 0x0, f = {create_image = 0x7ffff4b67810 <XCreateImage>,
destroy_image = 0x7ffff4b665b0, get_pixel = 0x7ffff4b67520,
put_pixel = 0x7ffff4b67450, sub_image = 0x7ffff4b67170,
add_pixel = 0x7ffff4b66650}}

I seem to always get a 32bit image. This is my code, js-ctypes, i take a screenshot of all monitors.
https://github.com/Noitidart/_scratchpad/blob/c41012b16842f0769595033bd51a3801451319be/x11%20new%20way%20skel%20non%20jsm.js
This is my XImage struct after XGetImage:
"width:" "1280" "height:" "919" "xoffset:" "0" "format:" "2" "data:" "ctypes.char.ptr(ctypes.UInt64("0x7f850fe00000"))" "byte_order:" "0" "bitmap_unit:" "32" "bitmap_bit_order:" "0" "bitmap_pad:" "32" "depth:" "24" "bytes_per_line:" "5120" "bits_per_pixel:" "32" "red_mask:" "16711680" "green_mask:" "65280" "blue_mask:" "255" "_END_"

Related

How to add relevant scale bars on inset maps using tmap

I used tmap to create the plot attached. However, I would like to add a scale bar to the inset map, but I haven't been able to figured out how to do that. Can someone please help me?
Here are the codes that I used to create the attached map:
main_map <- tmap::tm_shape(main_map_df) +
tmap::tm_polygons(
col = "var.q5",
palette = c("#CCCCCC", "#999999", "#666666", "#333333", "#000000"),
#alpha = 0.7,
lwd = 0.5,
title = "") +
tmap::tm_layout(
frame = FALSE,
legend.outside = TRUE,
legend.hist.width = 5,
legend.text.size = 0.5,
fontfamily = "Verdana") +
tmap::tm_scale_bar(
position = c("LEFT", "BOTTOM"),
breaks = c(0, 10, 20),
text.size = 0.5
) +
tmap::tm_compass(position = c("LEFT", "TOP"))
inset_map <- tmap::tm_shape(inset_map_df) +
tmap::tm_polygons() +
tmap::tm_shape(main_map_df) +
tm_fill("grey50") +
tmap::tm_scale_bar(
position = c("LEFT", "BOTTOM"),
breaks = c(0, 10, 20),
text.size = 0.5
)
# Combine crude rate map (inset + main) =====
tiff(
"main_map_w_iset.tiff",
height = 1200,
width = 1100,
compression = "lzw",
res = 300
)
main_map
print(
inset_map,
vp = viewport(
x = 0.7,
y = 0.18,
width = 0.3,
height = 0.3,
clip = "off")
)
dev.off()
Thank you!
Here's a simple example using the World data set:
library(tidyverse)
library(tmap)
library(grid)
data("World")
# main map
tm_main <- World %>%
filter(name == "Australia") %>%
tm_shape() +
tm_polygons(col = "red",
alpha = .5) +
tm_scale_bar()
# inset map
tm_inset <- tm_shape(World) +
tm_polygons(col = "gray",
alpha = .5) +
tm_scale_bar()
vp <- viewport(x = .615, y = .5, width = .6, height = .6, just = c("right", "top"))
# final map
tmap_save(tm_main, filename = "test_inset.png", insets_tm = tm_inset, insets_vp = vp,
height = 200, width = 200, units = "mm")

Can't reserve space for window with xcb

I'm trying to create a status bar in rust using xcb. I have written one already in C++ already using a mix of xcb and xlib so I'll be using that as a point of comparison. I'm also testing this on openbox which is a window manager written in xlib if that matters.
I'm currently unable to reserve space for my bar in the rust version. Below is the full output of xprop
WM_CLASS(STRING) = "onyxbar"
WM_NAME(STRING) = "bar"
_NET_WM_STRUT(CARDINAL) = 0, 0, 20, 0
_NET_WM_STRUT_PARTIAL(CARDINAL) = 0, 0, 20, 0, 0, 0, 0, 0, 1920, 3840, 0, 0
_NET_WM_STATE(ATOM) = _NET_WM_STATE_STICKY, _NET_WM_STATE_ABOVE
_NET_WM_WINDOW_TYPE(CARDINAL) = _NET_WM_WINDOW_TYPE_DOCK
you can see that the relevant _NET_WM_STRUT and _NET_WM_STRUT_PARTIAL are the same between this and the xprop output for my working bar in c++:
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_BELOW
_KDE_NET_WM_FRAME_STRUT(CARDINAL) = 0, 0, 0, 0
_NET_FRAME_EXTENTS(CARDINAL) = 0, 0, 0, 0
_NET_WM_ICON(CARDINAL) = Icon (48 x 48): (some big ascii icon)
_OB_APP_TYPE(UTF8_STRING) = "dock"
_OB_APP_TITLE(UTF8_STRING) = "bar"
_OB_APP_GROUP_CLASS(UTF8_STRING) =
_OB_APP_GROUP_NAME(UTF8_STRING) =
_OB_APP_CLASS(UTF8_STRING) =
_OB_APP_NAME(UTF8_STRING) = "limebar"
_OB_APP_ROLE(UTF8_STRING) =
_NET_WM_VISIBLE_ICON_NAME(UTF8_STRING) = "bar"
_NET_WM_VISIBLE_NAME(UTF8_STRING) = "bar"
WM_CLASS(STRING) = "limebar", "", "", "", "", ""
WM_NAME(STRING) = "bar"
_NET_WM_STRUT(CARDINAL) = 0, 0, 20, 0
_NET_WM_STRUT_PARTIAL(CARDINAL) = 0, 0, 20, 0, 0, 0, 0, 0, 1920, 3840, 0, 0
_NET_WM_DESKTOP(CARDINAL) = 4294967295
_NET_WM_STATE(ATOM) = _NET_WM_STATE_ABOVE
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DOCK
Now of course there's some extra info in the C++ version's output but it is my understanding that it's only _NET_WM_STRUT and _NET_WM_STRUT_PARTIAL that matter when it comes to reserving space. What am I missing here?
Your working example has a WM_STATE property. The non-working does not.
This property is set by the window manager when it manages a window. Are you perhaps creating an override-redirect window in the Rust version, but not in the C++ version?

What am I missing in order to create an UIGridLayout in code?

this is a question about creating a UIGridLayout. I know how to do this using the Studio menus, but I am trying to do it with only code. Here is my code:
local layout = Instance.new("UIGridLayout")
layout.Name = "UIGridLayout"
layout.Parent = script.Parent
layout.FillDirection = Enum.FillDirection.Horizontal
layout.CellPadding = UDim2.new(0, 100, 0, 5)
layout.CellSize = UDim2.new(0, 200, 0, 200)
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.SortOrder = Enum.SortOrder.LayoutOrder
layout.StartCorner = Enum.StartCorner.TopLeft
layout.VerticalAlignment = Enum.VerticalAlignment.Bottom
local teamFrame = Instance.new("Frame")
teamFrame.BackgroundTransparency = 0
teamFrame.LayoutOrder = 0
teamFrame.Parent = script.Parent
local lblTeamTag = Instance.new("TextLabel", teamFrame)
lblTeamTag.TextTransparency = 0
lblTeamTag.TextStrokeTransparency = 0
lblTeamTag.Name = "TeamTag"
lblTeamTag.Text = "Team"
lblTeamTag.Size = UDim2.new(0, 200, 0, 50)
lblTeamTag.Position = UDim2.new(0, 0, 0, 0)
local lblPoints = Instance.new("TextLabel", teamFrame)
lblPoints.TextStrokeTransparency = 0
lblPoints.BackgroundTransparency = 0
lblPoints.Name = "Points"
lblPoints.Text = "0"
lblPoints.Size = UDim2.new(0, 200, 0, 150)
lblPoints.Position = UDim2.new(0, 0, 0, 50)
The script where this code sits is a local script child of ScreenGui. I am expecting to see something like this:
But I got nothing. I know I am close. What am I missing. Many thanks
If what you're getting is just the TextLabels not being in the right places, it's because the UIGridLayout has to be inside the frame instead of being inside the same parent of the frame. So if you instance the UIGridLayout after instancing the frame and then making the frame the parent of the UIGridLayout it should work. Here's how it should be done so you can just copy and paste:
local teamFrame = Instance.new("Frame")
teamFrame.BackgroundTransparency = 0
teamFrame.LayoutOrder = 0
teamFrame.Parent = script.Parent
local layout = Instance.new("UIGridLayout")
layout.Name = "UIGridLayout"
layout.Parent = script.Parent
layout.FillDirection = Enum.FillDirection.Horizontal
layout.CellPadding = UDim2.new(0, 100, 0, 5)
layout.CellSize = UDim2.new(0, 200, 0, 200)
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.SortOrder = Enum.SortOrder.LayoutOrder
layout.StartCorner = Enum.StartCorner.TopLeft
layout.VerticalAlignment = Enum.VerticalAlignment.Bottom
local lblTeamTag = Instance.new("TextLabel", teamFrame)
lblTeamTag.TextTransparency = 0
lblTeamTag.TextStrokeTransparency = 0
lblTeamTag.Name = "TeamTag"
lblTeamTag.Text = "Team"
lblTeamTag.Size = UDim2.new(0, 200, 0, 50)
lblTeamTag.Position = UDim2.new(0, 0, 0, 0)
local lblPoints = Instance.new("TextLabel", teamFrame)
lblPoints.TextStrokeTransparency = 0
lblPoints.BackgroundTransparency = 0
lblPoints.Name = "Points"
lblPoints.Text = "0"
lblPoints.Size = UDim2.new(0, 200, 0, 150)
lblPoints.Position = UDim2.new(0, 0, 0, 50)

Ruby-Sketchup change color of faces

I would like to color the top of this shape to rfClr, any ideas? I can change the whole thing Grey, but how to change the top to blue?
l=100
w=60
h=20
hl=8
slope=4
clr='Gray'
rfClr='blue'
ent = Sketchup.active_model.entities
#---------Clear All
Sketchup.active_model.entities.clear!
#----------------
model = Sketchup.active_model
model.start_operation "Create Box"
#-----------------------------------------------------------------------------
entities = model.active_entities
group = entities.add_group
entities = group.entities
group.name="Box"
#pt0 = [0, 0, 0]
#pt1 = [0, 0, h*12+hl]
#pt2 = [w*12/2, 0, 12*h+hl+(w/2)*slope]
#pt3 = [w*12, 0, 12*h+hl]
#pt4 = [w*12, 0, 0]
newface = entities.add_face(#pt0, #pt1, #pt2, #pt3 , #pt4)
newface.material=Sketchup::Color.new clr
#newface.reverse!
newface.pushpull l*12
I found this answer.
I guess it finds the faces that have a z value
vfaces = entities.grep(Sketchup::Face).find_all{|f| f.normal.z.abs != 0 }
vfaces.each{|f| f.material = rfClr }

CreateDIBSection to get uint8_t[] of portion of screen

I am trying to get a uint8_t[] of a portion of the screen. The xy coordinates of the top left is 2,3 and of bottom right is 17,18.
This is the top 30x30 pixels of my screen with regular screenshot and photoshop crop:
And this is what 2,3 to 17,18 screenshot should look like via regular screenshot and Photoshop crop:
This is what I am getting as a result of my code:
My code is in js-ctypes but there is no ctypes errors. This is a winapi thing. So I didn't tag this with ctypes as they would be confused. This is the simplified code I am using, the error checks etc have been removed:
c1 = {x:2, y:3} // top left corner
c2 = {x:17, y:18} // bottom right corner
CreateDC('DISPLAY', null, null, null);
nBPP = GetDeviceCaps(hdcScreen, BITSPIXEL);
w = c2.x - c1.x; // width = 15
h = c2.y - c1.y; // height = 15
hdcMemoryDC = CreateCompatibleDC(hdcScreen);
bmi = BITMAPINFO();
bmi.bmiHeader.biSize = BITMAPINFOHEADER.size;
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = -1 * h;
bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = nBPP; // nBPP is 32
bmi.bmiHeader.biCompression = BI_RGB;
hbmp = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, (void**)&pixelBuffer, null, 0);
SelectObject(hdcMemoryDC, hbmp);
BitBlt(hdcMemoryDC, 0, 0, w, h, hdcScreen, c1.x, c1.y, SRCCOPY);
Why portion of screen bits come out wrong? If I do a full screen shot it works fine.

Resources