Implement basic raw-to-tga conversion
This commit is contained in:
parent
2f467a2591
commit
98221ec036
2 changed files with 24 additions and 1 deletions
24
tgp-2prpl.c
24
tgp-2prpl.c
|
@ -231,13 +231,35 @@ int p2tgl_imgstore_add_with_id (const char* filename) {
|
|||
return id;
|
||||
}
|
||||
|
||||
int p2tgl_imgstore_add_with_id_raw (const unsigned char *raw_rgba, unsigned width, unsigned height) {
|
||||
/* Heavily inspired by: https://github.com/EionRobb/pidgin-opensteamworks/blob/master/libsteamworks.cpp#L113 */
|
||||
const unsigned char tga_header[] = {
|
||||
/* No ID; no color map; uncompressed true color */
|
||||
0,0,2,
|
||||
/* No color map metadata */
|
||||
0,0,0,0,0,
|
||||
/* No offsets */
|
||||
0,0,0,0,
|
||||
/* Dimensions */
|
||||
width&0xFF,(width/256)&0xFF,height&0xFF,(height/256)&0xFF,
|
||||
/* 32 bits per pixel */
|
||||
32,
|
||||
/* "Origin in upper left-hand corner" */
|
||||
32};
|
||||
// Will be owned by libpurple imgstore, which uses glib functions for managing memory
|
||||
const unsigned tga_len = sizeof(tga_header) + width * height * 4;
|
||||
unsigned char *tga = g_malloc(tga_len);
|
||||
memcpy(tga, tga_header, sizeof(tga_header));
|
||||
memcpy(tga + sizeof(tga_header), raw_rgba, width * height * 4);
|
||||
return purple_imgstore_add_with_id (tga, tga_len, NULL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBWEBP
|
||||
|
||||
static const int MAX_W = 256;
|
||||
static const int MAX_H = 256;
|
||||
|
||||
int p2tgl_imgstore_add_with_id_webp (const char *filename) {
|
||||
|
||||
const uint8_t *data = NULL;
|
||||
size_t len;
|
||||
GError *err = NULL;
|
||||
|
|
|
@ -46,6 +46,7 @@ PurpleNotifyUserInfo *p2tgl_notify_encrypted_chat_info_new (struct tgl_state *TL
|
|||
int p2tgl_imgstore_add_with_id (const char* filename);
|
||||
void p2tgl_buddy_icons_set_for_user (PurpleAccount *pa, tgl_peer_id_t id, const char* filename);
|
||||
|
||||
int p2tgl_imgstore_add_with_id_raw (const unsigned char *raw_rgba, unsigned width, unsigned height);
|
||||
#ifdef HAVE_LIBWEBP
|
||||
int p2tgl_imgstore_add_with_id_webp (const char *filename);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue