--- psiconv/trunk/lib/psiconv/generate_image.c 2000/12/28 15:49:12 86 +++ psiconv/trunk/lib/psiconv/generate_image.c 2003/11/27 20:55:01 175 @@ -1,4 +1,5 @@ /* + generate_image.c - Part of psiconv, a PSION 5 file formats converter Copyright (c) 1999, 2000 Frodo Looijaard @@ -22,4 +23,766 @@ #include "generate_routines.h" #include "error.h" +#include "list.h" + +#ifdef DMALLOC +#include +#endif + +typedef psiconv_list psiconv_pixel_bytes; /* psiconv_u8 */ + +typedef psiconv_list psiconv_pixel_ints; /* of psiconv_u32 */ + +typedef struct psiconv_pixel_float_s +{ + psiconv_u32 length; + float *red; + float *green; + float *blue; +} psiconv_pixel_floats_t; + +static int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels, + int xsize,int ysize, + const psiconv_pixel_floats_t data, + int colordepth, + const psiconv_pixel_floats_t palet); +static int psiconv_pixel_data_to_bytes(const psiconv_config config, + psiconv_pixel_bytes *bytes, int xsize, + int ysize, const psiconv_pixel_ints pixels, + int colordepth); +static int psiconv_encode_rle8(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes); +static int psiconv_encode_rle16(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes); +static int psiconv_encode_rle24(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes); + +#define PALET_GREY_2_LEN 4 +float palet_grey_2_rgb[PALET_GREY_2_LEN] = {0.0/3, 1.0/3, 2.0/3, 3.0/3}; +#define PALET_GREY_4_LEN 16 +float palet_grey_4_rgb[PALET_GREY_4_LEN] = + { 0.0/15, 1.0/15, 2.0/15, 3.0/15, + 4.0/15, 5.0/15, 6.0/15, 7.0/15, + 8.0/15, 9.0/15, 10.0/15, 11.0/15, + 12.0/15, 13.0/15, 14.0/15, 15.0/15}; +#define PALET_NONE_LEN 0 + +psiconv_pixel_floats_t palet_grey_2 = + { + PALET_GREY_2_LEN, + (float *) palet_grey_2_rgb, + (float *) palet_grey_2_rgb, + (float *) palet_grey_2_rgb + }; + +psiconv_pixel_floats_t palet_grey_4 = + { + PALET_GREY_4_LEN, + (float *) palet_grey_4_rgb, + (float *) palet_grey_4_rgb, + (float *) palet_grey_4_rgb + }; + +psiconv_pixel_floats_t palet_none = + { + PALET_NONE_LEN, + NULL, + NULL, + NULL + }; + + +int psiconv_write_paint_data_section(const psiconv_config config, + psiconv_buffer buf, + const psiconv_paint_data_section value, + int is_clipart) +{ + int res,colordepth,i; + psiconv_pixel_ints ints; + psiconv_pixel_floats_t floats,palet; + psiconv_list bytes,bytes_rle; + psiconv_u8 *byteptr,encoding; + + if (!value) { + psiconv_warn(config,0,psiconv_buffer_length(buf),"Null paint data section"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + floats.red = value->red; + floats.green = value->green; + floats.blue = value->blue; + floats.length = value->xsize * value->ysize; + + switch (config->colordepth) { + default: + case 2: palet = (config->color?palet_none:palet_grey_2); + break; + case 4: palet = (config->color?palet_none:palet_grey_4); + break; + } + + if ((res = psiconv_collect_pixel_data(&ints,value->xsize, + value->ysize,floats, + config->colordepth,palet))) + goto ERROR1; + + if ((res = psiconv_pixel_data_to_bytes(config,&bytes,value->xsize,value->ysize, + ints,config->colordepth))) + goto ERROR2; + + + encoding = 0x00; + if ((res = psiconv_encode_rle8(config,bytes,&bytes_rle))) + goto ERROR3; + if (psiconv_list_length(bytes_rle) < psiconv_list_length(bytes)) { + encoding = 0x01; + psiconv_list_free(bytes); + bytes = bytes_rle; + } else { + bytes_rle = NULL; + } + + if ((res = psiconv_write_u32(config,buf, + 0x28+psiconv_list_length(bytes)))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,0x28))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,value->xsize))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,value->ysize))) + goto ERROR3; + if ((res = psiconv_write_length(config,buf,value->pic_xsize))) + goto ERROR3; + if ((res = psiconv_write_length(config,buf,value->pic_ysize))) + goto ERROR3; + colordepth = config->colordepth; + if ((colordepth != 2) && colordepth != 4) + colordepth = 2; + if ((res = psiconv_write_u32(config,buf,colordepth))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,(config->color?1:0)))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,0))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,encoding))) + goto ERROR3; + if (is_clipart) { + if ((res = psiconv_write_u32(config,buf,0xffffffff))) + goto ERROR3; + if ((res = psiconv_write_u32(config,buf,0x00000044))) + goto ERROR3; + } + for (i = 0; i < psiconv_list_length(bytes); i++) { + if (!(byteptr = psiconv_list_get(bytes,i))) + goto ERROR3; + if ((res = psiconv_write_u8(config,buf,*byteptr))) + goto ERROR3; + } + +ERROR3: + psiconv_list_free(bytes); +ERROR2: + psiconv_list_free(ints); +ERROR1: + return res; +} + +/* Translate the floating point RGB information into pixel values. + The palet is optional; without it, we just use the + colordepth. With a large palet this is not very fast, but it will do for + now. For greyscale pictures, just use the palet. */ +int psiconv_collect_pixel_data(psiconv_pixel_ints *pixels,int xsize,int ysize, + const psiconv_pixel_floats_t data, + int colordepth, + const psiconv_pixel_floats_t palet) +{ + int res,x,y,i; + psiconv_u32 index,pixel; + float p_red,p_green,p_blue,mult,dist,new_dist; + + if (!(*pixels = psiconv_list_new(sizeof(psiconv_u32)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + mult = 1 << colordepth; + for (y = 0; y < ysize; y++) { + for (x = 0; x < xsize; x++) { + index = y*xsize+x; + p_red = data.red[index]; + p_green = data.green[index]; + p_blue = data.blue[index]; + if (!palet.length) { + pixel = (((psiconv_u32) (p_red*mult+0.5)) << (2*colordepth)) + + (((psiconv_u32) (p_green*mult+0.5)) << colordepth) + + ((psiconv_u32) (p_blue*mult+0.5)); + } else { + dist = 4; /* Max distance is 3, so this is safe */ + pixel = -1; + for (i = 0; i < palet.length; i++) { + new_dist = (p_red - palet.red[i]) * (p_red - palet.red[i]) + + (p_green - palet.green[i]) * (p_green - palet.green[i]) + + (p_blue - palet.blue[i]) * (p_blue - palet.blue[i]); + if (new_dist < dist) { + pixel = i; + dist = new_dist; + } + } + } + if ((res = psiconv_list_add(*pixels,&pixel))) + goto ERROR2; + } + } + return 0; + +ERROR2: + psiconv_list_free(*pixels); +ERROR1: + return res; +} + +int psiconv_pixel_data_to_bytes(const psiconv_config config, + psiconv_pixel_bytes *bytes, int xsize, + int ysize, const psiconv_pixel_ints pixels, + int colordepth) +{ + int res; + int x,y; + + psiconv_u32 inputdata; + psiconv_u8 outputbyte; + psiconv_u32 *pixelptr; + int inputbitsleft,outputbitnr,bitsfit,outputbytenr; + + + if (!bytes) { + psiconv_warn(config,0,0,"NULL pixel data"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + if (!pixels) { + psiconv_warn(config,0,0,"NULL pixel data"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + if (psiconv_list_length(pixels) != xsize * ysize) { + psiconv_warn(config,0,0,"Pixel number is not correct"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + if (!(*bytes = psiconv_list_new(sizeof(psiconv_u8)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + + outputbitnr = 0; + outputbyte = 0; + for (y = 0; y < ysize; y++) { + outputbytenr = 0; + for (x = 0; x < xsize; x++) { + if (!(pixelptr = psiconv_list_get(pixels,y*xsize+x))) { + psiconv_warn(config,0,0,"Massive internal corruption"); + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + inputbitsleft = colordepth; + inputdata = *pixelptr; + while (inputbitsleft) { + bitsfit = (inputbitsleft+outputbitnr<=8?inputbitsleft:8-outputbitnr); + outputbyte |= (inputdata & ((1 << bitsfit) - 1)) << outputbitnr; + inputdata = inputdata >> bitsfit; + inputbitsleft -= bitsfit; + outputbitnr += bitsfit; + if (outputbitnr == 8) { + if ((res = psiconv_list_add(*bytes,&outputbyte))) + goto ERROR2; + outputbitnr = 0; + outputbyte = 0; + outputbytenr ++; + } + } + } + /* Always end lines on a long border */ + if (outputbitnr != 0) { + if ((res = psiconv_list_add(*bytes,&outputbyte))) + goto ERROR2; + outputbitnr = 0; + outputbyte = 0; + outputbytenr ++; + } + + while (outputbytenr % 0x04) { + if ((res = psiconv_list_add(*bytes,&outputbyte))) + goto ERROR2; + outputbytenr ++; + } + } + + return 0; + +ERROR2: + psiconv_list_free(*bytes); +ERROR1: + return res; +} + +int psiconv_encode_rle8(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes) +{ + int res,i,j,len; + psiconv_u8 *entry,*next; + psiconv_u8 temp; + + if (!(*encoded_bytes = psiconv_list_new(sizeof(*entry)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + for (i = 0; i < psiconv_list_length(plain_bytes);) { + if (!(entry = psiconv_list_get(plain_bytes,i))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next = psiconv_list_get(plain_bytes,i+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (i == psiconv_list_length(plain_bytes) - 2) { + temp = 0xfe; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next))) + goto ERROR2; + i +=2; + } else if (*next == *entry) { + len = 0; + while ((*next == *entry) && + (i+len + 1 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + if (!(next = psiconv_list_get(plain_bytes,i+len))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + temp = len - 1; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry))) + goto ERROR2; + i += len; + } else { + len = 1; + while ((*next != *entry) && + (i+len+1 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + entry = next; + if (!(next = psiconv_list_get(plain_bytes,i+len))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + len --; + temp = 0x100 - len; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + for (j = 0; j < len; j++) { + if (!(next = psiconv_list_get(plain_bytes,i+j))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if ((res = psiconv_list_add(*encoded_bytes,next))) + goto ERROR2; + } + i += len; + } + } + return 0; + +ERROR2: + psiconv_list_free(*encoded_bytes); +ERROR1: + return res; +} + +int psiconv_encode_rle16(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes) +{ + int res,i,j,len; + psiconv_u8 *entry1,*entry2,*next1,*next2; + psiconv_u8 temp; + + if (!(*encoded_bytes = psiconv_list_new(sizeof(*entry1)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + for (i = 0; i < psiconv_list_length(plain_bytes);) { + if (!(entry1 = psiconv_list_get(plain_bytes,i))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(entry2 = psiconv_list_get(plain_bytes,i+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next1 = psiconv_list_get(plain_bytes,i+2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+3))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (i == psiconv_list_length(plain_bytes) - 4) { + temp = 0xfe; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry2))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next2))) + goto ERROR2; + i +=4; + } else if ((*next1 == *entry1) && (*next2 == *entry2)) { + len = 0; + while (((*next1 == *entry1) && (*next2 == *entry2)) && + (i+2*len + 4 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + if (!(next1 = psiconv_list_get(plain_bytes,i+len*2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+len*2+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + temp = len - 1; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry2))) + goto ERROR2; + i += len*2; + } else { + len = 1; + while (((*next1 != *entry1) || (*next2 != *entry2))&& + (i+len*2+4 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + entry1 = next1; + entry2 = next2; + if (!(next1 = psiconv_list_get(plain_bytes,i+len*2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+len*2+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + len --; + temp = 0x100 - len; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + for (j = 0; j < len; j++) { + if (!(next1 = psiconv_list_get(plain_bytes,i+j*2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+j*2+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if ((res = psiconv_list_add(*encoded_bytes,next1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next2))) + goto ERROR2; + } + i += len*2; + } + } + return 0; + +ERROR2: + psiconv_list_free(*encoded_bytes); +ERROR1: + return res; +} + +int psiconv_encode_rle24(const psiconv_config config, + const psiconv_pixel_bytes plain_bytes, + psiconv_pixel_bytes *encoded_bytes) +{ + int res,i,j,len; + psiconv_u8 *entry1,*entry2,*entry3,*next1,*next2,*next3; + psiconv_u8 temp; + + if (!(*encoded_bytes = psiconv_list_new(sizeof(*entry1)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + for (i = 0; i < psiconv_list_length(plain_bytes);) { + if (!(entry1 = psiconv_list_get(plain_bytes,i))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(entry2 = psiconv_list_get(plain_bytes,i+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(entry3 = psiconv_list_get(plain_bytes,i+2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next1 = psiconv_list_get(plain_bytes,i+3))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+4))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next3 = psiconv_list_get(plain_bytes,i+5))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (i == psiconv_list_length(plain_bytes) - 6) { + temp = 0xfe; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry2))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry3))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next2))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next3))) + goto ERROR2; + i +=4; + } else if ((*next1 == *entry1) && (*next2 == *entry2) && + (*next3 == *entry3)) { + len = 0; + while (((*next1 == *entry1) && (*next2 == *entry2) && + (*next3 == *entry3)) && + (i+3*len + 6 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + if (!(next1 = psiconv_list_get(plain_bytes,i+len*3))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+len*3+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next3 = psiconv_list_get(plain_bytes,i+len*3+2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + temp = len - 1; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry2))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,entry3))) + goto ERROR2; + i += len*3; + } else { + len = 1; + while (((*next1 != *entry1) || (*next2 != *entry2) || + (*next3 != *entry3)) && + (i+len*3+6 < psiconv_list_length(plain_bytes)) && + len < 0x80) { + len ++; + entry1 = next1; + entry2 = next2; + entry3 = next3; + if (!(next1 = psiconv_list_get(plain_bytes,i+len*3))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+len*3+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next3 = psiconv_list_get(plain_bytes,i+len*3+2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + } + len --; + temp = 0x100 - len; + if ((res = psiconv_list_add(*encoded_bytes,&temp))) + goto ERROR2; + for (j = 0; j < len; j++) { + if (!(next1 = psiconv_list_get(plain_bytes,i+j*3))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+j*3+1))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if (!(next2 = psiconv_list_get(plain_bytes,i+j*3+2))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + if ((res = psiconv_list_add(*encoded_bytes,next1))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next2))) + goto ERROR2; + if ((res = psiconv_list_add(*encoded_bytes,next3))) + goto ERROR2; + } + i += len*3; + } + } + return 0; + +ERROR2: + psiconv_list_free(*encoded_bytes); +ERROR1: + return res; +} + + +int psiconv_write_sketch_section(const psiconv_config config, + psiconv_buffer buf, + const psiconv_sketch_section value) +{ + int res; + + if (!value) { + psiconv_warn(config,0,0,"NULL sketch section"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + if ((res = psiconv_write_u16(config,buf,value->displayed_xsize))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->displayed_ysize))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->picture_data_x_offset))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->picture_data_y_offset))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->displayed_size_x_offset))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->displayed_size_y_offset))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->form_xsize))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->form_ysize))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,0x0000))) + goto ERROR1; + if ((res = psiconv_write_paint_data_section(config,buf,value->picture,0))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->magnification_x * 0x03e8))) + goto ERROR1; + if ((res = psiconv_write_u16(config,buf,value->magnification_y * 0x03e8))) + goto ERROR1; + if ((res = psiconv_write_u32(config,buf,value->cut_left * 0x0c * + value->displayed_xsize))) + goto ERROR1; + if ((res = psiconv_write_u32(config,buf,value->cut_right * 0x0c * + value->displayed_xsize))) + goto ERROR1; + if ((res = psiconv_write_u32(config,buf,value->cut_top * 0x0c * + value->displayed_ysize))) + goto ERROR1; + if ((res = psiconv_write_u32(config,buf,value->cut_bottom * 0x0c * + value->displayed_ysize))) + goto ERROR1; + +ERROR1: + return res; +} + +int psiconv_write_clipart_section(const psiconv_config config, + psiconv_buffer buf, + const psiconv_clipart_section value) +{ + int res; + + + if (!value) { + psiconv_warn(config,0,psiconv_buffer_length(buf), + "NULL Clipart Section"); + res = -PSICONV_E_GENERATE; + goto ERROR; + } + if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART_ITEM))) + goto ERROR; + if ((res = psiconv_write_u32(config,buf,0x00000002))) + goto ERROR; + if ((res = psiconv_write_u32(config,buf,0x00000000))) + goto ERROR; + if ((res = psiconv_write_u32(config,buf,0x00000000))) + goto ERROR; + if ((res = psiconv_write_u32(config,buf,0x0000000C))) + goto ERROR; + if ((res = psiconv_write_paint_data_section(config,buf,value->picture,1))) + goto ERROR; + +ERROR: + return res; +} + +int psiconv_write_jumptable_section(const psiconv_config config, + psiconv_buffer buf, + const psiconv_jumptable_section value) +{ + int res,i; + psiconv_u32 *offset_ptr; + + + if (!value) { + psiconv_warn(config,0,psiconv_buffer_length(buf), + "NULL Jumptable Section"); + res = -PSICONV_E_GENERATE; + goto ERROR; + } + if ((res = psiconv_write_u32(config,buf,psiconv_list_length(value)))) + goto ERROR; + for (i = 0; i < psiconv_list_length(value); i++) { + if (!(offset_ptr = psiconv_list_get(value,i))) { + psiconv_warn(config,0,psiconv_buffer_length(buf), + "Massive memory corruption"); + res = -PSICONV_E_NOMEM; + goto ERROR; + } + if ((res = psiconv_write_offset(config,buf,*offset_ptr))) + goto ERROR; + } + +ERROR: + return res; +}