386 * To minimize allocation overhead and to allow I/O of large contiguous 387 * blocks, we allocate the sample rows in groups of as many rows as possible 388 * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request. 389 * NB: the virtual array control routines, later in this file, know about 390 * this chunking of rows. The rowsperchunk value is left in the mem manager 391 * object so that it can be saved away if this sarray is the workspace for 392 * a virtual array. 393 */ 394 395 METHODDEF(JSAMPARRAY) 396 alloc_sarray (j_common_ptr cinfo, int pool_id, 397 JDIMENSION samplesperrow, JDIMENSION numrows) 398 /* Allocate a 2-D sample array */ 399 { 400 my_mem_ptr mem = (my_mem_ptr) cinfo->mem; 401 JSAMPARRAY result; 402 JSAMPROW workspace; 403 JDIMENSION rowsperchunk, currow, i; 404 long ltemp; 405 406 /* Calculate max # of rows allowed in one allocation chunk */ 407 ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / 408 ((long) samplesperrow * SIZEOF(JSAMPLE)); 409 if (ltemp <= 0) 410 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 411 if (ltemp < (long) numrows) 412 rowsperchunk = (JDIMENSION) ltemp; 413 else 414 rowsperchunk = numrows; 415 mem->last_rowsperchunk = rowsperchunk; 416 417 /* Get space for row pointers (small object) */ 418 result = (JSAMPARRAY) alloc_small(cinfo, pool_id, 419 (size_t) (numrows * SIZEOF(JSAMPROW))); 420 421 /* Get the rows themselves (large objects) */ 422 currow = 0; 423 while (currow < numrows) { 424 rowsperchunk = MIN(rowsperchunk, numrows - currow); 425 workspace = (JSAMPROW) alloc_large(cinfo, pool_id, 433 434 return result; 435 } 436 437 438 /* 439 * Creation of 2-D coefficient-block arrays. 440 * This is essentially the same as the code for sample arrays, above. 441 */ 442 443 METHODDEF(JBLOCKARRAY) 444 alloc_barray (j_common_ptr cinfo, int pool_id, 445 JDIMENSION blocksperrow, JDIMENSION numrows) 446 /* Allocate a 2-D coefficient-block array */ 447 { 448 my_mem_ptr mem = (my_mem_ptr) cinfo->mem; 449 JBLOCKARRAY result; 450 JBLOCKROW workspace; 451 JDIMENSION rowsperchunk, currow, i; 452 long ltemp; 453 454 /* Calculate max # of rows allowed in one allocation chunk */ 455 ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / 456 ((long) blocksperrow * SIZEOF(JBLOCK)); 457 if (ltemp <= 0) 458 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 459 if (ltemp < (long) numrows) 460 rowsperchunk = (JDIMENSION) ltemp; 461 else 462 rowsperchunk = numrows; 463 mem->last_rowsperchunk = rowsperchunk; 464 465 /* Get space for row pointers (small object) */ 466 result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, 467 (size_t) (numrows * SIZEOF(JBLOCKROW))); 468 469 /* Get the rows themselves (large objects) */ 470 currow = 0; 471 while (currow < numrows) { 472 rowsperchunk = MIN(rowsperchunk, numrows - currow); | 386 * To minimize allocation overhead and to allow I/O of large contiguous 387 * blocks, we allocate the sample rows in groups of as many rows as possible 388 * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request. 389 * NB: the virtual array control routines, later in this file, know about 390 * this chunking of rows. The rowsperchunk value is left in the mem manager 391 * object so that it can be saved away if this sarray is the workspace for 392 * a virtual array. 393 */ 394 395 METHODDEF(JSAMPARRAY) 396 alloc_sarray (j_common_ptr cinfo, int pool_id, 397 JDIMENSION samplesperrow, JDIMENSION numrows) 398 /* Allocate a 2-D sample array */ 399 { 400 my_mem_ptr mem = (my_mem_ptr) cinfo->mem; 401 JSAMPARRAY result; 402 JSAMPROW workspace; 403 JDIMENSION rowsperchunk, currow, i; 404 long ltemp; 405 406 if (samplesperrow == 0) { 407 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 408 } 409 410 /* Calculate max # of rows allowed in one allocation chunk */ 411 ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / 412 ((long) samplesperrow * SIZEOF(JSAMPLE)); 413 if (ltemp <= 0) 414 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 415 if (ltemp < (long) numrows) 416 rowsperchunk = (JDIMENSION) ltemp; 417 else 418 rowsperchunk = numrows; 419 mem->last_rowsperchunk = rowsperchunk; 420 421 /* Get space for row pointers (small object) */ 422 result = (JSAMPARRAY) alloc_small(cinfo, pool_id, 423 (size_t) (numrows * SIZEOF(JSAMPROW))); 424 425 /* Get the rows themselves (large objects) */ 426 currow = 0; 427 while (currow < numrows) { 428 rowsperchunk = MIN(rowsperchunk, numrows - currow); 429 workspace = (JSAMPROW) alloc_large(cinfo, pool_id, 437 438 return result; 439 } 440 441 442 /* 443 * Creation of 2-D coefficient-block arrays. 444 * This is essentially the same as the code for sample arrays, above. 445 */ 446 447 METHODDEF(JBLOCKARRAY) 448 alloc_barray (j_common_ptr cinfo, int pool_id, 449 JDIMENSION blocksperrow, JDIMENSION numrows) 450 /* Allocate a 2-D coefficient-block array */ 451 { 452 my_mem_ptr mem = (my_mem_ptr) cinfo->mem; 453 JBLOCKARRAY result; 454 JBLOCKROW workspace; 455 JDIMENSION rowsperchunk, currow, i; 456 long ltemp; 457 458 if (blocksperrow == 0) { 459 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 460 } 461 462 /* Calculate max # of rows allowed in one allocation chunk */ 463 ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / 464 ((long) blocksperrow * SIZEOF(JBLOCK)); 465 if (ltemp <= 0) 466 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 467 if (ltemp < (long) numrows) 468 rowsperchunk = (JDIMENSION) ltemp; 469 else 470 rowsperchunk = numrows; 471 mem->last_rowsperchunk = rowsperchunk; 472 473 /* Get space for row pointers (small object) */ 474 result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, 475 (size_t) (numrows * SIZEOF(JBLOCKROW))); 476 477 /* Get the rows themselves (large objects) */ 478 currow = 0; 479 while (currow < numrows) { 480 rowsperchunk = MIN(rowsperchunk, numrows - currow); |