int set_avatar(uint32_t friend_number, const uint8_t *data, uint32_t size) { if (size > UTOX_AVATAR_MAX_DATA_LENGTH) { debug_error("Avatars:\t avatar too large\n"); return 0; } uint16_t w, h; UTOX_NATIVE_IMAGE *image = decode_image_rgb((UTOX_IMAGE)data, size, &w, &h, 1); if(!UTOX_NATIVE_IMAGE_IS_VALID(image)) { debug("Avatars:\t avatar is invalid\n"); return 0; } else { if (friend_number == -1) { avatar_free_image(&self.avatar); self.avatar.image = image; self.avatar.width = w; self.avatar.height = h; self.avatar.format = UTOX_AVATAR_FORMAT_PNG; tox_hash(self.avatar.hash, data, size); } else { FRIEND *f = &friend[friend_number]; avatar_free_image(&f->avatar); f->avatar.image = image; f->avatar.width = w; f->avatar.height = h; f->avatar.format = UTOX_AVATAR_FORMAT_PNG; tox_hash(f->avatar.hash, data, size); } return 1; } }
int set_avatar(AVATAR *avatar, const uint8_t *data, uint32_t size) { if (size > UTOX_AVATAR_MAX_DATA_LENGTH) { debug("Avatars:\t avatar too large\n"); return 0; } uint16_t w, h; UTOX_NATIVE_IMAGE *image = png_to_image((UTOX_PNG_IMAGE)data, size, &w, &h, 1); if(!UTOX_NATIVE_IMAGE_IS_VALID(image)) { debug("Avatars:\t avatar is invalid\n"); return 0; } else { avatar_free_image(avatar); avatar->image = image; avatar->width = w; avatar->height = h; avatar->format = UTOX_AVATAR_FORMAT_PNG; tox_hash(avatar->hash, data, size); return 1; } }
void friend_recvimage(FRIEND *f, UTOX_NATIVE_IMAGE *native_image, uint16_t width, uint16_t height) { if(!UTOX_NATIVE_IMAGE_IS_VALID(native_image)) { return; } MSG_IMG *msg = malloc(sizeof(MSG_IMG)); msg->author = 0; msg->msg_type = MSG_TYPE_IMAGE; msg->w = width; msg->h = height; msg->zoom = 0; msg->image = native_image; msg->position = 0.0; message_add(&messages_friend, (void*)msg, &f->msg); }