Пример #1
0
static void iw_opt_16_to_8(struct iw_context *ctx, struct iw_opt_ctx *optctx, int spp)
{
	unsigned char *newpixels;
	size_t newbpr;
	int i,j;

	if(!ctx->opt_16_to_8) return;

	newbpr = iw_calc_bytesperrow(optctx->width,8*spp);
	newpixels = iw_malloc_large(ctx, newbpr, optctx->height);
	if(!newpixels) return;

	for(j=0;j<optctx->height;j++) {
		for(i=0;i<spp*optctx->width;i++) {
			// i is a sample number, not a pixel number.
			newpixels[j*newbpr + i] = optctx->pixelsptr[j*optctx->bpr + i*2];
		}
	}

	// Remove previous image if it was allocated by the optimization code.
	if(optctx->tmp_pixels) iw_free(optctx->tmp_pixels);

	// Attach our new image
	optctx->tmp_pixels = newpixels;
	optctx->pixelsptr = optctx->tmp_pixels;
	optctx->bpr = newbpr;
	optctx->bit_depth = 8;
}
Пример #2
0
// Create a new (8-bit) image by copying up to 3 channels from the old image.
static void iw_opt_copychannels_8(struct iw_context *ctx, struct iw_opt_ctx *optctx,
			int new_imgtype, int c0, int c1, int c2)
{
	unsigned char *newpixels;
	int oldnc, newnc; // num_channels
	size_t newbpr;
	int i,j;

	oldnc = iw_imgtype_num_channels(optctx->imgtype);
	newnc = iw_imgtype_num_channels(new_imgtype);

	newbpr = iw_calc_bytesperrow(optctx->width,8*newnc);
	newpixels = iw_malloc_large(ctx, newbpr, optctx->height);
	if(!newpixels) return;

	for(j=0;j<optctx->height;j++) {
		for(i=0;i<optctx->width;i++) {
			newpixels[j*newbpr + i*newnc +0] = optctx->pixelsptr[j*optctx->bpr + i*oldnc +c0];
			if(newnc>1)
				newpixels[j*newbpr + i*newnc +1] = optctx->pixelsptr[j*optctx->bpr + i*oldnc +c1];
			if(newnc>2)
				newpixels[j*newbpr + i*newnc +2] = optctx->pixelsptr[j*optctx->bpr + i*oldnc +c2];
		}
	}

	// Remove previous image if it was allocated by the optimization code.
	if(optctx->tmp_pixels) iw_free(optctx->tmp_pixels);

	// Attach our new image
	optctx->tmp_pixels = newpixels;
	optctx->pixelsptr = optctx->tmp_pixels;
	optctx->bpr = newbpr;
	optctx->imgtype = new_imgtype;

}
Пример #3
0
static void iw_opt_16_to_8(struct iw_context *ctx, struct iw_opt_ctx *optctx, int spp)
{
	iw_byte *newpixels;
	size_t newbpr;
	int i,j,k;

	if(!ctx->opt_16_to_8) return;

	newbpr = iw_calc_bytesperrow(optctx->width,8*spp);
	newpixels = iw_malloc_large(ctx, newbpr, optctx->height);
	if(!newpixels) return;

	for(j=0;j<optctx->height;j++) {
		for(i=0;i<spp*optctx->width;i++) {
			// i is a sample number, not a pixel number.
			newpixels[j*newbpr + i] = optctx->pixelsptr[j*optctx->bpr + i*2];
		}
	}

	// Remove previous image if it was allocated by the optimization code.
	if(optctx->tmp_pixels) iw_free(ctx,optctx->tmp_pixels);

	// Attach our new image
	optctx->tmp_pixels = newpixels;
	optctx->pixelsptr = optctx->tmp_pixels;
	optctx->bpr = newbpr;
	optctx->bit_depth = 8;

	// If there's a background color label, also reduce its precision.
	if(optctx->has_bkgdlabel) {
		for(k=0;k<4;k++) {
			optctx->bkgdlabel[k] >>= 8;
		}
	}
}