本文整理汇总了C++中setjmp函数的典型用法代码示例。如果您正苦于以下问题:C++ setjmp函数的具体用法?C++ setjmp怎么用?C++ setjmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setjmp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pic_apply
pic_value
pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
{
struct pic_code *pc, c;
int ai = pic_gc_arena_preserve(pic);
jmp_buf jmp;
size_t argc, i;
struct pic_code boot[2];
#if PIC_DIRECT_THREADED_VM
static void *oplabels[] = {
&&L_OP_POP, &&L_OP_PUSHNIL, &&L_OP_PUSHTRUE, &&L_OP_PUSHFALSE, &&L_OP_PUSHFLOAT,
&&L_OP_PUSHINT, &&L_OP_PUSHCHAR, &&L_OP_PUSHCONST,
&&L_OP_GREF, &&L_OP_GSET, &&L_OP_LREF, &&L_OP_LSET, &&L_OP_CREF, &&L_OP_CSET,
&&L_OP_JMP, &&L_OP_JMPIF, &&L_OP_CALL, &&L_OP_TAILCALL, &&L_OP_RET, &&L_OP_LAMBDA,
&&L_OP_CONS, &&L_OP_CAR, &&L_OP_CDR, &&L_OP_NILP,
&&L_OP_ADD, &&L_OP_SUB, &&L_OP_MUL, &&L_OP_DIV,
&&L_OP_EQ, &&L_OP_LT, &&L_OP_LE, &&L_OP_STOP
};
#endif
if (setjmp(jmp) == 0) {
pic->jmp = &jmp;
}
else {
goto L_RAISE;
}
argc = pic_length(pic, argv) + 1;
#if VM_DEBUG
puts("== booting VM...");
printf(" proc = ");
pic_debug(pic, pic_obj_value(proc));
puts("");
printf(" argv = ");
pic_debug(pic, argv);
puts("");
printf(" irep = ");
print_irep(pic, proc->u.irep);
puts("\nLet's go!");
#endif
PUSH(pic_obj_value(proc));
for (i = 1; i < argc; ++i) {
PUSH(pic_car(pic, argv));
argv = pic_cdr(pic, argv);
}
/* boot! */
boot[0].insn = OP_CALL;
boot[0].u.i = argc;
boot[1].insn = OP_STOP;
pc = boot;
c = *pc;
goto L_CALL;
VM_LOOP {
CASE(OP_POP) {
POPN(1);
NEXT;
}
CASE(OP_PUSHNIL) {
PUSH(pic_nil_value());
NEXT;
}
CASE(OP_PUSHTRUE) {
PUSH(pic_true_value());
NEXT;
}
CASE(OP_PUSHFALSE) {
PUSH(pic_false_value());
NEXT;
}
CASE(OP_PUSHFLOAT) {
PUSH(pic_float_value(c.u.f));
NEXT;
}
CASE(OP_PUSHINT) {
PUSH(pic_int_value(c.u.i));
NEXT;
}
CASE(OP_PUSHCHAR) {
PUSH(pic_char_value(c.u.c));
NEXT;
}
CASE(OP_PUSHCONST) {
PUSH(pic->pool[c.u.i]);
NEXT;
}
CASE(OP_GREF) {
PUSH(pic->globals[c.u.i]);
NEXT;
}
CASE(OP_GSET) {
pic->globals[c.u.i] = POP();
NEXT;
}
CASE(OP_LREF) {
PUSH(pic->ci->fp[c.u.i]);
//.........这里部分代码省略.........
开发者ID:hiromu,项目名称:picrin,代码行数:101,代码来源:vm.c
示例2: vp8_decode
static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
const uint8_t *data,
unsigned int data_sz,
void *user_priv,
long deadline)
{
vpx_codec_err_t res = VPX_CODEC_OK;
unsigned int resolution_change = 0;
unsigned int w, h;
if (!ctx->fragments.enabled && (data == NULL && data_sz == 0))
{
return 0;
}
/* Update the input fragment data */
if(update_fragments(ctx, data, data_sz, &res) <= 0)
return res;
/* Determine the stream parameters. Note that we rely on peek_si to
* validate that we have a buffer that does not wrap around the top
* of the heap.
*/
w = ctx->si.w;
h = ctx->si.h;
res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0],
&ctx->si, ctx->decrypt_cb, ctx->decrypt_state);
if((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf)
{
/* the peek function returns an error for non keyframes, however for
* this case, it is not an error */
res = VPX_CODEC_OK;
}
if(!ctx->decoder_init && !ctx->si.is_kf)
res = VPX_CODEC_UNSUP_BITSTREAM;
if ((ctx->si.h != h) || (ctx->si.w != w))
resolution_change = 1;
/* Initialize the decoder instance on the first frame*/
if (!res && !ctx->decoder_init)
{
VP8D_CONFIG oxcf;
oxcf.Width = ctx->si.w;
oxcf.Height = ctx->si.h;
oxcf.Version = 9;
oxcf.postprocess = 0;
oxcf.max_threads = ctx->cfg.threads;
oxcf.error_concealment =
(ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
/* If postprocessing was enabled by the application and a
* configuration has not been provided, default it.
*/
if (!ctx->postproc_cfg_set
&& (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) {
ctx->postproc_cfg.post_proc_flag =
VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE;
ctx->postproc_cfg.deblocking_level = 4;
ctx->postproc_cfg.noise_level = 0;
}
res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf);
ctx->decoder_init = 1;
}
/* Set these even if already initialized. The caller may have changed the
* decrypt config between frames.
*/
if (ctx->decoder_init) {
ctx->yv12_frame_buffers.pbi[0]->decrypt_cb = ctx->decrypt_cb;
ctx->yv12_frame_buffers.pbi[0]->decrypt_state = ctx->decrypt_state;
}
if (!res)
{
VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0];
if (resolution_change)
{
VP8_COMMON *const pc = & pbi->common;
MACROBLOCKD *const xd = & pbi->mb;
#if CONFIG_MULTITHREAD
int i;
#endif
pc->Width = ctx->si.w;
pc->Height = ctx->si.h;
{
int prev_mb_rows = pc->mb_rows;
if (setjmp(pbi->common.error.jmp))
{
pbi->common.error.setjmp = 0;
vp8_clear_system_state();
/* same return value as used in vp8dx_receive_compressed_data */
return -1;
}
//.........这里部分代码省略.........
开发者ID:nvnhcmus,项目名称:libvpx,代码行数:101,代码来源:vp8_dx_iface.c
示例3: Congrd1
void
Congrd1(ASL_fg *asl, int i, real *X, real *G, fint *nerror)
{
Jmp_buf err_jmp0;
cde *d;
cgrad *gr, *gr1;
int i0, ij, j, *vmi, xksave;
real *Adjoints, *vscale;
size_t L;
if (nerror && *nerror >= 0) {
err_jmp = &err_jmp0;
ij = setjmp(err_jmp0.jb);
if ((*nerror = ij))
return;
}
errno = 0; /* in case f77 set errno opening files */
if (!asl->i.x_known)
x0_check_ASL(asl,X);
if ((!asl->i.ncxval || asl->i.ncxval[i] != asl->i.nxval)
&& (!(x0kind & ASL_have_conval)
|| i < n_conjac[0] || i >= n_conjac[1])) {
xksave = asl->i.x_known;
asl->i.x_known = 1;
con1ival((ASL*)asl,i,X,nerror);
asl->i.x_known = xksave;
if (nerror && *nerror)
return;
}
if (asl->i.Derrs)
deriv_errchk_ASL((ASL*)asl, nerror, i, 1);
if (!(x0kind & ASL_have_funnel)) {
if (f_b)
funnelset_ASL(asl, f_b);
if (f_c)
funnelset_ASL(asl, f_c);
x0kind |= ASL_have_funnel;
}
Adjoints = adjoints;
d = &con_de[i];
gr1 = asl->i.Cgrad0[i];
for(gr = gr1; gr; gr = gr->next)
Adjoints[gr->varno] = gr->coef;
if ((L = d->zaplen)) {
memset(adjoints_nv1, 0, L);
derprop(d->d);
}
vmi = 0;
if (asl->i.vmap)
vmi = get_vminv_ASL((ASL*)asl);
if ((vscale = asl->i.vscale)) {
if (vmi)
for(gr = gr1; gr; gr = gr->next) {
i0 = gr->varno;
Adjoints[i0] *= vscale[vmi[i0]];
}
else
for(gr = gr1; gr; gr = gr->next) {
i0 = gr->varno;
Adjoints[i0] *= vscale[i0];
}
}
gr = gr1;
i0 = 0;
switch(asl->i.congrd_mode) {
case 1:
for(; gr; gr = gr->next)
G[i0++] = Adjoints[gr->varno];
break;
case 2:
for(; gr; gr = gr->next)
G[gr->goff] = Adjoints[gr->varno];
break;
default:
if (vmi) {
for(; gr; gr = gr->next) {
i = vmi[j = gr->varno];
while(i0 < i)
G[i0++] = 0;
G[i] = Adjoints[j];
i0 = i + 1;
}
}
else
for(; gr; gr = gr->next) {
i = gr->varno;
while(i0 < i)
G[i0++] = 0;
G[i] = Adjoints[i];
i0 = i + 1;
}
i = n_var;
while(i0 < i)
G[i0++] = 0;
}
err_jmp = 0;
}
开发者ID:gidden,项目名称:mp,代码行数:97,代码来源:con1ival.c
示例4: Screendump
void Screendump(const char* destFile, const int width, const int height)
{
std::string fname = join_path(GetPiUserDir("screenshots").c_str(), destFile, 0);
// pad rows to 4 bytes, which is the default row alignment for OpenGL
const int stride = (3*width + 3) & ~3;
std::vector<png_byte> pixel_data(stride * height);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glPixelStorei(GL_PACK_ALIGNMENT, 4); // never trust defaults
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &pixel_data[0]);
glFinish();
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (!png_ptr) {
fprintf(stderr, "Couldn't create png_write_struct\n");
return;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, 0);
fprintf(stderr, "Couldn't create png_info_struct\n");
return;
}
//http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.1
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fprintf(stderr, "Couldn't set png jump buffer\n");
return;
}
FILE *out = fopen(fname.c_str(), "wb");
if (!out) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fprintf(stderr, "Couldn't open %s for writing\n", fname.c_str());
return;
}
png_init_io(png_ptr, out);
png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_bytepp rows = new png_bytep[height];
for (int i = 0; i < height; ++i) {
rows[i] = reinterpret_cast<png_bytep>(&pixel_data[(height-i-1) * stride]);
}
png_set_rows(png_ptr, info_ptr, rows);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0);
png_destroy_write_struct(&png_ptr, &info_ptr);
delete[] rows;
fclose(out);
printf("Screenshot %s saved\n", fname.c_str());
}
开发者ID:Sunsetjoy,项目名称:pioneer,代码行数:62,代码来源:utils.cpp
示例5: load_image
static gint32
load_image (char *filename)
{
GPixelRgn pixel_rgn;
TileDrawable *drawable;
gint32 image_ID;
gint32 layer_ID;
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *infile;
guchar *buf;
guchar **rowbuf;
char *name;
int image_type;
int layer_type;
int tile_height;
int scanlines;
int i, start, end;
int m;
int depth = 8;
/* We set up the normal JPEG error routines. */
cinfo.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if ((infile = fopen (filename, "rb")) == NULL)
{
g_warning ("can't open \"%s\"\n", filename);
gimp_quit ();
}
if( strrchr(filename,'.') &&
strcmp( strrchr(filename, '.'), ".jp4") == 0 )
depth = 16;
name = malloc (strlen (filename) + 12);
sprintf (name, "%s %s:", _("Loading"), filename);
gimp_progress_init (name);
free (name);
image_ID = -1;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp (jerr.setjmp_buffer))
{
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress (&cinfo);
if (infile)
fclose (infile);
if (image_ID != -1)
gimp_image_delete (image_ID);
gimp_quit ();
}
/* Now we can initialize the JPEG decompression object. */
jpeg_create_decompress (&cinfo);
/* Step 2: specify data source (eg, a file) */
jpeg_stdio_src (&cinfo, infile);
setup_read_icc_profile(&cinfo);
for (m = 0; m < 16; m++)
jpeg_save_markers(&cinfo, JPEG_APP0 + m, 0xFFFF);
/* Step 3: read file parameters with jpeg_read_header() */
(void) jpeg_read_header (&cinfo, TRUE);
/* We can ignore the return value from jpeg_read_header since
* (a) suspension is not possible with the stdio data source, and
* (b) we passed TRUE to reject a tables-only JPEG file as an error.
* See libjpeg.doc for more info.
*/
/* Step 4: set parameters for decompression */
/* In this example, we don't need to change any of the defaults set by
* jpeg_read_header(), so we do nothing here.
*/
prepareColour( &cinfo );
/* Step 5: Start decompressor */
jpeg_start_decompress (&cinfo);
/* We may need to do some setup of our own at this point before reading
* the data. After jpeg_start_decompress() we have the correct scaled
* output image dimensions available, as well as the output colormap
* if we asked for color quantization.
* In this example, we need to make an output work buffer of the right size.
*/
/* temporary buffer */
tile_height = gimp_tile_height ();
buf = g_new (guchar, tile_height * cinfo.output_width * cinfo.output_components);
rowbuf = g_new (guchar*, tile_height);
for (i = 0; i < tile_height; i++)
rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i;
/* Create a new image of the proper size and associate the filename with it.
//.........这里部分代码省略.........
开发者ID:milankni,项目名称:cinepaint-oyranos,代码行数:101,代码来源:jpeg.c
示例6: Coro_setup
void Coro_setup(Coro *self, void *arg)
{
setjmp(buf);
buf[8] = (int)Coro_stack(self) + (int)Coro_stackSize(self) - 16;
buf[9] = (int)Coro_Start;
}
开发者ID:bolshakov,项目名称:io,代码行数:6,代码来源:Coro.c
示例7: png_create_read_struct
// load in the image data
IImage* CImageLoaderPng::loadImage(io::IReadFile* file) const
{
#ifdef _IRR_COMPILE_WITH_LIBPNG_
if (!file)
return 0;
video::IImage* image = 0;
//Used to point to image rows
u8** RowPointers = 0;
png_byte buffer[8];
// Read the first few bytes of the PNG file
if( file->read(buffer, 8) != 8 )
{
os::Printer::log("LOAD PNG: can't read file\n", file->getFileName(), ELL_ERROR);
return 0;
}
// Check if it really is a PNG file
if( png_sig_cmp(buffer, 0, 8) )
{
os::Printer::log("LOAD PNG: not really a png\n", file->getFileName(), ELL_ERROR);
return 0;
}
// Allocate the png read struct
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, (png_error_ptr)png_cpexcept_error, (png_error_ptr)png_cpexcept_warn);
if (!png_ptr)
{
os::Printer::log("LOAD PNG: Internal PNG create read struct failure\n", file->getFileName(), ELL_ERROR);
return 0;
}
// Allocate the png info struct
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
os::Printer::log("LOAD PNG: Internal PNG create info struct failure\n", file->getFileName(), ELL_ERROR);
png_destroy_read_struct(&png_ptr, NULL, NULL);
return 0;
}
// for proper error handling
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
if (RowPointers)
delete [] RowPointers;
return 0;
}
// changed by zola so we don't need to have public FILE pointers
png_set_read_fn(png_ptr, file, user_read_data_fcn);
png_set_sig_bytes(png_ptr, 8); // Tell png that we read the signature
png_read_info(png_ptr, info_ptr); // Read the info section of the png file
u32 Width;
u32 Height;
s32 BitDepth;
s32 ColorType;
{
// Use temporary variables to avoid passing casted pointers
png_uint_32 w,h;
// Extract info
png_get_IHDR(png_ptr, info_ptr,
&w, &h,
&BitDepth, &ColorType, NULL, NULL, NULL);
Width=w;
Height=h;
}
// Convert palette color to true color
if (ColorType==PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
// Convert low bit colors to 8 bit colors
if (BitDepth < 8)
{
if (ColorType==PNG_COLOR_TYPE_GRAY || ColorType==PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_expand_gray_1_2_4_to_8(png_ptr);
else
png_set_packing(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
// Convert high bit colors to 8 bit colors
if (BitDepth == 16)
png_set_strip_16(png_ptr);
// Convert gray color to true color
if (ColorType==PNG_COLOR_TYPE_GRAY || ColorType==PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
int intent;
//.........这里部分代码省略.........
开发者ID:Badcreature,项目名称:sagcg,代码行数:101,代码来源:CImageLoaderPNG.cpp
示例8: display_loop
void display_loop(){
// mcuf_serial_mode();
mode = setjmp(newmode_jmpbuf);
#ifdef JOYSTICK_SUPPORT
// in case we get here via mode jump, we (re)enable joystick queries
waitForFire = 1;
#endif
oldOldmode = oldMode;
#ifdef JOYSTICK_SUPPORT
waitForFire = 1;
#endif
for(;;){
#ifndef MENU_SUPPORT
clear_screen(0);
#endif
oldMode = mode;
switch(mode++) {
#ifdef ANIMATION_SCROLLTEXT
case 1:
scrolltext(scrolltext_text);
#ifdef RANDOM_SUPPORT
{
char a[28];
sprintf(a,"</# counter == %lu ",
(unsigned long)percnt_get(&g_reset_counter, &g_reset_counter_idx));
scrolltext(a);
}
#endif
#endif
#ifdef ANIMATION_TIME
#ifndef ANIMATION_SCROLLTEXT
case 1:
#endif
time_anim();
break;
#else
#ifdef ANIMATION_SCROLLTEXT
break;
#endif
#endif
#ifdef ANIMATION_SPIRAL
# ifndef SPIRAL_DELAY
# define SPIRAL_DELAY 5
# endif
case 2:
spiral(SPIRAL_DELAY);
break;
#endif
#ifdef ANIMATION_JOERN1
case 3:
joern1();
break;
#endif
#ifdef ANIMATION_SNAKE
case 4:
snake_animation();
break;
#endif
#ifdef ANIMATION_CHECKERBOARD
case 5:
checkerboard(20);
break;
#endif
#ifdef ANIMATION_FIRE
case 6:
fire();
break;
#endif
#ifdef ANIMATION_TIME
case 7:
time_anim();
break;
#endif
#ifdef ANIMATION_MATRIX
case 8:
matrix();
break;
#endif
#ifdef ANIMATION_RANDOM_BRIGHT
case 9:
random_bright(30);
break;
#endif
//.........这里部分代码省略.........
开发者ID:stefanctdo,项目名称:borgware-2d,代码行数:101,代码来源:display_loop.c
示例9: writepng
static gboolean writepng( FILE *f, GrxContext *grc )
{
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 height;
png_uint_32 width;
png_byte *png_pixels = NULL;
png_byte **row_pointers = NULL;
png_byte *pix_ptr = NULL;
int x, y;
unsigned char r, g, b;
GrxColor *pColors = NULL;
/* Create and initialize the png_struct */
png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
if( png_ptr == NULL )
return FALSE;
/* Allocate/initialize the image information data */
info_ptr = png_create_info_struct( png_ptr );
if( info_ptr == NULL ){
png_destroy_write_struct( &png_ptr,(png_infopp)NULL );
return FALSE;
}
/* Set error handling */
if( setjmp( png_jmpbuf(png_ptr) ) ){
/* If we get here, we had a problem reading the file */
png_destroy_write_struct( &png_ptr,&info_ptr );
return FALSE;
}
/* set up the output control we are using standard C streams */
png_init_io( png_ptr,f );
/* Set the image information */
width = grx_get_width();
height = grx_get_height();
png_set_IHDR( png_ptr,info_ptr,width,height,8,PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE );
/* No gamma correction by now */
/* png_set_gAMA(png_ptr, info_ptr, gamma); */
/* No comments by now */
/* text_ptr[0].key = "Title";
text_ptr[0].text = "Mona Lisa";
text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[1].key = "Author";
text_ptr[1].text = "Leonardo DaVinci";
text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[2].key = "Description";
text_ptr[2].text = "<long text>";
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
png_set_text(png_ptr, info_ptr, text_ptr, 3); */
/* Write the file header information */
png_write_info( png_ptr,info_ptr );
png_pixels = (png_byte *) malloc( width * 3 * sizeof(png_byte) );
if( png_pixels == NULL ){
png_destroy_write_struct( &png_ptr,&info_ptr );
return FALSE;
}
row_pointers = (png_byte **) malloc( 1 * sizeof(png_bytep) );
if( row_pointers == NULL ){
png_destroy_write_struct( &png_ptr,&info_ptr );
free( png_pixels );
return FALSE;
}
pColors = malloc( width * sizeof(GrxColor) );
if( pColors == NULL ){
png_destroy_write_struct( &png_ptr,&info_ptr );
free( row_pointers );
free( png_pixels );
return FALSE;
}
row_pointers[0] = png_pixels;
for( y=0; y<height; y++ ){
pix_ptr = png_pixels;
memcpy( pColors,grx_get_scanline( 0,width-1,y,NULL ),sizeof(GrxColor)*width );
for( x=0; x<width; x++ ){
grx_color_query( pColors[x],&r,&g,&b );
*pix_ptr++ = r;
*pix_ptr++ = g;
*pix_ptr++ = b;
}
png_write_rows( png_ptr,&row_pointers[0],1 );
}
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end( png_ptr,info_ptr );
/* clean up after the write, and free any memory allocated */
png_destroy_write_struct( &png_ptr,&info_ptr );
//.........这里部分代码省略.........
开发者ID:ev3dev,项目名称:grx,代码行数:101,代码来源:ctx2png.c
示例10: obj2grd_ASL
void
obj2grd_ASL(ASL *a, int i, real *X, real *G, fint *nerror)
{
ASL_fgh *asl;
Jmp_buf err_jmp0;
cde *d;
fint ne0;
int ij, j, *vmi, xksave, *z;
ograd *gr, **gr0;
real *Adjoints, *vscale;
size_t L;
static char who[] = "obj2grd";
NNOBJ_chk(a, i, who);
asl = (ASL_fgh*)a;
if (!want_derivs)
No_derivs_ASL(who);
ne0 = -1;
if (nerror && (ne0 = *nerror) >= 0) {
err_jmp = &err_jmp0;
ij = setjmp(err_jmp0.jb);
if ((*nerror = ij))
goto done;
}
errno = 0; /* in case f77 set errno opening files */
if (!asl->i.x_known)
x2_check(X);
if (!asl->i.noxval || asl->i.noxval[i] != asl->i.nxval) {
xksave = asl->i.x_known;
asl->i.x_known = 1;
obj2val_ASL(a, i, X, nerror);
asl->i.x_known = xksave;
if (ne0 >= 0 && *nerror)
goto done;
}
if (asl->i.Derrs)
deriv_errchk_ASL(a, nerror, -(i+1), 1);
if (f_b)
funnelset(asl, f_b);
if (f_o)
funnelset(asl, f_o);
Adjoints = adjoints;
d = obj_de + i;
gr0 = Ograd + i;
for(gr = *gr0; gr; gr = gr->next)
Adjoints[gr->varno] = gr->coef;
if ((L = d->zaplen)) {
memset(adjoints_nv1, 0, L);
derprop(d->d);
}
if (zerograds) { /* sparse gradients */
z = zerograds[i];
while((i = *z++) >= 0)
G[i] = 0;
}
vmi = 0;
if (a->i.vmap)
vmi = get_vminv_ASL(a);
gr = *gr0;
if ((vscale = asl->i.vscale)) {
if (vmi)
for(; gr; gr = gr->next) {
j = vmi[i = gr->varno];
G[j] = vscale[j] * Adjoints[i];
}
else
for(; gr; gr = gr->next) {
i = gr->varno;
G[i] = vscale[i] * Adjoints[i];
}
}
else if (vmi)
for(; gr; gr = gr->next) {
i = gr->varno;
G[vmi[i]] = Adjoints[i];
}
else
for(; gr; gr = gr->next) {
i = gr->varno;
G[i] = Adjoints[i];
}
done:
err_jmp = 0;
}
开发者ID:ampl,项目名称:mp,代码行数:84,代码来源:obj2val.c
示例11: obj2val_ASL
real
obj2val_ASL(ASL *a, int i, real *X, fint *nerror)
{
ASL_fgh *asl;
Jmp_buf err_jmp0;
cde *d;
expr *e1;
int ij, j1, kv, *vmi;
ograd *gr, **gr0;
real f, *vscale;
NNOBJ_chk(a, i, "obj2val");
asl = (ASL_fgh*)a;
if (nerror && *nerror >= 0) {
err_jmp = &err_jmp0;
ij = setjmp(err_jmp0.jb);
if ((*nerror = ij)) {
f = 0.;
goto done;
}
}
want_deriv = want_derivs;
errno = 0; /* in case f77 set errno opening files */
x2_check(X);
if (!asl->i.noxval)
asl->i.noxval = (int*)M1zapalloc(n_obj*sizeof(int));
co_index = -(i + 1);
if (!(x0kind & ASL_have_objcom)) {
if (ncom0 > combc)
comeval(asl, combc, ncom0);
x0kind |= ASL_have_objcom;
}
d = obj_de + i;
if (d->n_com1)
com1eval(asl, d->com11, d->n_com1);
gr0 = Ograd + i;
e1 = d->e;
f = (*e1->op)(e1 C_ASL);
asl->i.noxval[i] = asl->i.nxval;
kv = 0;
vmi = 0;
if ((vscale = asl->i.vscale))
kv = 2;
if (asl->i.vmap) {
vmi = get_vminv_ASL(a);
++kv;
}
gr = *gr0;
switch(kv) {
case 3:
for(; gr; gr = gr->next) {
j1 = vmi[gr->varno];
f += X[j1] * vscale[j1] * gr->coef;
}
break;
case 2:
for(; gr; gr = gr->next) {
j1 = gr->varno;
f += X[j1] * vscale[j1] * gr->coef;
}
break;
case 1:
for(; gr; gr = gr->next)
f += X[vmi[gr->varno]] * gr->coef;
break;
case 0:
for(; gr; gr = gr->next)
f += X[gr->varno] * gr->coef;
}
done:
err_jmp = 0;
return f;
}
开发者ID:ampl,项目名称:mp,代码行数:73,代码来源:obj2val.c
示例12: process_queue
void process_queue(void) {
struct pkg_list *rundown;
struct pkginfo *volatile pkg;
volatile enum action action_todo;
jmp_buf ejbuf;
enum istobes istobe= itb_normal;
if (abort_processing)
return;
clear_istobes();
switch (cipaction->arg_int) {
case act_triggers:
case act_configure: case act_install: istobe= itb_installnew; break;
case act_remove: case act_purge: istobe= itb_remove; break;
default:
internerr("unknown action '%d'", cipaction->arg_int);
}
for (rundown = queue.head; rundown; rundown = rundown->next) {
ensure_package_clientdata(rundown->pkg);
if (rundown->pkg->clientdata->istobe == istobe) {
/* Erase the queue entry - this is a second copy! */
switch (cipaction->arg_int) {
case act_triggers:
case act_configure: case act_remove: case act_purge:
printf(_("Package %s listed more than once, only processing once.\n"),
pkg_name(rundown->pkg, pnaw_nonambig));
break;
case act_install:
printf(_("More than one copy of package %s has been unpacked\n"
" in this run ! Only configuring it once.\n"),
pkg_name(rundown->pkg, pnaw_nonambig));
break;
default:
internerr("unknown action '%d'", cipaction->arg_int);
}
rundown->pkg = NULL;
} else {
rundown->pkg->clientdata->istobe= istobe;
}
}
while (!pkg_queue_is_empty(&queue)) {
pkg = pkg_queue_pop(&queue);
if (!pkg)
continue; /* Duplicate, which we removed earlier. */
action_todo = cipaction->arg_int;
if (sincenothing++ > queue.length * 2 + 2) {
if (progress_bytrigproc && progress_bytrigproc->trigpend_head) {
enqueue_package(pkg);
pkg = progress_bytrigproc;
action_todo = act_configure;
} else {
dependtry++;
sincenothing = 0;
assert(dependtry <= 4);
}
}
assert(pkg->status <= stat_installed);
if (setjmp(ejbuf)) {
/* Give up on it from the point of view of other packages, i.e. reset
* istobe. */
pkg->clientdata->istobe= itb_normal;
pop_error_context(ehflag_bombout);
if (abort_processing)
return;
continue;
}
push_error_context_jump(&ejbuf, print_error_perpackage,
pkg_name(pkg, pnaw_nonambig));
switch (action_todo) {
case act_triggers:
if (!pkg->trigpend_head)
ohshit(_("package %.250s is not ready for trigger processing\n"
" (current status `%.250s' with no pending triggers)"),
pkg_name(pkg, pnaw_nonambig), statusinfos[pkg->status].name);
/* Fall through. */
case act_install:
/* Don't try to configure pkgs that we've just disappeared. */
if (pkg->status == stat_notinstalled)
break;
/* Fall through. */
case act_configure:
/* Do whatever is most needed. */
if (pkg->trigpend_head)
trigproc(pkg);
else
deferred_configure(pkg);
break;
case act_remove: case act_purge:
deferred_remove(pkg);
break;
default:
//.........这里部分代码省略.........
开发者ID:nisc-code,项目名称:dpkg,代码行数:101,代码来源:packages.c
示例13: ReadPNG
int ReadPNG(FILE* in_file, WebPPicture* const pic, int keep_alpha,
Metadata* const metadata) {
volatile png_structp png;
volatile png_infop info = NULL;
volatile png_infop end_info = NULL;
int color_type, bit_depth, interlaced;
int has_alpha;
int num_passes;
int p;
int ok = 0;
png_uint_32 width, height, y;
int stride;
uint8_t* volatile rgb = NULL;
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (png == NULL) {
goto End;
}
png_set_error_fn(png, 0, error_function, NULL);
if (setjmp(png_jmpbuf(png))) {
Error:
MetadataFree(metadata);
goto End;
}
info = png_create_info_struct(png);
if (info == NULL) goto Error;
end_info = png_create_info_struct(png);
if (end_info == NULL) goto Error;
png_init_io(png, in_file);
png_read_info(png, info);
if (!png_get_IHDR(png, info,
&width, &height, &bit_depth, &color_type, &interlaced,
NULL, NULL)) goto Error;
png_set_strip_16(png);
png_set_packing(png);
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png);
}
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
if (bit_depth < 8) {
png_set_expand_gray_1_2_4_to_8(png);
}
png_set_gray_to_rgb(png);
}
if (png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_tRNS_to_alpha(png);
has_alpha = 1;
} else {
has_alpha = !!(color_type & PNG_COLOR_MASK_ALPHA);
}
if (!keep_alpha) {
png_set_strip_alpha(png);
has_alpha = 0;
}
num_passes = png_set_interlace_handling(png);
png_read_update_info(png, info);
stride = (has_alpha ? 4 : 3) * width * sizeof(*rgb);
rgb = (uint8_t*)malloc(stride * height);
if (rgb == NULL) goto Error;
for (p = 0; p < num_passes; ++p) {
for (y = 0; y < height; ++y) {
png_bytep row = (png_bytep)(rgb + y * stride);
png_read_rows(png, &row, NULL, 1);
}
}
png_read_end(png, end_info);
if (metadata != NULL &&
!ExtractMetadataFromPNG(png, info, end_info, metadata)) {
fprintf(stderr, "Error extracting PNG metadata!\n");
goto Error;
}
pic->width = width;
pic->height = height;
pic->use_argb = 1;
ok = has_alpha ? WebPPictureImportRGBA(pic, rgb, stride)
: WebPPictureImportRGB(pic, rgb, stride);
if (!ok) {
goto Error;
}
End:
if (png != NULL) {
png_destroy_read_struct((png_structpp)&png,
(png_infopp)&info, (png_infopp)&end_info);
}
free(rgb);
return ok;
}
开发者ID:BBLionel,项目名称:libwebp,代码行数:98,代码来源:pngdec.c
示例14: runops
void
runops(PARROT_INTERP, size_t offs)
{
ASSERT_ARGS(runops)
volatile size_t offset = offs;
const int old_runloop_id = interp->current_runloop_id;
int our_runloop_level = interp->current_runloop_level;
int our_runloop_id = old_runloop_id;
/* It is OK if the runloop ID overflows; we only ever test it for equality,
so the chance of collision is slight. */
interp->current_runloop_id = our_runloop_id;
#if RUNLOOP_TRACE
fprintf(stderr, "[entering loop %d, level %d]\n",
interp->current_runloop_id, our_runloop_level);
#endif
/*
* STACKED_EXCEPTIONS are necessary to catch exceptions in reentered
* run loops, e.g. if a delegate method throws an exception
*/
#if ! STACKED_EXCEPTIONS
if (!interp->current_runloop)
#endif
{
new_runloop_jump_point(interp);
our_runloop_id = interp->current_runloop_id;
our_runloop_level = interp->current_runloop_level;
reenter:
interp->current_runloop->handler_start = NULL;
switch (setjmp(interp->current_runloop->resume)) {
case 1:
/* an exception was handled */
if (STACKED_EXCEPTIONS)
free_runloop_jump_point(interp);
interp->current_runloop_level = our_runloop_level - 1;
interp->current_runloop_id = old_runloop_id;
#if RUNLOOP_TRACE
fprintf(stderr, "[handled exception; back to loop %d, level %d]\n",
interp->current_runloop_id, interp->current_runloop_level);
#endif
return;
case 2:
/* Reenter the runloop from a exception thrown from C
* with a pir handler */
free_runloops_until(interp, our_runloop_id);
PARROT_ASSERT(interp->current_runloop->handler_start);
offset = interp->current_runloop->handler_start - interp->code->base.data;
/* Prevent incorrect reuse */
goto reenter;
case 3:
/* Reenter the runloop when finished the handling of a
* exception */
free_runloops_until(interp, our_runloop_id);
offset = interp->current_runloop->handler_start - interp->code->base.data;
goto reenter;
default:
break;
}
}
runops_int(interp, offset);
interp->current_runloop->handler_start = NULL;
/* Remove the current runloop marker (put it on the free list). */
if (STACKED_EXCEPTIONS || interp->current_runloop)
free_runloop_jump_point(interp);
#if RUNLOOP_TRACE
fprintf(stderr, "[exiting loop %d, level %d]\n",
our_runloop_id, our_runloop_level);
#endif
}
开发者ID:mpeters,项目名称:parrot,代码行数:76,代码来源:ops.c
示例15: png_create_write_struct
bool PNG::Encode (ImageBuffer *imageBuffer, ByteArray *bytes) {
png_structp png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, user_error_fn, user_warning_fn);
if (!png_ptr) {
return false;
}
png_infop info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr) {
return false;
}
if (setjmp (png_jmpbuf (png_ptr))) {
png_destroy_write_struct (&png_ptr, &info_ptr);
return false;
}
QuickVec<uint8> out_buffer;
png_set_write_fn (png_ptr, &out_buffer, user_write_data, user_flush_data);
int w = imageBuffer->width;
int h = imageBuffer->height;
int bit_depth = 8;
//int color_type = (inSurface->Format () & pfHasAlpha) ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB;
int color_type = PNG_COLOR_TYPE_RGB_ALPHA;
png_set_IHDR (png_ptr, info_ptr, w, h, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info (png_ptr, info_ptr);
bool do_alpha = (color_type == PNG_COLOR_TYPE_RGBA);
unsigned char* imageData = imageBuffer->data->Bytes();
int stride = w * imageBuffer->bpp;
{
QuickVec<uint8> row_data (w * 4);
png_bytep row = &row_data[0];
for (int y = 0; y < h; y++) {
uint8 *buf = &row_data[0];
const uint8 *src = (const uint8 *)(imageData + (stride * y));
for (int x = 0; x < w; x++) {
buf[0] = src[0];
buf[1] = src[1];
buf[2] = src[2];
src += 3;
buf += 3;
if (do_alpha) {
*buf++ = *src;
}
src++;
}
png_write_rows (png_ptr, &row, 1);
}
}
png_write_end (png_ptr, NULL);
*bytes = ByteArray (out_buffer);
return true;
}
开发者ID:Khaledgarbaya,项目名称:lime,代码行数:83,代码来源:PNG.cpp
示例16: png_pixel_plot
int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{
struct mainprog_info_type wpng_info;
struct mainprog_info_type *graphic;
uint8_t outdata[image_width * 3];
png_structp png_ptr;
png_infop info_ptr;
graphic = &wpng_info;
uint8_t *image_data;
int i, row, column, errn;
int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
switch(rotate_angle) {
case 0:
case 180:
graphic->width = image_width;
graphic->height = image_height;
break;
case 90:
case 270:
graphic->width = image_height;
graphic->height = image_width;
break;
}
/* sort out colour options */
to_upper((uint8_t*)symbol->fgcolour);
to_upper((uint8_t*)symbol->bgcolour);
if(strlen(symbol->fgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ZERROR_INVALID_OPTION;
}
if(strlen(symbol->bgcolour) != 6) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ZERROR_INVALID_OPTION;
}
errn = is_sane(SSET, (uint8_t*)symbol->fgcolour, strlen(symbol->fgcolour));
if (errn == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed foreground colour target");
return ZERROR_INVALID_OPTION;
}
errn = is_sane(SSET, (uint8_t*)symbol->bgcolour, strlen(symbol->bgcolour));
if (errn == ZERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "Malformed background colour target");
return ZERROR_INVALID_OPTION;
}
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
/* Open output file in binary mode */
if((symbol->output_options & BARCODE_STDOUT) != 0) {
graphic->outfile = stdout;
} else {
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "Can't open output file");
return ZERROR_FILE_ACCESS;
}
}
/* Set up error handling routine as proc() above */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL);
if (!png_ptr) {
strcpy(symbol->errtxt, "Out of memory");
return ZERROR_MEMORY;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
strcpy(symbol->errtxt, "Out of memory");
return ZERROR_MEMORY;
}
/* catch jumping here */
if (setjmp(graphic->jmpbuf)) {
png_destroy_write_struct(&png_ptr, &info_ptr);
strcpy(symbol->errtxt, "libpng error occurred");
return ZERROR_MEMORY;
}
/* open output file with libpng */
png_init_io(png_ptr, graphic->outfile);
/* set compression */
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
/* set Header block */
png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height,
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
/* write all chunks up to (but not including) first IDAT */
png_write_info(png_ptr, info_ptr);
//.........这里部分代码省略.........
开发者ID:dwatson78,项目名称:openrpt,代码行数:101,代码来源:png.c
示例17: memcpy
bool PNG::Decode (Resource *resource, ImageBuffer *imageBuffer) {
unsigned char png_sig[PNG_SIG_SIZE];
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
FILE_HANDLE *file = NULL;
if (resource->path) {
file = lime::fopen (resource->path, "rb");
if (!file) return false;
int read = lime::fread (png_sig, PNG_SIG_SIZE, 1, file);
if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE)) {
lime::fclose (file);
return false;
}
} else {
memcpy (png_sig, resource->data->Bytes (), PNG_SIG_SIZE);
if (png_sig_cmp (png_sig, 0, PNG_SIG_SIZE)) {
return false;
}
}
if ((png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) == NULL) {
if (file) lime::fclose (file);
return false;
}
if ((info_ptr = png_create_info_struct (png_ptr)) == NULL) {
png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
if (file) lime::fclose (file);
return false;
}
// sets the point which libpng will jump back to in the case of an error
if (setjmp (png_jmpbuf (png_ptr))) {
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp)NULL);
if (file) lime::fclose (file);
return false;
}
if (file) {
if (file->isFile ()) {
png_init_io (png_ptr, file->getFile ());
png_set_sig_bytes (png_ptr, PNG_SIG_SIZE);
} else {
ByteArray data = ByteArray (resource->path);
ReadBuffer buffer (data.Bytes (), data.Size ());
png_set_read_fn (png_ptr, &buffer, user_read_data_fn);
}
} else {
ReadBuffer buffer (resource->data->Bytes (), resource->data->Size ());
png_set_read_fn (png_ptr, &buffer, user_read_data_fn);
}
png_read_info (png_ptr, info_ptr);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
//bool has_alpha = (color_type == PNG_COLOR_TYPE_GRAY_ALPHA || color_type == PNG_COLOR_TYPE_RGB_ALPHA || png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS));
png_set_expand (png_ptr);
png_set_filler (png_ptr, 0xff, PNG_FILLER_AFTER);
//png_set_gray_1_2_4_to_8 (png_ptr);
png_set_palette_to_rgb (png_ptr);
png_set_gray_to_rgb (png_ptr);
if (bit_depth < 8) {
png_set_packing (png_ptr);
} else if (bit_depth == 16) {
|
请发表评论