-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbitmap_ximage.c
73 lines (65 loc) · 2.07 KB
/
bitmap_ximage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2021 Justin Meiners
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bitmap.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
static inline
CcPixel swap1_pixel_(CcPixel x)
{
return x >> 8;
//return cc_color_swap(x) >> 8;
/*
return ((x & 0xFF000000) >> 24) |
((x & 0x00FF0000) >> 8) |
((x & 0x0000FF00) << 8) |
((x & 0x000000FF) << 24);
*/
}
static inline
void swap1_(
char *dst,
size_t stride,
int w,
int h) {
while (h)
{
CcPixel *row = (CcPixel *)dst;
for (int col = 0; col < w; ++col) {
row[col] = swap1_pixel_(row[col]);
}
dst += stride;
--h;
}
}
void cc_bitmap_swap_for_xvisual(CcBitmap *b, const XVisualInfo *info)
{
// https://groups.google.com/g/comp.windows.x/c/c4tjX7UiuVU
if (info->red_mask == 0x00FF0000
&& info->green_mask == 0x0000FF00
&& info->blue_mask == 0x000000FF) {
swap1_((char *)b->data, sizeof(CcPixel) * b->w, b->w, b->h);
} else {
assert(0); // need to change formats
}
}
XImage *cc_bitmap_create_ximage(CcBitmap *b, Display *display, Visual *visual)
{
// What is bitmap_pad?
// the documentation isn't clear, but I found:
// "This is a very roundabout way of describing the pixel size in bits."
// https://handmade.network/wiki/2834-tutorial_a_tour_through_xlib_and_related_technologies
return XCreateImage(display, visual, 24, ZPixmap, 0, (char *)b->data, b->w, b->h, 32, b->w * sizeof(CcPixel));
}