soc.2009.vulture: 605ce9ff: First forays into buddy icons.

gdick at soc.pidgin.im gdick at soc.pidgin.im
Mon Jul 13 15:10:34 EDT 2009


-----------------------------------------------------------------
Revision: 605ce9ff4bf8a72d960f54b9d7502eabce2d7e20
Ancestor: 8f772a5fd790af110bf7470f28fc575dc25785b8
Author: gdick at soc.pidgin.im
Date: 2009-07-13T19:07:04
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/605ce9ff4bf8a72d960f54b9d7502eabce2d7e20

Added files:
        vulture/purplebicon.c vulture/purplebicon.h
        vulture/vulturebicon.h
Modified files:
        vulture/Makefile.mingw

ChangeLog: 

First forays into buddy icons.

-------------- next part --------------
============================================================
--- vulture/purplebicon.c	61ef9c6cdb51afeaccdbdfab3adb8d38c24d4883
+++ vulture/purplebicon.c	61ef9c6cdb51afeaccdbdfab3adb8d38c24d4883
@@ -0,0 +1,143 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purplebicon.c: Buddy-icon management.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+
+#include <windows.h>
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "vulture.h"
+#include "purple.h"
+#include "purplebicon.h"
+
+
+
+/**
+ * Retrieves the buddy icon for a buddy.
+ *
+ * @param	lpbuddy		Buddy.
+ *
+ * @return Bitmap handle, or NULL on error.
+ */
+HBITMAP PurpleGetBuddyIcon(PurpleBuddy *lpbuddy)
+{
+	GdkPixbuf *lppixbuf;
+	GdkPixbufLoader *lppbloader;
+	PurpleBuddyIcon *lpbuddyicon;
+	gconstpointer lpvBuddyIconData;
+	size_t cbBuddyIconData;
+	guchar *lpucPixbufPixels;
+	int cbPixbufRowstride, cbDIBRowstride;
+	int cx, cy;
+	HDC hdc;
+	HBITMAP hbitmap;
+	BITMAPINFO bmi;
+	BYTE *lpbyBits;
+	int iRow;
+	int iChannels, iBitsPerSample;
+
+	lpbuddyicon = purple_buddy_icons_find(lpbuddy->account, lpbuddy->name);
+
+	if(!lpbuddyicon)
+		return NULL;
+
+	lpvBuddyIconData = purple_buddy_icon_get_data(lpbuddyicon, &cbBuddyIconData);
+
+	lppbloader = gdk_pixbuf_loader_new();
+	gdk_pixbuf_loader_write(lppbloader, lpvBuddyIconData, cbBuddyIconData, NULL);
+	gdk_pixbuf_loader_close(lppbloader, NULL);
+
+	lppixbuf = gdk_pixbuf_loader_get_pixbuf(lppbloader);
+
+	g_object_unref(lppbloader);
+
+	lpucPixbufPixels = gdk_pixbuf_get_pixels(lppixbuf);
+
+	cx = gdk_pixbuf_get_width(lppixbuf);
+	cy = gdk_pixbuf_get_height(lppixbuf);
+	cbPixbufRowstride = gdk_pixbuf_get_rowstride(lppixbuf);
+	iChannels = gdk_pixbuf_get_n_channels(lppixbuf);
+	iBitsPerSample = gdk_pixbuf_get_bits_per_sample(lppixbuf);
+
+	/* This assertion will always pass at the time of writing, but we do
+	 * rely on these properties.
+	 */
+	if((iChannels != 3 && iChannels != 4) || iBitsPerSample != 8)
+	{
+		g_object_unref(lppixbuf);
+		return NULL;
+	}
+
+
+	/* Convert the pixbuf's pixels into a DIB. */
+
+	bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
+	bmi.bmiHeader.biBitCount = iChannels * iBitsPerSample;
+	bmi.bmiHeader.biCompression = BI_RGB;
+	bmi.bmiHeader.biWidth = cx;
+	bmi.bmiHeader.biHeight = cy;
+	bmi.bmiHeader.biPlanes = 1;
+	bmi.bmiHeader.biSizeImage = 0;
+	bmi.bmiHeader.biClrImportant = 0;
+	bmi.bmiHeader.biClrUsed = 0;
+	bmi.bmiHeader.biXPelsPerMeter = 0;
+	bmi.bmiHeader.biYPelsPerMeter = 0;
+
+	/* Scanlines must start on DWORD boundaries. */
+	cbDIBRowstride = (4 * cx * sizeof(DWORD) + 3) / 4;
+
+	lpbyBits = ProcHeapAlloc(cbDIBRowstride * cy);
+
+	/* Bottom-up DIB. */
+	for(iRow = 0; iRow < cy; iRow++)
+	{
+		int cbDIBRowOffest = (cy - iRow) * cbDIBRowstride;
+		int cbPixbufRowOffest = (cy - iRow) * cbDIBRowstride;
+		int iCol;
+
+		for(iCol = 0; iCol < cx; iCol++)
+		{
+			int iChan;
+
+			/* DIB is 0x(AA)RRGGBB; pixbuf is 0x(AA)BBGGRR (both
+			 * little-endian).
+			 */
+
+			/* Blue, green, red. */
+			for(iChan = 0; iChan < 3; iChan++)
+				lpbyBits[cbDIBRowOffest + iChan] = lpucPixbufPixels[cbPixbufRowOffest + (2 - iChan)];
+
+			if(iChannels == 4)
+				lpbyBits[cbDIBRowOffest + 3] = lpucPixbufPixels[cbPixbufRowOffest + 3];
+		}
+	}
+
+	g_object_unref(lppixbuf);
+
+	hdc = GetDC(NULL);
+	hbitmap = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, lpbyBits, &bmi, DIB_RGB_COLORS);
+	ReleaseDC(NULL, hdc);
+
+	ProcHeapFree(lpbyBits);
+
+	return hbitmap;
+}
============================================================
--- vulture/purplebicon.h	52b0a6a50c6f8b807be05ddbac1b902466a8dca7
+++ vulture/purplebicon.h	52b0a6a50c6f8b807be05ddbac1b902466a8dca7
@@ -0,0 +1,35 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * purplebicon.h: Buddy-icon management.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _VULTURE_PURPLEBICON_H_
+#define _VULTURE_PURPLEBICON_H_
+
+
+#include <windows.h>
+
+#include "purple.h"
+
+
+HBITMAP PurpleGetBuddyIcon(PurpleBuddy *lpbuddy);
+
+
+#endif
============================================================
--- vulture/vulturebicon.h	61e9bca7fef802cd5a4962c8cdf68101bcdfcd68
+++ vulture/vulturebicon.h	61e9bca7fef802cd5a4962c8cdf68101bcdfcd68
@@ -0,0 +1,21 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * vulturebicon.h: Buddy-icon management for the UI.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
============================================================
--- vulture/Makefile.mingw	f092c2bb84eb2ef5200bb1bdd42d43369e86e8ee
+++ vulture/Makefile.mingw	7d3e3322c0f104c3a512dd1128fcebc9a992e0bd
@@ -40,7 +40,8 @@ PURPLE_INCLUDE_PATHS =	\
 			-I$(PIDGIN_TREE_TOP) \
 			-I$(GTK_TOP)/include \
 			-I$(GTK_TOP)/include/glib-2.0 \
-			-I$(GTK_TOP)/lib/glib-2.0/include
+			-I$(GTK_TOP)/lib/glib-2.0/include \
+			-I$(GTK_TOP)/include/gtk-2.0
 
 INCLUDE_PATHS +=	\
 			$(PURPLE_INCLUDE_PATHS) \
@@ -67,7 +68,8 @@ VULTURE_C_SRC =	\
 			purpleblist.c \
 			vultureconv.c \
 			purpleconv.c \
-			vulturedlg.c
+			vulturedlg.c \
+			purplebicon.c
 
 VULTURE_RC_SRC = vulture-res.rc
 VULTURE_OBJECTS = $(VULTURE_C_SRC:%.c=%.o) $(VULTURE_RC_SRC:%.rc=%.o)
@@ -81,7 +83,9 @@ VULTURE_LIBS =	\
 		-lpurple \
 		-lwinmm \
 		-lcomctl32 \
-		-lgthread-2.0
+		-lgthread-2.0 \
+		-lgobject-2.0 \
+		-lgdk_pixbuf-2.0
 
 include $(PIDGIN_COMMON_RULES)
 


More information about the Commits mailing list