コード例 #1
0
ファイル: scommon.c プロジェクト: faragon/libsrt
void s_st_pk_u64(uint8_t **buf0, uint64_t v)
{
	uint8_t *buf;
	if (!buf0 || !*buf0)
		return;
	buf = *buf0;
	/* 7-bit (8-bit container) */
	if (v <= D8_LE_MASK) {
		buf[0] = D8_LE_ID | (uint8_t)(v << D8_LE_SHIFT);
		(*buf0) += D8_LE_SZ;
		return;
	}
	/* 14-bit (16-bit container) */
	if (v <= D16_LE_MASK) {
		S_ST_LE_U16(buf, D16_LE_ID | (uint16_t)(v << D16_LE_SHIFT));
		(*buf0) += D16_LE_SZ;
		return;
	}
	/* 21-bit (24-bit container) */
	if (v <= D24_LE_MASK) {
		S_ST_LE_U32(buf, D24_LE_ID | (uint32_t)(v << D24_LE_SHIFT));
		(*buf0) += D24_LE_SZ;
		return;
	}
	/* 28-bit (32-bit container) */
	if (v <= D32_LE_MASK) {
		S_ST_LE_U32(buf, D32_LE_ID | ((uint32_t)v << D32_LE_SHIFT));
		(*buf0) += D32_LE_SZ;
		return;
	}
	/* 35-bit (40-bit container) */
	if (v <= D40_LE_MASK) {
		S_ST_LE_U64(buf, D40_LE_ID | (v << D40_LE_SHIFT));
		(*buf0) += D40_LE_SZ;
		return;
	}
	/* 42-bit (48-bit container) */
	if (v <= D48_LE_MASK) {
		S_ST_LE_U64(buf, D48_LE_ID | (v << D48_LE_SHIFT));
		(*buf0) += D48_LE_SZ;
		return;
	}
	/* 49-bit (56-bit container) */
	if (v <= D56_LE_MASK) {
		S_ST_LE_U64(buf, D56_LE_ID | (v << D56_LE_SHIFT));
		(*buf0) += D56_LE_SZ;
		return;
	}
	/* 64-bit (72-bit container) */
	buf[0] = D72_LE_ID;
	S_ST_LE_U64(buf + 1, v);
	(*buf0) += D72_LE_SZ;
}
コード例 #2
0
ファイル: imgc.c プロジェクト: lamproae/libsrt
static size_t rgb2tga(ss_t **tga, const ss_t *rgb, const struct RGB_Info *ri)
{
	RETURN_IF(!rgb || (!valid_rgbi(ri) && (ri->bpp / ri->chn) != 8), 0);
	RETURN_IF(ri->chn != 1 && ri->chn != 3 && ri->chn != 4, 0);
	size_t buf_size = ri->bmp_size + TGA_RGBHDR;
	RETURN_IF(ss_reserve(tga, buf_size) < buf_size, 0);
	char *h = ss_get_buffer(*tga);
	memset(h, 0, TGA_RGBHDR);
	h[TGA_ID] = TGA_NO_X_INFO;
	h[TGA_CMAP] = TGA_NO_CMAP;
	h[TGA_TYPE] = ri->chn == 1 ? TGA_RAW_GRAY : TGA_RAW_RGB;
	S_ST_LE_U16(h + TGA_W, ri->width);
	S_ST_LE_U16(h + TGA_H, ri->height);
	h[TGA_BPP] = ri->bpp;
	h[TGA_DESC] = TGA_TOP_LEFT;
	ss_cpy_cn(tga, h, TGA_RGBHDR);
	if (ri->chn == 1)
		ss_cat(tga, rgb);
	else
		tga_rgb_swap(ri->bpp, ri->bmp_size, ss_get_buffer_r(rgb),
			     ss_get_buffer(*tga) + TGA_RGBHDR);
	ss_set_size(*tga, buf_size);
	return ss_size(*tga);
}