Skip to content

Commit cc9cbd0

Browse files
committed
added pixmap function pointers, fixed 24 bit fill bug, added more pixel testing, epx_pixel_format parsing and formating both in erlang and in C
1 parent 73072c7 commit cc9cbd0

24 files changed

+2109
-666
lines changed

Diff for: README

+15
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@ epx:start().
99
B = epx_backend:backend(BID).
1010
W=epx:window_create(0,0,1280,1024, [button_press, key_press, key_release]).
1111
epx:window_attach(W, B).
12+
13+
14+
* howto run framebuffer on vmware (ubuntu)
15+
16+
Append "vmwgfx.enable_fbdev=no" to GRUB_CMDLINE_LINUX_DEFAULT in
17+
file /etc/default/grub.
18+
"no" is not a correct value, driver will complain. But this
19+
is a bug workaround :-)
20+
May look something like this:
21+
22+
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet vmwgfx.enable_fbdev=no"
23+
24+
Then the fb driver may be probed:
25+
26+
sudo modprobe uvesafb

Diff for: c_src/README

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
Pixel formats
2+
=============
3+
4+
Epx pixel formats describe how the pixel channels are stored
5+
in memory, not how they are stored in a register when read
6+
from memory.
7+
For example the pixel format argb (identical with a8r8g8b8 and
8+
a8r8g8b8/big) describe the size and channel order of the pixels
9+
in memory.
10+
11+
> P = pixmap_create(1, 1, argb).
12+
> epx:pixmap_put_pixel(P,0,0,16#01020304).
13+
> epx:pixmap_put_pixel(P,0,0,{A,R,G,B}).
14+
> <<A,R,G,B>> = epx:pixmap_get_pixels(P, 0, 0, 1, 1).
15+
16+
The 16 bit formats are a bit more tricky, since they are normally
17+
given in terms of 16-bit words.
18+
19+
> P = pixmap_create(1, 1, r5g6b5).
20+
> epx:pixmap_put_pixel(P,0,0,{A,R,G,B}).
21+
> <<R1:5,G1:6,B1:5>> = epx:pixmap_get_pixels(P, 0, 0, 1, 1).
22+
23+
Note that R,G,B are in [0-255] range so that R1,G1,B1 are
24+
down scaled version, say R = 8 => R1 = 1.
25+
26+
A little endian version of the above 16-bit format may be
27+
given as:
28+
29+
> P = pixmap_create(1, 1, r5g6b5/little).
30+
> epx:pixmap_put_pixel(P1,0,0,{A,R,G,B}).
31+
> <<A0,A1>> = epx:pixmap_get_pixels(P, 0, 0, 1, 1)
32+
> <<R1:5,G1:6,B1:5>> = <<A1,A0>>
33+
34+
(There is a lack of a grouped little endian modifier in Erlang)
35+
36+
137
Pixel composition operations
238

339
Input pixels alpha and color components

Diff for: c_src/epx_anim.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void epx_anim_copy_frame(epx_pixmap_t* pic, epx_gc_t* gc, int x, int y,
182182
unsigned char *dst0 = EPX_PIXEL_ADDR(pic, x, y);
183183
int dst_wb = pic->bytes_per_row;
184184
epx_format_t src_format = src_pt;
185-
int srcPixelSize = EPX_PIXEL_SIZE(src_pt);
185+
int srcPixelSize = EPX_PIXEL_BYTE_SIZE(src_pt);
186186
epx_format_t dst_format = pic->pixel_format;
187187
int dstPixelSize = pic->bytes_per_pixel;
188188

@@ -270,7 +270,7 @@ void epx_anim_draw_frame(epx_pixmap_t* pic, epx_gc_t* gc, int x, int y,
270270
unsigned char *dst0 = EPX_PIXEL_ADDR(pic, x, y);
271271
int dst_wb = pic->bytes_per_row;
272272
epx_format_t src_format = src_pt;
273-
int srcPixelSize = EPX_PIXEL_SIZE(src_pt);
273+
int srcPixelSize = EPX_PIXEL_BYTE_SIZE(src_pt);
274274
epx_format_t dst_format = pic->pixel_format;
275275
int dstPixelSize = pic->bytes_per_pixel;
276276
epx_rect_t r = {{x,y}, {width,height}};

Diff for: c_src/epx_area_body.i

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void AREA_FUNCTION(uint8_t* src, int src_wb, epx_format_t src_pt,
3434
epx_pixel_unpack_t unpack_src;
3535
epx_pixel_pack_t pack_dst;
3636

37-
src_psz = EPX_PIXEL_SIZE(src_pt);
38-
dst_psz = EPX_PIXEL_SIZE(dst_pt);
37+
src_psz = EPX_PIXEL_BYTE_SIZE(src_pt);
38+
dst_psz = EPX_PIXEL_BYTE_SIZE(dst_pt);
3939
unpack_src = epx_pixel_unpack_func(src_pt);
4040
unpack_dst = epx_pixel_unpack_func(dst_pt);
4141
pack_dst = epx_pixel_pack_func(dst_pt);

Diff for: c_src/epx_backend_fb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ static void fb_mod_vinfo(epx_dict_t *param, struct fb_var_screeninfo *vinfo)
527527
if (epx_dict_lookup_string(param,"pixel_format",&string_param,NULL) != -1) {
528528
epx_format_t fmt = epx_pixel_format_from_name(string_param);
529529
if (fmt != EPX_FORMAT_INVALID)
530-
vinfo->bits_per_pixel = EPX_PIXEL_SIZE(fmt)*8;
530+
vinfo->bits_per_pixel = EPX_PIXEL_BIT_SIZE(fmt);
531531
}
532532
else {
533533
if (epx_dict_lookup_integer(param, "pixel_type", &int_param) != -1) {
534-
vinfo->bits_per_pixel = EPX_PIXEL_SIZE(int_param)*8;
534+
vinfo->bits_per_pixel = EPX_PIXEL_BIT_SIZE(int_param);
535535
}
536536
}
537537

Diff for: c_src/epx_backend_macos.c

+1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ static int carbon_pix_detach(epx_backend_t* backend, epx_pixmap_t* pixmap)
529529
CGColorSpaceRelease(pe->colorspace);
530530
CGDataProviderRelease(pe->provider);
531531
epx_object_unlink(&backend->pixmap_list, pixmap);
532+
// FIXME: free(pe) ?
532533
pixmap->opaque = 0;
533534
pixmap->backend = 0;
534535
}

Diff for: c_src/epx_draw.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ void epx_pixmap_draw_point(epx_pixmap_t* pic, epx_gc_t* gc, int x, int y)
7171
return;
7272
dst = EPX_PIXEL_ADDR(pic,x,y);
7373
if (!gc) gc = &epx_default_gc;
74-
put_apixel(dst,pic->unpack,pic->pack,gc->line_style,gc->foreground_color);
74+
put_apixel(dst,pic->func.unpack,pic->func.pack,
75+
gc->line_style,gc->foreground_color);
7576
}
7677

7778

Diff for: c_src/epx_font.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void epx_compressed_add_color_area(epx_pixmap_t* src,epx_pixmap_t* dst,
373373
width = dr.wh.width;
374374
height = dr.wh.height;
375375

376-
dst_psz = EPX_PIXEL_SIZE(dst->pixel_format);
376+
dst_psz = EPX_PIXEL_BYTE_SIZE(dst->pixel_format);
377377

378378
if ((flags&EPX_FLAG_BLEND) == 0) {
379379
while(height--) {
@@ -388,7 +388,7 @@ void epx_compressed_add_color_area(epx_pixmap_t* src,epx_pixmap_t* dst,
388388
s = epx_pixel_add(color,s);
389389
s.a = ((s.a * fader) >> 8);
390390
s = epx_pixel_shadow(s.a, s);
391-
dst->pack(s, dptr1);
391+
dst->func.pack(s, dptr1);
392392
dptr1 += dst_psz;
393393
}
394394
epx_fnt2_skip(&ctx, src_wb - width);
@@ -404,15 +404,15 @@ void epx_compressed_add_color_area(epx_pixmap_t* src,epx_pixmap_t* dst,
404404
epx_pixel_t s;
405405
epx_pixel_t d;
406406

407-
d = dst->unpack(dptr1);
407+
d = dst->func.unpack(dptr1);
408408
s.px = 0;
409409
s.a = epx_fnt2_ctx_next(&ctx);
410410

411411
/* add the color to source */
412412
s = epx_pixel_add(color,s);
413413
s.a = ((s.a * fader) >> 8);
414414
d = epx_pixel_blend(s.a, s, d);
415-
dst->pack(d, dptr1);
415+
dst->func.pack(d, dptr1);
416416
dptr1 += dst_psz;
417417
}
418418
epx_fnt2_skip(&ctx, src_wb - width);
@@ -461,7 +461,7 @@ void epx_font_draw_glyph(epx_gc_t* gc, epx_pixmap_t* dst, int* x, int* y, int c)
461461
/* Set dst = 0 to determine change in x and y */
462462
if (dst != 0) {
463463
uint16_t pixel_format = font->font_info.pixel_format;
464-
int psz = EPX_PIXEL_SIZE(pixel_format);
464+
int psz = EPX_PIXEL_BYTE_SIZE(pixel_format);
465465
unsigned int bytes_per_row;
466466
epx_pixmap_t gmap;
467467

Diff for: c_src/epx_line.c

+33-19
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void epx_draw_line_vertical(epx_pixmap_t* pic, int x, int y1, int y2,
172172
y2 = epx_clip_range(y2, yt, yb);
173173
ptr = EPX_PIXEL_ADDR(pic,x,y1);
174174
while(y1 <= y2) {
175-
put_apixel(ptr, pic->unpack, pic->pack, flags, fg);
175+
put_apixel(ptr, pic->func.unpack, pic->func.pack, flags, fg);
176176
y1++;
177177
ptr += pic->bytes_per_row;
178178
}
@@ -260,26 +260,31 @@ void trace_aalias_line_1(epx_pixmap_t* pic, epx_line_t* line, int flags,
260260
/* put alias point below */
261261
if (epx_point_xy_in_rect(L(x0,0),L(y0,0)-L(sy,0), &pic->clip)) {
262262
fa.a = -ae;
263-
put_apixel(L(ptr,0)-L(wsy,0), pic->unpack,pic->pack, flags, fa);
263+
put_apixel(L(ptr,0)-L(wsy,0), pic->func.unpack,
264+
pic->func.pack, flags, fa);
264265
}
265266
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
266267
fa.a = a+ae;
267-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fa);
268+
put_apixel(L(ptr,0),pic->func.unpack,pic->func.pack,
269+
flags, fa);
268270
}
269271
}
270272
else if (ae > 0) {
271273
/* put alias point abow */
272274
if (epx_point_xy_in_rect(L(x0,0),L(y0,0)+L(sy,0), &pic->clip)) {
273275
fa.a = ae;
274-
put_apixel(L(ptr,0)+L(wsy,0), pic->unpack,pic->pack, flags, fa);
276+
put_apixel(L(ptr,0)+L(wsy,0), pic->func.unpack,
277+
pic->func.pack, flags, fa);
275278
}
276279
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
277280
fa.a = a-ae;
278-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fa);
281+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
282+
flags, fa);
279283
}
280284
}
281285
else if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
282-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fg);
286+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
287+
flags, fg);
283288
}
284289
}
285290
}
@@ -294,26 +299,31 @@ void trace_aalias_line_1(epx_pixmap_t* pic, epx_line_t* line, int flags,
294299
/* put alias point left */
295300
if (epx_point_xy_in_rect(L(x0,0)-L(sx,0),L(y0,0), &pic->clip)) {
296301
fa.a = -ae;
297-
put_apixel(L(ptr,0)-L(wsx,0), pic->unpack,pic->pack, flags, fa);
302+
put_apixel(L(ptr,0)-L(wsx,0),pic->func.unpack,
303+
pic->func.pack,flags,fa);
298304
}
299305
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
300306
fa.a = a+ae;
301-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fa);
307+
put_apixel(L(ptr,0),pic->func.unpack,pic->func.pack,
308+
flags, fa);
302309
}
303310
}
304311
else if (ae > 0) {
305312
/* put alias point right */
306313
if (epx_point_xy_in_rect(L(x0,0)+L(sx,0),L(y0,0), &pic->clip)) {
307314
fa.a = ae;
308-
put_apixel(L(ptr,0)+L(wsx,0), pic->unpack,pic->pack, flags, fa);
315+
put_apixel(L(ptr,0)+L(wsx,0), pic->func.unpack,
316+
pic->func.pack,flags,fa);
309317
}
310318
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
311319
fa.a = a-ae;
312-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fa);
320+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
321+
flags, fa);
313322
}
314323
}
315324
else if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
316-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fg);
325+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
326+
flags, fg);
317327
}
318328
}
319329
}
@@ -336,7 +346,8 @@ void trace_line_1(epx_pixmap_t* pic, epx_line_t* line, int flags, epx_pixel_t fg
336346
L(y0,0),L(dy,0),L(sy,0),L(wsy,0));
337347
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
338348
// fprintf(stderr, "(%d,%d,%p)\r\n", L(x0,0), L(y0,0),L(ptr,0));
339-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fg);
349+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
350+
flags, fg);
340351
// fprintf(stderr, "OK\r\n");
341352
}
342353
}
@@ -348,7 +359,8 @@ void trace_line_1(epx_pixmap_t* pic, epx_line_t* line, int flags, epx_pixel_t fg
348359
L(x0,0),L(dx,0),L(sx,0),L(wsx,0));
349360
if (epx_point_xy_in_rect(L(x0,0),L(y0,0), &pic->clip)) {
350361
// fprintf(stderr, "(%d,%d,%p)\r\n", L(x0,0), L(y0,0), L(ptr,0));
351-
put_apixel(L(ptr,0), pic->unpack,pic->pack, flags, fg);
362+
put_apixel(L(ptr,0), pic->func.unpack,pic->func.pack,
363+
flags, fg);
352364
// fprintf(stderr, "OK\r\n");
353365
}
354366
}
@@ -774,12 +786,13 @@ void epx_draw_line_thick(epx_pixmap_t* pic,
774786
eacc += eadj;
775787
w = eacc >> 8;
776788
if (((i != 0) || !(flags&EPX_LINE_STYLE_NFIRST))) {
777-
draw_dline(ptr, pic->unpack,pic->pack, tk,
789+
draw_dline(ptr, pic->func.unpack,pic->func.pack, tk,
778790
-d0, d1, kt, ks, kd, ku, kv,
779791
x0, y0, sx, sy, sxw, syw,
780792
x2, x3, y2, y3, line_width,flags,fg);
781793
if (epx_in_range(y0-sy, y2, y3))
782-
put_wu_apixel(ptr-syw,pic->unpack,pic->pack,w^255,flags,ag,wl);
794+
put_wu_apixel(ptr-syw,pic->func.unpack,pic->func.pack,
795+
w^255,flags,ag,wl);
783796
}
784797
if (d0 >= kt) {
785798
d0 -= ku;
@@ -790,7 +803,7 @@ void epx_draw_line_thick(epx_pixmap_t* pic,
790803
else {
791804
y0 += sy; ptr += syw;
792805
d1 += kd;
793-
draw_dline(ptr, pic->unpack,pic->pack, tk,
806+
draw_dline(ptr, pic->func.unpack,pic->func.pack, tk,
794807
-d0, d1, kt, ks, kd, ku, kv,
795808
x0, y0, sx, sy, sxw, syw,
796809
x2, x3, y2, y3, line_width,flags,fg);
@@ -822,12 +835,13 @@ void epx_draw_line_thick(epx_pixmap_t* pic,
822835
eacc += eadj;
823836
w = eacc >> 8;
824837
if (((i != 0) || !(flags&EPX_LINE_STYLE_NFIRST))) {
825-
draw_dline(ptr, pic->unpack,pic->pack, tk,
838+
draw_dline(ptr, pic->func.unpack,pic->func.pack, tk,
826839
-d0, d1, kt, ks, kd, ku, kv,
827840
x0, y0, sx, sy, sxw, syw,
828841
x2, x3, y2, y3, line_width,flags,fg);
829842
if (epx_in_range(x0-sx,x2,x3))
830-
put_wu_apixel(ptr-sxw,pic->unpack,pic->pack,w^255,flags,ag,wl);
843+
put_wu_apixel(ptr-sxw,pic->func.unpack,pic->func.pack,
844+
w^255,flags,ag,wl);
831845
}
832846
if (d0 >= kt) {
833847
d0 -= kv;
@@ -838,7 +852,7 @@ void epx_draw_line_thick(epx_pixmap_t* pic,
838852
else {
839853
x0 += sx; ptr += sxw;
840854
d1 += kd;
841-
draw_dline(ptr, pic->unpack,pic->pack, tk,
855+
draw_dline(ptr, pic->func.unpack,pic->func.pack, tk,
842856
-d0, d1, kt, ks, kd, ku, kv,
843857
x0, y0, sx, sy, sxw, syw,
844858
x2, x3, y2, y3,line_width,flags,fg);

0 commit comments

Comments
 (0)