Xlib question
Hi,
In Xlib, how do you create a transparent background textbox in g++ or gcc and stick it onto an image. I used the following code, hope you can extend it
Code snippet:
struct jpeg_decompress_struct cinfo;
FILE *infile;
JSAMPARRAY buffer;
int row_stride, lines = 0, total_size;
unsigned char *buf_tmp;
if ((infile = fopen ("test.jpg", "rb")) == NULL)
return NULL;
// if (setjmp (jerr.setjmp_buffer)) {
// jpeg_destroy_decompress(&cinfo);
// jpeg_destroy_decompress(&cinfo);
// fclose(infile);
// return 0;
// }
jpeg_create_decompress(&cinfo);
jpeg_stdio_src (&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
total_size = row_stride * cinfo.output_height;
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
// read the file into memory, no need to display it
buf_tmp = (unsigned char *) malloc (total_size * sizeof(char));
while (cinfo.output_scanline < cinfo.output_height) {
(void) jpeg_read_scanlines (&cinfo, buffer, 1);
memcpy (buf_tmp, buffer[0], row_stride);
buf_tmp += row_stride;
lines++;
}
// Add a Text Label here, with transparent background
// The text Label is the photo timestamp, then save it back
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(infile);
|