void Canvas::fillRect(int left, int top, int width, int height, pixel_t drawColor) { int dtX = x(); int dtY = y(); uint8_t dR, dG, dB; GET_RGB(drawColor, dR, dG, dB); if (left == 0 && _w == width && top < _h && top > -1 && dR == dG && dR == dB) { // contiguous block of uniform colour unsigned blockH = height; if (top + height > _h) { blockH = height - top; } memset(getLine(top), drawColor, 4 * width * blockH); } else { for (int y = 0; y < height; y++) { int posY = y + top; if (posY == _h) { break; } else if (posY >= dtY) { pixel_t *line = getLine(posY); for (int x = 0; x < width; x++) { int posX = x + left; if (posX == _w) { break; } else if (posX >= dtX) { line[posX] = drawColor; } } } } } }
static void _PG_JP_finish_plot(PG_device *dev) {int row_stride; long imagesize, i, j; unsigned char *input, *r, *g, *b; char fname[MAXLINE]; FILE *fh; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; frame *fr; PG_RAST_device *mdv; GET_RAST_DEVICE(dev, mdv); PG_make_raster_family_name(mdv, fname, MAXLINE); fh = SC_fopen_safe(fname, "wb"); if (fh == NULL) return; /* This function calls the Independent JPEG Group * (IJG) JPEG library to write the input image to * a file in JPEG format */ /* initialize jpeg library default error handler */ cinfo.err = jpeg_std_error(&jerr); /* initialize the jpeg library compression structure */ jpeg_create_compress(&cinfo); /* tell the jpeg library the destination (output file) */ jpeg_stdio_dest(&cinfo, fh); cinfo.image_width = mdv->width; cinfo.image_height = mdv->height; cinfo.input_components = 3; /* # color components */ cinfo.in_color_space = JCS_RGB; /* color space */ jpeg_set_defaults(&cinfo); /* set image quality if requested */ if ((_PG_gattrs.jpg_quality > 0) && (_PG_gattrs.jpg_quality <= 100)) jpeg_set_quality(&cinfo, _PG_gattrs.jpg_quality, TRUE); /* begin a compression cycle */ jpeg_start_compress(&cinfo, TRUE); row_stride = mdv->width * cinfo.input_components; fr = mdv->raster; imagesize = mdv->width * mdv->height * cinfo.input_components; input = CMAKE_N(unsigned char, imagesize); GET_RGB(fr, r, g, b); for (i = 0, j=0; i < (mdv->width * mdv->height); i++, j+=3) {input[j] = r[i]; input[j+1] = g[i]; input[j+2] = b[i];} while (cinfo.next_scanline < cinfo.image_height) {row_pointer[0] = &input[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&cinfo, row_pointer, 1);} /* finish the compression cycle */ jpeg_finish_compress(&cinfo); /* close the output file */ SC_fclose_safe(fh); CFREE(input); /* release the compression object's subsidiary memory */ jpeg_destroy_compress(&cinfo); return;}
static int read_image_tiff(bgav_stream_t * s, gavl_video_frame_t * frame) { uint32_t * raster_ptr; uint8_t * frame_ptr; uint8_t * frame_ptr_start; int i, j; tiff_t *p = s->decoder_priv; if(!p->raster) p->raster = (uint32_t*)_TIFFmalloc(p->Height * p->Width * sizeof(uint32_t)); if(!TIFFReadRGBAImage(p->tiff, p->Width, p->Height, (uint32*)p->raster, 0)) return 0; if(p->SampleSperPixel ==4) { frame_ptr_start = frame->planes[0]; for (i=0;i<p->Height; i++) { frame_ptr = frame_ptr_start; raster_ptr = p->raster + (p->Height - 1 - i) * p->Width; for(j=0;j<p->Width; j++) { GET_RGBA(frame_ptr, raster_ptr); raster_ptr++; } frame_ptr_start += frame->strides[0]; } } else { frame_ptr_start = frame->planes[0]; for (i=0;i<p->Height; i++) { frame_ptr = frame_ptr_start; raster_ptr = p->raster + (p->Height - 1 - i) * p->Width; for(j=0;j<p->Width; j++) { GET_RGB(frame_ptr, raster_ptr); raster_ptr++; } frame_ptr_start += frame->strides[0]; } } bgav_set_video_frame_from_packet(p->packet, frame); TIFFClose( p->tiff ); p->tiff = NULL; bgav_stream_done_packet_read(s, p->packet); p->packet = NULL; return 1; }