diff options
Diffstat (limited to 'converter/other/pdbimgtopam.c')
-rw-r--r-- | converter/other/pdbimgtopam.c | 127 |
1 files changed, 61 insertions, 66 deletions
diff --git a/converter/other/pdbimgtopam.c b/converter/other/pdbimgtopam.c index 67044109..b191644f 100644 --- a/converter/other/pdbimgtopam.c +++ b/converter/other/pdbimgtopam.c @@ -56,7 +56,7 @@ parseCommandLine(int argc, const char ** argv, struct cmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- parse program command line described in Unix standard form by argc - and argv. Return the information in the options as *cmdlineP. + and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. @@ -90,7 +90,7 @@ parseCommandLine(int argc, const char ** argv, if (!notefileSpec) cmdlineP->notefile = NULL; - + if (argc-1 < 1) cmdlineP->inputFileName = "-"; else if (argc-1 == 1) @@ -152,7 +152,7 @@ decompress(const uint8_t * const compressed, const uint8_t * inP; uint8_t * outP; size_t bytesLeft; - + for (bytesLeft = imageSize, inP = &compressed[0], outP = &uncompressed[0]; bytesLeft > 0; @@ -224,7 +224,7 @@ readCompressed(IMAGE * const imgP, * this extra byte and ignore it by paying attention to * the image dimensions. */ - size_t const maxCompressedSizeWithBloat = ipdb_img_size(imgP) * 2; + size_t const maxCompressedSizeWithBloat = ipdb_imgSize(imgP) * 2; /* * Provide a buffer large enough for the worst case. * See note in lib/util/runlength.c . @@ -251,7 +251,7 @@ readCompressed(IMAGE * const imgP, * Read to the indicated offset. */ dataSize = end_offset - ftell(fP) + 1; - + MALLOCARRAY(buffer, dataSize); if (buffer == NULL) @@ -306,9 +306,9 @@ imageReadHeader(FILE * const fileP, pm_message(" Y_anchor: %u", imgP->y_anchor); pm_message(" Width: %u", imgP->width); pm_message(" Height: %u", imgP->height); - pm_message("Pixels per byte: %u", ipdb_img_ppb(imgP)); + pm_message("Pixels per byte: %u", ipdb_imgPpb(imgP)); pm_message("Image size: %lu bytes", - (unsigned long)ipdb_img_size(imgP)); + (unsigned long)ipdb_imgSize(imgP)); } } @@ -318,7 +318,7 @@ imageReadData(FILE * const fileP, IMAGE * const imgP, uint32_t const end_offset) { - size_t const imageSize = ipdb_img_size(imgP); + size_t const imageSize = ipdb_imgSize(imgP); int retval; size_t dataSize; @@ -390,7 +390,7 @@ textRead(TEXT * const textP, return 0; textP->r->offset = (uint32_t)ftell(fileP); - + /* * What a pain in the ass! Why the hell isn't there a length * attached to the text record? I suppose the designer wasn't @@ -453,7 +453,7 @@ pdbheadRead(PDBHEAD * const pdbHeadP, pm_readbiglongu2(fileP, &pdbHeadP->next_rec); pm_readbigshortu(fileP, &pdbHeadP->num_recs); - if (!memeq(pdbHeadP->type, IPDB_vIMG, 4) + if (!memeq(pdbHeadP->type, IPDB_vIMG, 4) || !memeq(pdbHeadP->id, IPDB_View, 4)) retval = E_NOTIMAGE; else @@ -531,62 +531,54 @@ ipdbRead(IPDB * const pdbP, int retval; - ipdb_clear(pdbP); + int status; - pdbP->p = ipdb_pdbhead_alloc(NULL); + status = pdbheadRead(pdbP->p, fileP); - if (pdbP->p == NULL) - retval = ENOMEM; + if (status != 0) + retval = status; else { - int status; - - status = pdbheadRead(pdbP->p, fileP); - - if (status != 0) - retval = status; + pdbP->i = ipdb_imageCreate(pdbP->p->name, IMG_GRAY, 0, 0); + if (pdbP->i == NULL) + retval = ENOMEM; else { - pdbP->i = ipdb_image_alloc(pdbP->p->name, IMG_GRAY, 0, 0); - if (pdbP->i == NULL) - retval = ENOMEM; + int status; + status = rechdrRead(pdbP->i->r, fileP); + if (status != 0) + retval = status; else { - int status; - status = rechdrRead(pdbP->i->r, fileP); - if (status != 0) - retval = status; - else { - if (pdbP->p->num_recs > 1) { - pdbP->t = ipdb_text_alloc(NULL); - if (pdbP->t == NULL) - retval = ENOMEM; - else { - int status; - status = rechdrRead(pdbP->t->r, fileP); - if (status != 0) - retval = status; - else - retval = 0; - } - } else - retval = 0; - - if (retval == 0) { - uint32_t const offset = - pdbP->t == NULL ? - UNKNOWN_OFFSET : pdbP->t->r->offset - 1; - + if (pdbP->p->num_recs > 1) { + pdbP->t = ipdb_textAlloc(); + if (pdbP->t == NULL) + retval = ENOMEM; + else { int status; - - status = imageRead(pdbP->i, offset, fileP, verbose); + status = rechdrRead(pdbP->t->r, fileP); if (status != 0) retval = status; - else { - if (pdbP->t != NULL) { - int status; - - status = textRead(pdbP->t, fileP); - if (status != 0) - retval = status; - } + else + retval = 0; + } + } else + retval = 0; + + if (retval == 0) { + uint32_t const offset = + pdbP->t == NULL ? + UNKNOWN_OFFSET : pdbP->t->r->offset - 1; + + int status; + + status = imageRead(pdbP->i, offset, fileP, verbose); + if (status != 0) + retval = status; + else { + if (pdbP->t != NULL) { + int status; + + status = textRead(pdbP->t, fileP); + if (status != 0) + retval = status; } } } @@ -663,8 +655,8 @@ static void g16row(IPDB * const pdbP, unsigned int const row, uint8_t * const buffer) { - - g16unpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP)); + + g16unpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP)); } @@ -674,7 +666,7 @@ grow(IPDB * const pdbP, unsigned int const row, uint8_t * const buffer) { - gunpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP)); + gunpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP)); } @@ -684,7 +676,7 @@ mrow(IPDB * const pdbP, unsigned int const row, uint8_t * const buffer) { - munpack(ipdb_img_row(pdbP->i, row), buffer, ipdb_width(pdbP)); + munpack(ipdb_imgRow(pdbP->i, row), buffer, ipdb_width(pdbP)); } @@ -715,7 +707,7 @@ writeImgPam(IPDB * const pdbP, PAM_PBM_TUPLETYPE : PAM_PGM_TUPLETYPE); pnm_writepaminit(&pam); - + tupleRow = pnm_allocpamrow(&pam); for (row = 0; row < pam.height; ++row) { @@ -731,7 +723,7 @@ writeImgPam(IPDB * const pdbP, for (col = 0; col < pam.width; ++col) tupleRow[col][0] = imgRow[col]; - + pnm_writepamrow(&pam, tupleRow); } pnm_freepamrow(tupleRow); @@ -754,7 +746,7 @@ writeText(IPDB * const pdbP, fP = pm_openw(name); if (fP == NULL) pm_error("Could not open note file '%s' for output", name); - + fprintf(fP, "%s\n", note); pm_close(fP); @@ -777,7 +769,7 @@ main(int argc, const char ** argv) { ifP = pm_openr(cmdline.inputFileName); - pdbP = ipdb_alloc(NULL); + pdbP = ipdb_alloc(); if (pdbP == NULL) pm_error("Could not allocate IPDB structure."); @@ -795,3 +787,6 @@ main(int argc, const char ** argv) { return EXIT_SUCCESS; } + + + |