- if (png_ptr->offset_table == NULL)
- {
- /* try to see if we need to do any of this fancy stuff */
- ret = farmalloc(size);
- if (ret == NULL || ((png_size_t)ret & 0xffff))
- {
- int num_blocks;
- png_uint_32 total_size;
- png_bytep table;
- int i;
- png_byte huge * hptr;
-
- if (ret != NULL)
- {
- farfree(ret);
- ret = NULL;
- }
-
- num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
- if (num_blocks < 1)
- num_blocks = 1;
- if (png_ptr->zlib_mem_level >= 7)
- num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
- else
- num_blocks++;
-
- total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
-
- table = farmalloc(total_size);
-
- if (table == NULL)
- {
- png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
- }
-
- if ((png_size_t)table & 0xfff0)
- {
- png_error(png_ptr, "Farmalloc didn't return normalized pointer");
- }
-
- png_ptr->offset_table = table;
- png_ptr->offset_table_ptr = farmalloc(num_blocks *
- sizeof (png_bytep));
-
- if (png_ptr->offset_table_ptr == NULL)
- {
- png_error(png_ptr, "Out Of memory.");
- }
-
- hptr = (png_byte huge *)table;
- if ((png_size_t)hptr & 0xf)
- {
- hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
- hptr += 16L;
- }
- for (i = 0; i < num_blocks; i++)
- {
- png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
- hptr += (png_uint_32)65536L;
- }
-
- png_ptr->offset_table_number = num_blocks;
- png_ptr->offset_table_count = 0;
- png_ptr->offset_table_count_free = 0;
- }
- }
-
- if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
- png_error(png_ptr, "Out of Memory.");