static void CharAE_extend(CharAE *ae, int new_buflength) { int old_buflength; old_buflength = ae->_buflength; if (new_buflength == -1) new_buflength = _get_new_buflength(old_buflength); ae->elts = (char *) realloc2(ae->elts, new_buflength, old_buflength, sizeof(char)); ae->_buflength = new_buflength; return; }
static void LLongAE_extend(LLongAE *ae, int new_buflength) { int old_buflength; old_buflength = ae->_buflength; if (new_buflength == -1) new_buflength = _get_new_buflength(old_buflength); ae->elts = (long long *) realloc2(ae->elts, new_buflength, old_buflength, sizeof(long long)); ae->_buflength = new_buflength; return; }
static void IntPairAEAE_extend(IntPairAEAE *aeae, int new_buflength) { int old_buflength, i; old_buflength = aeae->_buflength; if (new_buflength == -1) new_buflength = _get_new_buflength(old_buflength); aeae->elts = (IntPairAE **) realloc2(aeae->elts, new_buflength, old_buflength, sizeof(IntPairAE *)); for (i = old_buflength; i < new_buflength; i++) aeae->elts[i] = NULL; aeae->_buflength = new_buflength; return; }
static void addEntryToIcon(MS_Ico const MSIconData, const char * const xorPpmFname, const char * const andPgmFname, bool const trueTransparent) { IC_Entry entry; FILE * xorfile; pixel ** xorPPMarray; gray ** andPGMarray; ICON_bmp xorBitmap; ICON_bmp andBitmap; int rows, cols; int bpp, colors; int entry_cols; IC_Palette palette; colorhash_table xorCht; colorhash_table andCht; const char * error; pixval xorMaxval; gray andMaxval; MALLOCVAR_NOFAIL(entry); /* * Read the xor PPM. */ xorfile = pm_openr(xorPpmFname); xorPPMarray = ppm_readppm(xorfile, &cols, &rows, &xorMaxval); pm_close(xorfile); /* * Since the entry uses 1 byte to hold the width and height of the icon, the * image can't be more than 256 x 256. */ if (rows > 255 || cols > 255) { pm_error("Max size for a icon is 255 x 255 (1 byte fields). " "%s is %d x %d", xorPpmFname, cols, rows); } if (verbose) pm_message("read PPM: %dw x %dh, maxval = %d", cols, rows, xorMaxval); makePalette(xorPPMarray, cols, rows, xorMaxval, &palette, &xorCht, &colors, &error); if (error) pm_error("Unable to make palette for '%s'. %s", xorPpmFname, error); /* * All the icons I found seemed to pad the palette to the max entries * for that bitdepth. * * The spec indicates this isn't neccessary, but I'll follow this behaviour * just in case. */ if (colors < 3) { bpp = 1; entry_cols = 2; } else if (colors < 17) { bpp = 4; entry_cols = 16; } else { bpp = 8; entry_cols = 256; } getOrFakeAndMap(andPgmFname, cols, rows, &andPGMarray, &andMaxval, &andCht, &error); if (error) pm_error("Error in and map for '%s'. %s", xorPpmFname, error); if (andPGMarray && trueTransparent) blackenTransparentAreas(xorPPMarray, cols, rows, andPGMarray, andMaxval); xorBitmap = createBitmap(bpp, xorPPMarray, cols, rows, xorCht); andBitmap = createAndBitmap(andPGMarray, cols, rows, andMaxval); /* * Fill in the entry data fields. */ entry->width = cols; entry->height = rows; entry->color_count = entry_cols; entry->reserved = 0; entry->planes = 1; /* * all the icons I looked at ignored this value... */ entry->bitcount = bpp; entry->ih = createInfoHeader(entry, xorBitmap, andBitmap); entry->colors = palette->colors; overflow2(4, entry->color_count); overflow_add(xorBitmap->size, andBitmap->size); overflow_add(xorBitmap->size + andBitmap->size, 40); overflow_add(xorBitmap->size + andBitmap->size + 40, 4 * entry->color_count); entry->size_in_bytes = xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count); if (verbose) pm_message("entry->size_in_bytes = %d + %d + %d = %d", xorBitmap->size ,andBitmap->size, 40, entry->size_in_bytes ); /* * We don't know the offset ATM, set to 0 for now. * Have to calculate this at the end. */ entry->file_offset = 0; entry->xorBitmapOut = xorBitmap->data; entry->andBitmapOut = andBitmap->data; entry->xBytesXor = xorBitmap->xBytes; entry->xBytesAnd = andBitmap->xBytes; /* * Add the entry to the entries array. */ overflow_add(MSIconData->count,1); MSIconData->count++; /* * Perhaps I should use something that allocs a decent amount at start... */ MSIconData->entries = realloc2 (MSIconData->entries, MSIconData->count * sizeof(IC_Entry *)); MSIconData->entries[MSIconData->count-1] = entry; }