[cairo-commit] libglc/src glc.h,1.4,1.5 glc_glx_surface.c,1.6,1.7 glc_surface.c,1.6,1.7
Peter Nilsson
commit at pdx.freedesktop.org
Tue Dec 9 02:35:59 PST 2003
Committed by: peter
Update of /cvs/cairo/libglc/src
In directory pdx:/tmp/cvs-serv4250/src
Modified Files:
glc.h glc_glx_surface.c glc_surface.c
Log Message:
Moved read/draw pixels from glx backend to glc core
Index: glc.h
===================================================================
RCS file: /cvs/cairo/libglc/src/glc.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** glc.h 7 Dec 2003 02:42:29 -0000 1.4
--- glc.h 9 Dec 2003 10:35:57 -0000 1.5
***************
*** 220,224 ****
extern glc_status_t __external_linkage
glc_surface_get_status (glc_surface_t *surface);
-
/* glc_rect.c */
--- 220,223 ----
***************
*** 419,441 ****
glc_glx_surface_swap_buffers (glc_surface_t *surface);
- void
- glc_glx_surface_read_pixels (glc_surface_t *surface,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- char *pixels);
-
- void
- glc_glx_surface_draw_pixels (glc_surface_t *surface,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- char *pixels);
-
#endif /* LIBGLC_HAS_GLX_BACKEND */
!
#if defined(__cplusplus) || defined(c_plusplus)
}
--- 418,424 ----
glc_glx_surface_swap_buffers (glc_surface_t *surface);
#endif /* LIBGLC_HAS_GLX_BACKEND */
!
#if defined(__cplusplus) || defined(c_plusplus)
}
Index: glc_glx_surface.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_glx_surface.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** glc_glx_surface.c 8 Dec 2003 21:03:33 -0000 1.6
--- glc_glx_surface.c 9 Dec 2003 10:35:57 -0000 1.7
***************
*** 385,538 ****
glc_glx_context_pop_current (glx_surface->context);
}
-
- void
- glc_glx_surface_read_pixels (glc_surface_t *surface,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- char *pixels)
- {
- unsigned char *pixel_buf;
- int rowstride, area_rowstride, pixelsize;
- unsigned int i;
- GLenum format, type;
- glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
-
- if (x < 0 || x > (int) glx_surface->base.width - (int) width ||
- y < 0 || y > (int) glx_surface->base.height - (int) height) {
- glc_surface_status_add (surface, GLC_STATUS_BAD_COORDINATE_MASK);
- return;
- }
-
- pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
- format = glc_get_texture_format_from_pixelsize (pixelsize);
- type = glc_get_texture_data_type_from_pixelsize (pixelsize);
-
- /* We currently read the whole image to a temporary buffer and then
- copy the part we want, not very efficient. We only want to read the
- area requested. I think it can be fixed with glPixelStore parameters. */
- rowstride = surface->real_width * pixelsize;
- rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
-
- pixel_buf = (unsigned char *) malloc (surface->real_height * rowstride);
-
- glc_surface_push_current (surface);
-
- if (surface->type != GLC_SURFACE_TEXTURE_TYPE) {
- glReadPixels (0, 0, surface->real_width, surface->real_height,
- format, type, pixel_buf);
- } else {
- glEnable (GL_TEXTURE_2D);
- glBindTexture (GL_TEXTURE_2D, surface->texture);
-
- glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
- glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
- glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
-
- glGetTexImage (GL_TEXTURE_2D, 0,
- format,
- type,
- pixel_buf);
- }
-
- glc_surface_pop_current (surface);
-
- area_rowstride = width * pixelsize;
- area_rowstride += (area_rowstride % 4)? (4 - (area_rowstride % 4)): 0;
-
- for (i = 0; i < height; i++)
- memcpy (&pixels[(height - i - 1) * area_rowstride],
- &pixel_buf[(surface->height - y - height + i) * rowstride + x],
- area_rowstride);
-
- free (pixel_buf);
- }
-
- void
- glc_glx_surface_draw_pixels (glc_surface_t *surface,
- int x,
- int y,
- unsigned int width,
- unsigned int height,
- char *pixels)
- {
- unsigned char *pixel_buf;
- int i, rowstride, pixelsize;
- glc_surface_t *dst, *offscreen = NULL;
- glc_glx_surface_t *glx_surface = (glc_glx_surface_t *) surface;
- GLenum format, type;
-
- if (x < 0 || x > (glx_surface->base.width - (int) width) ||
- y < 0 || y > (glx_surface->base.height - (int) height)) {
- glc_surface_status_add (surface, GLC_STATUS_BAD_COORDINATE_MASK);
- return;
- }
-
- pixelsize = glc_glx_format_get_pixelsize (glx_surface->format);
- format = glc_get_texture_format_from_pixelsize (pixelsize);
- type = glc_get_texture_data_type_from_pixelsize (pixelsize);
-
- rowstride = width * pixelsize;
- rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
-
- /* TODO: This is very ugly and I like to remove it as soon as possible.
- Needs some changes to texture handling, as images will become upside
- down without it. */
- pixel_buf = (unsigned char *) malloc (rowstride * height);
- for (i = 0; i < (int) height; i++)
- memcpy (&pixel_buf[i * rowstride],
- &pixels[(height - i - 1) * rowstride], rowstride);
-
- /* TODO: use glDrawPixels instead of temporary texture surface.
- glc_glx_surface_draw_pixels and glc_glx_surface_read_pixels can then
- be move from the GLX backend into glc_surface.c */
- if (glx_surface->base.type != GLC_SURFACE_TEXTURE_TYPE) {
- Display *display = glx_surface->screen_info->display_info->display;
- int screen = glx_surface->screen_info->screen;
-
- offscreen = glc_glx_surface_create_offscreen (display, screen,
- glx_surface->format,
- glx_surface->base.width,
- glx_surface->base.height);
- dst = offscreen;
- } else
- dst = surface;
-
- glc_surface_push_current (dst);
-
- glEnable (GL_TEXTURE_2D);
- glBindTexture (GL_TEXTURE_2D, dst->texture);
-
- glPixelStorei (GL_PACK_ROW_LENGTH, 0);
- glPixelStorei (GL_PACK_SKIP_ROWS, 0);
- glPixelStorei (GL_PACK_SKIP_PIXELS, 0);
-
- glTexSubImage2D (GL_TEXTURE_2D, 0,
- x, dst->height - y - height,
- width, height,
- format, type,
- pixel_buf);
-
- glFlush ();
-
- glDisable (GL_TEXTURE_2D);
-
- glc_surface_pop_current (dst);
-
- if (offscreen) {
- glc_composite (GLC_OPERATOR_SRC,
- offscreen,
- NULL,
- surface,
- 0, 0,
- 0, 0,
- x, y,
- width,
- height);
-
- glc_surface_destroy (offscreen);
- }
-
- free (pixel_buf);
- }
--- 385,386 ----
Index: glc_surface.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_surface.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** glc_surface.c 8 Dec 2003 21:03:33 -0000 1.6
--- glc_surface.c 9 Dec 2003 10:35:57 -0000 1.7
***************
*** 220,221 ****
--- 220,357 ----
return glc_get_texture_format_from_pixelsize (pixelsize);
}
+
+ void
+ glc_surface_read_pixels (glc_surface_t *surface,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height,
+ char *pixels)
+ {
+ unsigned char *pixel_buf;
+ int rowstride, area_rowstride, pixelsize;
+ unsigned int i;
+ GLenum format, type;
+
+ if (x < 0 || x > (int) surface->width - (int) width ||
+ y < 0 || y > (int) surface->height - (int) height) {
+ glc_surface_status_add (surface, GLC_STATUS_BAD_COORDINATE_MASK);
+ return;
+ }
+
+ pixelsize =
+ glc_get_pixelsize_from_components (surface->red,
+ surface->green,
+ surface->blue,
+ surface->alpha);
+ format = glc_get_texture_format_from_pixelsize (pixelsize);
+ type = glc_get_texture_data_type_from_pixelsize (pixelsize);
+
+ /* We currently read the whole image to a temporary buffer and then
+ copy the part we want, not very efficient. We only want to read the
+ area requested. I think it can be fixed with glPixelStore parameters. */
+ rowstride = surface->real_width * pixelsize;
+ rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
+
+ pixel_buf = (unsigned char *) malloc (surface->real_height * rowstride);
+
+ glc_surface_push_current (surface);
+
+ if (surface->type != GLC_SURFACE_TEXTURE_TYPE) {
+ glReadPixels (0, 0, surface->real_width, surface->real_height,
+ format, type, pixel_buf);
+ } else {
+ glEnable (GL_TEXTURE_2D);
+ glBindTexture (GL_TEXTURE_2D, surface->texture);
+
+ glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
+ glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
+
+ glGetTexImage (GL_TEXTURE_2D, 0,
+ format,
+ type,
+ pixel_buf);
+ }
+
+ glc_surface_pop_current (surface);
+
+ area_rowstride = width * pixelsize;
+ area_rowstride += (area_rowstride % 4)? (4 - (area_rowstride % 4)): 0;
+
+ for (i = 0; i < height; i++)
+ memcpy (&pixels[(height - i - 1) * area_rowstride],
+ &pixel_buf[(surface->height - y - height + i) * rowstride + x],
+ area_rowstride);
+
+ free (pixel_buf);
+ }
+
+ void
+ glc_surface_draw_pixels (glc_surface_t *surface,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height,
+ char *pixels)
+ {
+ unsigned char *pixel_buf;
+ GLenum format, type;
+ int pixelsize;
+
+ if (x < 0 || x > (surface->width - (int) width) ||
+ y < 0 || y > (surface->height - (int) height)) {
+ glc_surface_status_add (surface, GLC_STATUS_BAD_COORDINATE_MASK);
+ return;
+ }
+
+ pixelsize =
+ glc_get_pixelsize_from_components (surface->red,
+ surface->green,
+ surface->blue,
+ surface->alpha);
+ format = glc_get_texture_format_from_pixelsize (pixelsize);
+ type = glc_get_texture_data_type_from_pixelsize (pixelsize);
+
+ glc_surface_push_current (surface);
+
+ if (surface->type != GLC_SURFACE_TEXTURE_TYPE) {
+ glDrawBuffer (GL_FRONT_AND_BACK);
+ glPixelZoom (1.0, -1.0);
+ glRasterPos2i (x, y);
+ glDrawPixels (width, height, format, type, pixels);
+ glPixelZoom (1.0, 1.0);
+ } else {
+ int i, rowstride;
+
+ rowstride = width * pixelsize;
+ rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0;
+ pixel_buf = (unsigned char *) malloc (rowstride * height);
+
+ /* TODO: This is very ugly and I like to remove it as soon as possible.
+ Needs some changes to texture handling, as images will become upside
+ down without it. */
+ for (i = 0; i < (int) height; i++)
+ memcpy (&pixel_buf[i * rowstride],
+ &pixels[(height - i - 1) * rowstride], rowstride);
+
+ glEnable (GL_TEXTURE_2D);
+ glBindTexture (GL_TEXTURE_2D, surface->texture);
+
+ glPixelStorei (GL_PACK_ROW_LENGTH, 0);
+ glPixelStorei (GL_PACK_SKIP_ROWS, 0);
+ glPixelStorei (GL_PACK_SKIP_PIXELS, 0);
+
+ glTexSubImage2D (GL_TEXTURE_2D, 0,
+ x, surface->height - y - height,
+ width, height,
+ format, type,
+ pixel_buf);
+
+ glFlush ();
+ glDisable (GL_TEXTURE_2D);
+ free (pixel_buf);
+ }
+
+ glc_surface_pop_current (surface);
+ }
More information about the cairo-commit
mailing list