本文整理汇总了C++中ImagingCodecState::shuffle方法的典型用法代码示例。如果您正苦于以下问题:C++ ImagingCodecState::shuffle方法的具体用法?C++ ImagingCodecState::shuffle怎么用?C++ ImagingCodecState::shuffle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImagingCodecState
的用法示例。
在下文中一共展示了ImagingCodecState::shuffle方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
int x;
int chunk;
UINT8* out;
UINT8* ptr;
ptr = buf;
chunk = 3 * state->xsize;
for (;;) {
/* We need data for two full lines before we can do anything */
if (bytes < chunk)
return ptr - buf;
/* Unpack first line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1; /* This can hardly happen */
/* Unpack second line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x+state->xsize];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 3;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1;
ptr += chunk;
bytes -= chunk;
}
}
示例2: while
int
ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
UINT8 n;
UINT8* ptr;
ptr = buf;
for (;;) {
if (bytes < 1)
return ptr - buf;
if ((*ptr & 0xC0) == 0xC0) {
/* Run */
if (bytes < 2)
return ptr - buf;
n = ptr[0] & 0x3F;
while (n > 0) {
if (state->x >= state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
break;
}
state->buffer[state->x++] = ptr[1];
n--;
}
ptr += 2; bytes -= 2;
} else {
/* Literal */
state->buffer[state->x++] = ptr[0];
ptr++; bytes--;
}
if (state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}
示例3: HEX
int
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
UINT8* ptr;
int a, b;
ptr = buf;
for (;;) {
if (bytes < 2)
return ptr - buf;
a = HEX(ptr[0]);
b = HEX(ptr[1]);
if (a < 0 || b < 0) {
ptr++;
bytes--;
} else {
ptr += 2;
bytes -= 2;
state->buffer[state->x] = (a<<4) + b;
if (++state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y], state->buffer,
state->xsize);
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}
}
示例4:
int
ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
UINT8* buf, Py_ssize_t bytes)
{
UINT8 n;
UINT8* ptr;
int i;
ptr = buf;
for (;;) {
if (bytes < 1)
return ptr - buf;
if (ptr[0] & 0x80) {
if (ptr[0] == 0x80) {
/* Nop */
ptr++; bytes--;
continue;
}
/* Run */
if (bytes < 2)
return ptr - buf;
for (n = 257 - ptr[0]; n > 0; n--) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[1];
}
ptr += 2; bytes -= 2;
} else {
/* Literal */
n = ptr[0]+2;
if (bytes < n)
return ptr - buf;
for (i = 1; i < n; i++) {
if (state->x >= state->bytes) {
/* state->errcode = IMAGING_CODEC_OVERRUN; */
break;
}
state->buffer[state->x++] = ptr[i];
}
ptr += n; bytes -= n;
}
if (state->x >= state->bytes) {
/* Got a full line, unpack it */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->buffer,
state->xsize);
state->x = 0;
if (++state->y >= state->ysize) {
/* End of file (errcode = 0) */
return -1;
}
}
}
}
示例5: if
//.........这里部分代码省略.........
}
/* Apply predictor */
switch (context->mode) {
case ZIP_PNG:
switch (state->buffer[0]) {
case 0:
break;
case 1:
/* prior */
bpp = (state->bits + 7) / 8;
for (i = bpp+1; i <= state->bytes; i++)
state->buffer[i] += state->buffer[i-bpp];
break;
case 2:
/* up */
for (i = 1; i <= state->bytes; i++)
state->buffer[i] += context->previous[i];
break;
case 3:
/* average */
bpp = (state->bits + 7) / 8;
for (i = 1; i <= bpp; i++)
state->buffer[i] += context->previous[i]/2;
for (; i <= state->bytes; i++)
state->buffer[i] +=
(state->buffer[i-bpp] + context->previous[i])/2;
break;
case 4:
/* paeth filtering */
bpp = (state->bits + 7) / 8;
for (i = 1; i <= bpp; i++)
state->buffer[i] += context->previous[i];
for (; i <= state->bytes; i++) {
int a, b, c;
int pa, pb, pc;
/* fetch pixels */
a = state->buffer[i-bpp];
b = context->previous[i];
c = context->previous[i-bpp];
/* distances to surrounding pixels */
pa = abs(b - c);
pb = abs(a - c);
pc = abs(a + b - 2*c);
/* pick predictor with the shortest distance */
state->buffer[i] +=
(pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;
}
break;
default:
state->errcode = IMAGING_CODEC_UNKNOWN;
free(context->previous);
inflateEnd(&context->z_stream);
return -1;
}
break;
case ZIP_TIFF_PREDICTOR:
bpp = (state->bits + 7) / 8;
for (i = bpp+1; i <= state->bytes; i++)
state->buffer[i] += state->buffer[i-bpp];
break;
}
/* Stuff data into the image */
state->shuffle((UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize,
state->buffer + context->prefix,
state->xsize);
state->y++;
/* all inflate output has been consumed */
context->last_output = 0;
if (state->y >= state->ysize || err == Z_STREAM_END) {
/* The image and the data should end simultaneously */
/* if (state->y < state->ysize || err != Z_STREAM_END)
state->errcode = IMAGING_CODEC_BROKEN; */
free(context->previous);
inflateEnd(&context->z_stream);
return -1; /* end of file (errcode=0) */
}
/* Swap buffer pointers */
ptr = state->buffer;
state->buffer = context->previous;
context->previous = ptr;
}
return bytes; /* consumed all of it */
}
示例6: while
int
ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
const char *hex = "0123456789abcdef";
UINT8* ptr = buf;
int i, n;
if (!state->state) {
/* 8 pixels are stored in no more than 6 bytes */
state->bytes = 6*(state->xsize+7)/8;
state->state = 1;
}
if (bytes < state->bytes) {
state->errcode = IMAGING_CODEC_MEMORY;
return 0;
}
ptr = buf;
while (bytes >= state->bytes) {
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
if (state->y < state->ysize-1) {
/* any line but the last */
for (n = 0; n < state->xsize; n += 8) {
i = state->buffer[n/8];
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
*ptr++ = ',';
bytes -= 5;
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
}
state->y++;
} else {
/* last line */
for (n = 0; n < state->xsize; n += 8) {
i = state->buffer[n/8];
*ptr++ = '0';
*ptr++ = 'x';
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
if (n < state->xsize-8) {
*ptr++ = ',';
if (++state->count >= 79/5) {
*ptr++ = '\n';
bytes--;
state->count = 0;
}
} else
*ptr++ = '\n';
bytes -= 5;
}
state->errcode = IMAGING_CODEC_END;
break;
}
}
示例7: while
int
ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
UINT8* ptr;
int this;
GIFENCODERBLOCK* block;
GIFENCODERSTATE *context = (GIFENCODERSTATE*) state->context;
if (!state->state) {
/* place a clear code in the output buffer */
context->bitbuffer = CLEAR_CODE;
context->bitcount = 9;
state->count = FIRST_CODE;
if (context->interlace) {
context->interlace = 1;
context->step = 8;
} else
context->step = 1;
context->last = -1;
/* sanity check */
if (state->xsize <= 0 || state->ysize <= 0)
state->state = ENCODE_EOF;
}
ptr = buf;
for (;;)
switch (state->state) {
case INIT:
case ENCODE:
/* identify and store a run of pixels */
if (state->x == 0 || state->x >= state->xsize) {
if (!context->interlace && state->y >= state->ysize) {
state->state = ENCODE_EOF;
break;
}
if (context->flush) {
state->state = FLUSH;
break;
}
/* get another line of data */
state->shuffle(
state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize
);
state->x = 0;
if (state->state == INIT) {
/* preload the run-length buffer and get going */
context->last = state->buffer[0];
context->count = state->x = 1;
state->state = ENCODE;
}
/* step forward, according to the interlace settings */
state->y += context->step;
while (context->interlace && state->y >= state->ysize)
switch (context->interlace) {
case 1:
state->y = 4;
context->interlace = 2;
break;
case 2:
context->step = 4;
state->y = 2;
context->interlace = 3;
break;
case 3:
context->step = 2;
state->y = 1;
context->interlace = 0;
break;
default:
/* just make sure we don't loop forever */
context->interlace = 0;
}
}
this = state->buffer[state->x++];
if (this == context->last)
context->count++;
else {
//.........这里部分代码省略.........
示例8: switch
//.........这里部分代码省略.........
{
/* Use the lib's default */
break;
}
}
if (context->progressive)
jpeg_simple_progression(&context->cinfo);
context->cinfo.smoothing_factor = context->smooth;
context->cinfo.optimize_coding = (boolean) context->optimize;
if (context->xdpi > 0 && context->ydpi > 0) {
context->cinfo.density_unit = 1; /* dots per inch */
context->cinfo.X_density = context->xdpi;
context->cinfo.Y_density = context->ydpi;
}
switch (context->streamtype) {
case 1:
/* tables only -- not yet implemented */
state->errcode = IMAGING_CODEC_CONFIG;
return -1;
case 2:
/* image only */
jpeg_suppress_tables(&context->cinfo, TRUE);
jpeg_start_compress(&context->cinfo, FALSE);
/* suppress extra section */
context->extra_offset = context->extra_size;
//add exif header
if (context->rawExifLen > 0)
jpeg_write_marker(&context->cinfo, JPEG_APP0+1, (unsigned char*)context->rawExif, context->rawExifLen);
break;
default:
/* interchange stream */
jpeg_start_compress(&context->cinfo, TRUE);
//add exif header
if (context->rawExifLen > 0)
jpeg_write_marker(&context->cinfo, JPEG_APP0+1, (unsigned char*)context->rawExif, context->rawExifLen);
break;
}
state->state++;
/* fall through */
case 2:
if (context->extra) {
/* copy extra buffer to output buffer */
unsigned int n = context->extra_size - context->extra_offset;
if (n > context->destination.pub.free_in_buffer)
n = context->destination.pub.free_in_buffer;
memcpy(context->destination.pub.next_output_byte,
context->extra + context->extra_offset, n);
context->destination.pub.next_output_byte += n;
context->destination.pub.free_in_buffer -= n;
context->extra_offset += n;
if (context->extra_offset >= context->extra_size)
state->state++;
else
break;
} else
state->state++;
case 3:
ok = 1;
while (state->y < state->ysize) {
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
ok = jpeg_write_scanlines(&context->cinfo, &state->buffer, 1);
if (ok != 1)
break;
state->y++;
}
if (ok != 1)
break;
state->state++;
/* fall through */
case 4:
/* Finish compression */
if (context->destination.pub.free_in_buffer < 100)
break;
jpeg_finish_compress(&context->cinfo);
/* Clean up */
if (context->extra)
free(context->extra);
jpeg_destroy_compress(&context->cinfo);
/* if (jerr.pub.num_warnings) return BROKEN; */
state->errcode = IMAGING_CODEC_END;
break;
}
/* Return number of bytes in output buffer */
return context->destination.pub.next_output_byte - buf;
}
示例9: if
//.........这里部分代码省略.........
state->errcode = IMAGING_CODEC_BROKEN;
else if (err == Z_MEM_ERROR)
state->errcode = IMAGING_CODEC_MEMORY;
else
state->errcode = IMAGING_CODEC_CONFIG;
free(context->paeth);
free(context->average);
free(context->up);
free(context->prior);
free(context->previous);
deflateEnd(&context->z_stream);
return -1;
}
}
ImagingSectionEnter(&cookie);
for (;;) {
switch (state->state) {
case 1:
/* Compress image data */
while (context->z_stream.avail_out > 0) {
if (state->y >= state->ysize) {
/* End of image; now flush compressor buffers */
state->state = 2;
break;
}
/* Stuff image data into the compressor */
state->shuffle(state->buffer+1,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize,
state->xsize);
state->y++;
context->output = state->buffer;
if (context->mode == ZIP_PNG) {
/* Filter the image data. For each line, select
the filter that gives the least total distance
from zero for the filtered data (taken from
LIBPNG) */
bpp = (state->bits + 7) / 8;
/* 0. No filter */
for (i = 1, sum = 0; i <= state->bytes; i++) {
UINT8 v = state->buffer[i];
sum += (v < 128) ? v : 256 - v;
}
/* 2. Up. We'll test this first to save time when
an image line is identical to the one above. */
if (sum > 0) {
for (i = 1, s = 0; i <= state->bytes; i++) {
UINT8 v = state->buffer[i] - context->previous[i];
context->up[i] = v;
s += (v < 128) ? v : 256 - v;
}
if (s < sum) {
示例10: ImagingLibTiffEncode
int ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8* buffer, int bytes) {
/* One shot encoder. Encode everything to the tiff in the clientstate.
If we're running off of a FD, then run once, we're good, everything
ends up in the file, we close and we're done.
If we're going to memory, then we need to write the whole file into memory, then
parcel it back out to the pystring buffer bytes at a time.
*/
TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
TIFF *tiff = clientstate->tiff;
TRACE(("in encoder: bytes %d\n", bytes));
TRACE(("State: count %d, state %d, x %d, y %d, ystep %d\n", state->count, state->state,
state->x, state->y, state->ystep));
TRACE(("State: xsize %d, ysize %d, xoff %d, yoff %d \n", state->xsize, state->ysize,
state->xoff, state->yoff));
TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes));
TRACE(("Buffer: %p: %c%c%c%c\n", buffer, (char)buffer[0], (char)buffer[1],(char)buffer[2], (char)buffer[3]));
TRACE(("State->Buffer: %c%c%c%c\n", (char)state->buffer[0], (char)state->buffer[1],(char)state->buffer[2], (char)state->buffer[3]));
TRACE(("Image: mode %s, type %d, bands: %d, xsize %d, ysize %d \n",
im->mode, im->type, im->bands, im->xsize, im->ysize));
TRACE(("Image: image8 %p, image32 %p, image %p, block %p \n",
im->image8, im->image32, im->image, im->block));
TRACE(("Image: pixelsize: %d, linesize %d \n",
im->pixelsize, im->linesize));
dump_state(clientstate);
if (state->state == 0) {
TRACE(("Encoding line bt line"));
while(state->y < state->ysize){
state->shuffle(state->buffer,
(UINT8*) im->image[state->y + state->yoff] +
state->xoff * im->pixelsize,
state->xsize);
if (TIFFWriteScanline(tiff, (tdata_t)(state->buffer), (uint32)state->y, 0) == -1) {
TRACE(("Encode Error, row %d\n", state->y));
state->errcode = IMAGING_CODEC_BROKEN;
TIFFClose(tiff);
if (!clientstate->fp){
free(clientstate->data);
}
return -1;
}
state->y++;
}
if (state->y == state->ysize) {
state->state=1;
TRACE(("Flushing \n"));
if (!TIFFFlush(tiff)) {
TRACE(("Error flushing the tiff"));
// likely reason is memory.
state->errcode = IMAGING_CODEC_MEMORY;
TIFFClose(tiff);
if (!clientstate->fp){
free(clientstate->data);
}
return -1;
}
TRACE(("Closing \n"));
TIFFClose(tiff);
// reset the clientstate metadata to use it to read out the buffer.
clientstate->loc = 0;
clientstate->size = clientstate->eof; // redundant?
}
}
if (state->state == 1 && !clientstate->fp) {
int read = (int)_tiffReadProc(clientstate, (tdata_t)buffer, (tsize_t)bytes);
TRACE(("Buffer: %p: %c%c%c%c\n", buffer, (char)buffer[0], (char)buffer[1],(char)buffer[2], (char)buffer[3]));
if (clientstate->loc == clientstate->eof) {
TRACE(("Hit EOF, calling an end, freeing data"));
state->errcode = IMAGING_CODEC_END;
free(clientstate->data);
}
return read;
}
state->errcode = IMAGING_CODEC_END;
return 0;
}
示例11: ImagingLibTiffDecode
//.........这里部分代码省略.........
if (state->bytes > INT_MAX - 1) {
state->errcode = IMAGING_CODEC_MEMORY;
TIFFClose(tiff);
return -1;
}
/* realloc to fit whole tile */
new_data = realloc (state->buffer, state->bytes);
if (!new_data) {
state->errcode = IMAGING_CODEC_MEMORY;
TIFFClose(tiff);
return -1;
}
state->buffer = new_data;
TRACE(("TIFFTileSize: %d\n", state->bytes));
for (y = state->yoff; y < state->ysize; y += tile_length) {
for (x = state->xoff; x < state->xsize; x += tile_width) {
if (ReadTile(tiff, x, y, (UINT32*) state->buffer) == -1) {
TRACE(("Decode Error, Tile at %dx%d\n", x, y));
state->errcode = IMAGING_CODEC_BROKEN;
TIFFClose(tiff);
return -1;
}
TRACE(("Read tile at %dx%d; \n\n", x, y));
current_tile_width = min(tile_width, state->xsize - x);
// iterate over each line in the tile and stuff data into image
for (tile_y = 0; tile_y < min(tile_length, state->ysize - y); tile_y++) {
TRACE(("Writing tile data at %dx%d using tile_width: %d; \n", tile_y + y, x, current_tile_width));
// UINT8 * bbb = state->buffer + tile_y * row_byte_size;
// TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
state->shuffle((UINT8*) im->image[tile_y + y] + x * im->pixelsize,
state->buffer + tile_y * row_byte_size,
current_tile_width
);
}
}
}
} else {
UINT32 strip_row, row_byte_size;
UINT8 *new_data;
UINT32 rows_per_strip;
TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
TRACE(("RowsPerStrip: %u \n", rows_per_strip));
// We could use TIFFStripSize, but for YCbCr data it returns subsampled data size
row_byte_size = (state->xsize * state->bits + 7) / 8;
state->bytes = rows_per_strip * row_byte_size;
TRACE(("StripSize: %d \n", state->bytes));
/* realloc to fit whole strip */
new_data = realloc (state->buffer, state->bytes);
if (!new_data) {
state->errcode = IMAGING_CODEC_MEMORY;
TIFFClose(tiff);
return -1;
}
state->buffer = new_data;
for (; state->y < state->ysize; state->y += rows_per_strip) {
if (ReadStrip(tiff, state->y, (UINT32 *)state->buffer) == -1) {
TRACE(("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0)));
state->errcode = IMAGING_CODEC_BROKEN;
TIFFClose(tiff);
return -1;
}
TRACE(("Decoded strip for row %d \n", state->y));
// iterate over each row in the strip and stuff data into image
for (strip_row = 0; strip_row < min(rows_per_strip, state->ysize - state->y); strip_row++) {
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
// UINT8 * bbb = state->buffer + strip_row * (state->bytes / rows_per_strip);
// TRACE(("chars: %x %x %x %x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1], ((UINT8 *)bbb)[2], ((UINT8 *)bbb)[3]));
state->shuffle((UINT8*) im->image[state->y + state->yoff + strip_row] +
state->xoff * im->pixelsize,
state->buffer + strip_row * row_byte_size,
state->xsize);
}
}
}
TIFFClose(tiff);
TRACE(("Done Decoding, Returning \n"));
// Returning -1 here to force ImageFile.load to break, rather than
// even think about looping back around.
return -1;
}
示例12: malloc
int
ImagingWebPEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
WEBPCONTEXT* context = (WEBPCONTEXT*) state->context;
UINT8* buffer;
UINT8* ptr;
int y, stride;
float quality = 75.0F;
if (!state->state) {
/* copy image contents to packed buffer and compress it */
stride = state->xsize * 3;
buffer = malloc(im->ysize * stride);
if (!buffer) {
state->errcode = IMAGING_CODEC_MEMORY;
return -1;
}
for (ptr = buffer, y = 0; y < state->ysize; ptr += stride, y++) {
state->shuffle(ptr, (UINT8*) im->image[y + state->yoff] +
state->xoff * im->pixelsize, state->xsize);
}
if (context->quality > 0)
quality = (float) context->quality;
context->output_size = WebPEncodeRGB(buffer,
state->xsize, state->ysize,
stride, quality,
&context->output_data);
free(buffer);
if (!context->output_size) {
state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
state->state++;
/* keep a pointer to the full buffer */
context->output_buffer = context->output_data;
}
if (context->output_size < bytes) {
/* copy remaining part to output buffer */
memcpy(buf, context->output_data, context->output_size);
state->errcode = IMAGING_CODEC_END;
free(context->output_buffer);
return context->output_size;
} else {
/* not enough space; fill the buffer and try again next time */
memcpy(buf, context->output_data, bytes);
context->output_data += bytes;
context->output_size -= bytes;
return bytes;
}
}