Skip to content

Commit 3f182e9

Browse files
committed
FEAT: GOB to image conversion on Windows -> to-image make gob! []
1 parent 6d42d36 commit 3f182e9

File tree

4 files changed

+66
-55
lines changed

4 files changed

+66
-55
lines changed

src/core/t-image.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,14 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
10341034
case A_TO:
10351035
if (IS_IMAGE(arg)) goto makeCopy;
10361036
else if (IS_GOB(arg)) {
1037+
//originally it was returning image without content when conversion failed!
10371038
//value = Make_Image(ROUND_TO_INT(GOB_W(VAL_GOB(arg))), ROUND_TO_INT(GOB_H(VAL_GOB(arg))));
1038-
//*D_RET = *value;
1039+
#ifndef TO_WINDOWS
1040+
//TODO: remove this once OS_GOB_TO_IMAGE will be for all systems
1041+
Trap0(RE_FEATURE_NA);
1042+
#else
10391043
series = OS_GOB_TO_IMAGE(VAL_GOB(arg));
1044+
#endif
10401045
if (!series) Trap_Make(REB_IMAGE, arg);
10411046
SET_IMAGE(value, series);
10421047
break;

src/include/reb-compositor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct rebol_compositor_ctx {
4242
REBGOB *root_gob;
4343
REBGOB *wind_gob;
4444
REBXYI wind_size;
45-
//REBYTE *wind_buffer; // was used for AGG
45+
REBYTE *wind_buffer; // can be used for conversion to image; was also used with AGG
4646
#ifdef TO_WINDOWS
4747
HDC wind_DC;
4848
HBITMAP back_buffer;

src/os/win32/host-compositor.c

+59-29
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ static REBXYF Zero_Pair = {0, 0};
121121
}
122122

123123

124+
/***********************************************************************
125+
**
126+
*/ REBYTE* OS_Get_Window_Buffer(REBCMP* ctx)
127+
/*
128+
** Provide pointer to window compositing buffer.
129+
** Return NULL if buffer not available of call failed.
130+
**
131+
** NOTE: The buffer may be "locked" during this call on some platforms.
132+
** Always call Os_Release_Window_Buffer(ctx) to be sure it is released.
133+
**
134+
***********************************************************************/
135+
{
136+
return ctx->wind_buffer;
137+
}
138+
139+
/***********************************************************************
140+
**
141+
*/ void OS_Release_Window_Buffer(REBCMP* ctx)
142+
/*
143+
** Release the window compositing buffer acquired by Os_Get_Window_Buffer().
144+
**
145+
** NOTE: this call can be "no-op" on platforms that don't need locking.
146+
**
147+
***********************************************************************/
148+
{
149+
}
150+
151+
124152
/***********************************************************************
125153
**
126154
*/ REBOOL OS_Resize_Window_Buffer(REBCMP* ctx, REBGOB* winGob)
@@ -179,7 +207,7 @@ static REBXYF Zero_Pair = {0, 0};
179207
//make the new buffer actual
180208
ctx->back_buffer = new_buffer;
181209
ctx->back_DC = new_DC;
182-
//ctx->wind_buffer = new_bytes;
210+
ctx->wind_buffer = new_bytes;
183211

184212
//set window clip region
185213
// SetRectRgn(ctx->win_clip, 0, 0, w, h);
@@ -383,6 +411,36 @@ static REBXYF Zero_Pair = {0, 0};
383411
GOB_HO(gob) = GOB_LOG_H(gob);
384412
}
385413

414+
415+
/***********************************************************************
416+
**
417+
*/ REBSER* OS_Gob_To_Image(REBGOB *gob)
418+
/*
419+
** Render gob into an image.
420+
**
421+
***********************************************************************/
422+
{
423+
REBINT w, h;
424+
REBSER *img;
425+
REBCMP *cmp;
426+
427+
w = GOB_LOG_W_INT(gob);
428+
h = GOB_LOG_H_INT(gob);
429+
img = (REBSER*)RL_MAKE_IMAGE(w, h);
430+
431+
cmp = OS_Create_Compositor(Gob_Root, gob);
432+
OS_Compose_Gob(cmp, gob, gob, TRUE);
433+
434+
//copy the composed result to image
435+
memcpy((REBYTE *)RL_SERIES(img, RXI_SER_DATA), OS_Get_Window_Buffer(cmp), w * h * 4);
436+
437+
OS_Release_Window_Buffer(cmp);
438+
OS_Destroy_Compositor(cmp);
439+
440+
return img;
441+
}
442+
443+
386444
/***********************************************************************
387445
**
388446
*/ void OS_Blit_Window(REBCMP* ctx)
@@ -466,31 +524,3 @@ static REBXYF Zero_Pair = {0, 0};
466524
}
467525

468526

469-
#ifdef UNUSED_OLD_COMPOSITOR_CODE
470-
/***********************************************************************
471-
**
472-
*/ REBYTE* rebcmp_get_buffer(REBCMP* ctx)
473-
/*
474-
** Provide pointer to window compositing buffer.
475-
** Return NULL if buffer not available of call failed.
476-
**
477-
** NOTE: The buffer may be "locked" during this call on some platforms.
478-
** Always call rebcmp_release_buffer() to be sure it is released.
479-
**
480-
***********************************************************************/
481-
{
482-
return ctx->wind_buffer;
483-
}
484-
485-
/***********************************************************************
486-
**
487-
*/ void rebcmp_release_buffer(REBCMP* ctx)
488-
/*
489-
** Release the window compositing buffer acquired by rebcmp_get_buffer().
490-
**
491-
** NOTE: this call can be "no-op" on platforms that don't need locking.
492-
**
493-
***********************************************************************/
494-
{
495-
}
496-
#endif

src/os/win32/host-lib.c

-24
Original file line numberDiff line numberDiff line change
@@ -1319,27 +1319,3 @@ static void *Task_Ready;
13191319
return ret;
13201320
}
13211321

1322-
1323-
/***********************************************************************
1324-
**
1325-
*/ REBSER *OS_GOB_To_Image(REBGOB *gob)
1326-
/*
1327-
** Render a GOB into an image. Returns an image or zero if
1328-
** it cannot be done.
1329-
**
1330-
***********************************************************************/
1331-
{
1332-
1333-
#ifndef REB_CORE
1334-
1335-
#ifndef NO_COMPOSITOR
1336-
return (REBSER*)Gob_To_Image(gob);
1337-
#else
1338-
return 0;
1339-
#endif
1340-
1341-
#else
1342-
return 0;
1343-
#endif
1344-
1345-
}

0 commit comments

Comments
 (0)