[vlc-devel] [PATCH 2/2] Display cursor on video screenshot on X server systems using xfixes Cleaning patch source code with vlc conventions respect

Mehdi Lauters mehdilauters at gmail.com
Tue Apr 10 09:19:56 CEST 2012


---
 modules/access/screen/xcb.c |  245 ++++++++++++++++++++++++-------------------
 1 files changed, 137 insertions(+), 108 deletions(-)

diff --git a/modules/access/screen/xcb.c b/modules/access/screen/xcb.c
index 3d87f8a..229fe53 100644
--- a/modules/access/screen/xcb.c
+++ b/modules/access/screen/xcb.c
@@ -413,114 +413,143 @@ discard:
         return;
 
 
-///////////////////////////////////////////////cursor processing begining///////////////////////////////////
-// doesn't take account of cursor transparency
-
-    xcb_generic_error_t 	xcbError;
-
-	// initializing xfixes (to get the cursor image)
-	xcb_xfixes_query_version_reply(conn, xcb_xfixes_query_version(conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION), NULL);
-
-	// we ask for pointer informations ( on the same screen or not )
-	xcb_query_pointer_cookie_t pointerCookie= 	xcb_query_pointer (conn, drawable);
-	xcb_query_pointer_reply_t * pointerReply=	xcb_query_pointer_reply (conn, pointerCookie, &xcbError);
-
-
-	if(xcbError.error_code!=0)
-	{
-        msg_Warn (demux, "unable to locate cursor");
-	}
-	else
-	{
-		// if the cursor is on the same screen
-		if(pointerReply->same_screen == 1)
-		{
-			// we get more information about the cursor
-			xcb_xfixes_get_cursor_image_cookie_t cursorCookie=xcb_xfixes_get_cursor_image(conn);
-			xcb_xfixes_get_cursor_image_reply_t* cursorImageReply= xcb_xfixes_get_cursor_image_reply	(conn, cursorCookie, &xcbError);
-
-			if(xcbError.error_code==0)
-			{
-				// indices to browse images
-				int screenImageLinearIndice;
-				int pointerImageLinearIndice=0;
-
-				// images data
-				uint32_t *screenImageData=NULL;
-				uint32_t *pointerImageData;
-
-				// we get the cursor image data
-				pointerImageData=xcb_xfixes_get_cursor_image_cursor_image(cursorImageReply);
-
-				// we get screen image data
-				screenImageData=xcb_get_image_data (img);
-
-
-				//indices to browse the pointer picture
-				int ixCursor=0,
-					iyCursor=0;
-
-				int xMinScreen=cursorImageReply->x-cursorImageReply->xhot,								// top left corner of the pointer picture on the screen picture
-					yMinScreen=cursorImageReply->y-cursorImageReply->yhot,								// top right corner of the pointer picture on the screen picture
-					xMaxScreen=cursorImageReply->x+(cursorImageReply->width-cursorImageReply->xhot),	// bottom left corner of the pointer picture on the screen picture
-					yMaxScreen=cursorImageReply->y+(cursorImageReply->width-cursorImageReply->yhot);	// bottom right corner of the pointer picture on the screen picture
-
-
-				if(!(xMinScreen<0 || yMinScreen <0 || xMaxScreen > geo->width || yMaxScreen > geo->height)) // be sure that the entire pointer is on the screenshot
-				{
-
-					// we browse the screen picture
-					for(int ix=xMinScreen; // to center on the right point
-							ix<xMaxScreen;
-							ix++)
-					{
-						iyCursor=0;
-						for(int iy=yMinScreen; // to center on the right point
-								iy<yMaxScreen;
-								iy++)
-						{
-							//get the indice of the (ix,iy) pixel in the screen data buffer
-							screenImageLinearIndice=iy*geo->width+ix;
-
-
-	//						//get the relative indice of the cursor
-							pointerImageLinearIndice=iyCursor*cursorImageReply->width+ixCursor;
-
-							// get the indice of the first color of the current pixel ( switch from uint32 to uint8 )
-							screenImageLinearIndice=screenImageLinearIndice*4;
-							pointerImageLinearIndice=pointerImageLinearIndice*4;
-
-							// /!\ no transparency
-							if(((uint8_t *)pointerImageData)[pointerImageLinearIndice+3]>100)
-							{
-								// copying pixels colors
-								((uint8_t *)screenImageData)[screenImageLinearIndice]=((uint8_t *)pointerImageData)[pointerImageLinearIndice];			// r
-								((uint8_t *)screenImageData)[screenImageLinearIndice+1]=((uint8_t *)pointerImageData)[pointerImageLinearIndice+1];		// g
-								((uint8_t *)screenImageData)[screenImageLinearIndice+2]=((uint8_t *)pointerImageData)[pointerImageLinearIndice+2];		// b
-							}
-							iyCursor++;
-						}
-						ixCursor++;
-					}
-				}
-				else
-				{
-					msg_Warn (demux, "Cursor not on the picture");
-				}
-				free(cursorImageReply);
-			}
-			else
-			{
-				msg_Warn (demux, "unable to find cursor image");
-			}
-		}
-	}
-
-	free(pointerReply);
-	///////////////////////////////////////////////cursor processing end///////////////////////////////////
-
-
-    free (geo);
+
+    xcb_generic_error_t   xcbError;
+
+      // initializing xfixes (to get the cursor image)
+      xcb_xfixes_query_version_reply(conn,
+              xcb_xfixes_query_version(conn,
+                      XCB_XFIXES_MAJOR_VERSION,
+                      XCB_XFIXES_MINOR_VERSION),
+                      NULL);
+
+      // we ask for pointer informations ( on the same screen or not )
+      xcb_query_pointer_cookie_t pointerCookie=xcb_query_pointer(conn, drawable);
+      xcb_query_pointer_reply_t * pointerReply=xcb_query_pointer_reply (conn,
+              pointerCookie, &xcbError);
+
+
+      if(xcbError.error_code!=0)
+      {
+         msg_Warn (demux, "unable to locate cursor");
+      }
+      else
+      {
+          // if the cursor is on the same screen
+          if(pointerReply->same_screen == 1)
+          {
+              xcb_xfixes_get_cursor_image_cookie_t cursorCookie;
+              xcb_xfixes_get_cursor_image_reply_t* cursorImageReply;
+
+              // we get more information about the cursor
+              cursorCookie=xcb_xfixes_get_cursor_image(conn);
+              cursorImageReply= xcb_xfixes_get_cursor_image_reply (conn,
+                                          cursorCookie, &xcbError);
+
+              if(xcbError.error_code==0)
+              {
+                  // indices to browse images
+                  int iScreen;
+                  int iCursor=0;
+
+                  // images data
+                  uint32_t *screenData=NULL;
+                  uint32_t *pointerData;
+
+                  // we get the cursor image data
+                  pointerData=xcb_xfixes_get_cursor_image_cursor_image(
+                          cursorImageReply);
+
+                  // we get screen image data
+                  screenData=xcb_get_image_data (img);
+
+
+                  //indices to browse the pointer picture
+                  int ixCursor=0,
+                          iyCursor=0;
+
+                  // top left corner of the pointer picture
+                  //on the screen picture
+                  int xMinScreen=cursorImageReply->x-cursorImageReply->xhot,
+                      // top right corner of the pointer picture
+                      // on the screen picture
+                      yMinScreen=cursorImageReply->y-cursorImageReply->yhot,
+                      // bottom left corner of the pointer picture
+                      // on the screen picture
+                      xMaxScreen=cursorImageReply->x
+                      +(cursorImageReply->width-cursorImageReply->xhot),
+                      // bottom right corner of the pointer picture
+                      //on the screen picture
+                      yMaxScreen=cursorImageReply->y
+                      +(cursorImageReply->width-cursorImageReply->yhot);
+
+
+                  // be sure that the entire pointer is on the screenshot
+                  if(!(xMinScreen<0 || yMinScreen <0
+                          || xMaxScreen>geo->width || yMaxScreen>geo->height))
+                  {
+
+                      // we browse the screen picture
+                      for(int ix=xMinScreen; // to center on the right point
+                              ix<xMaxScreen;
+                              ix++)
+                      {
+                          iyCursor=0;
+                          for(int iy=yMinScreen; // to center on the right point
+                                  iy<yMaxScreen;
+                                  iy++)
+                          {
+                              //get the indice of the (ix,iy) pixel
+                              // in the screen data buffer
+                              iScreen=iy*geo->width+ix;
+
+
+                              //get the relative indice of the cursor
+                              iCursor=iyCursor*cursorImageReply->width+ixCursor;
+
+                              // get the indice of the first color of
+                              // the current pixel (switch from uint32 to uint8)
+                              iScreen=iScreen*4;
+                              iCursor=iCursor*4;
+
+                              // /!\ no transparency
+                              if(((uint8_t *)pointerData)[iCursor+3]>100)
+                              {
+                                  // copying pixels colors
+                                  // r
+                                  ((uint8_t*)screenData)[iScreen]=
+                                          ((uint8_t*)pointerData)[iCursor];
+
+                                  // g
+                                  ((uint8_t*)screenData)[iScreen+1]=
+                                          ((uint8_t*)pointerData)[iCursor+1];
+
+                                  // b
+                                  ((uint8_t*)screenData)[iScreen+2]=
+                                          ((uint8_t*)pointerData)[iCursor+2];
+                              }
+                              iyCursor++;
+                          }
+                          ixCursor++;
+                      }
+                  }
+                  else
+                  {
+                      msg_Warn (demux, "Cursor not on the picture");
+                  }
+                  free(cursorImageReply);
+              }
+              else
+              {
+                  msg_Warn (demux, "unable to find cursor image");
+              }
+          }
+      }
+
+      free(pointerReply);
+
+
+      free (geo);
     block_t *block = block_heap_Alloc (img, xcb_get_image_data (img),
                                        xcb_get_image_data_length (img));
     if (block == NULL)
-- 
1.7.1




More information about the vlc-devel mailing list