xp_comm_proj/rd_dicom/Papyrus3/JpegDir/JpgLless/pmreadoptimise.c
/*
 *--------------------------------------------------------------
 *
 * PmRead --
 *
 *		        Read the source image file pointed by inFile.
 *
 * Results:
 *		Source image parameters such as width, height, sample
 *		        precision and number of color components are passed
 *		        out by enInfo.
 *
 * Side effects:
 *		        Source image is read into mcuTable, input image size
 *		        is counted in inputFileBytes.
 *
 *--------------------------------------------------------------
 */
PmRead
Read the source image file pointed by inFile.

Source image parameters such as width, height, sample
precision and number of color components are passed
out by enInfo.

Side effects:
Source image is read into mcuTable, input image size
is counted in inputFileBytes.
PmRead Read the source image file pointed by inFile . Source image parameters such as width height sample precision and number of color components are passed out by enInfo . Side effects : Source image is read into mcuTable input image size is counted in inputFileBytes .
void
PmRead (CompressInfo *enInfo, int optimi)
{
	int 				maxMcu;
	JpegComponentInfo 	*compPtr;
	int 				ci, i, j, c;
	MCU					mcu;
	inputFileBytes=0;
	enInfo->numComponents = 1; 
	enInfo->compInfo = (JpegComponentInfo *) emalloc3 (enInfo->numComponents * sizeof (JpegComponentInfo));
	for (ci = 0; ci < enInfo->numComponents; ci++) 
	{
		compPtr = &(enInfo->compInfo[ci]);
		compPtr->componentId = ci;
		compPtr->componentIndex = ci;
		compPtr->hSampFactor = 1;
		compPtr->vSampFactor = 1;
	}
	enInfo->compsInScan = enInfo->numComponents;
	for (ci = 0; ci < enInfo->compsInScan; ci++) 
	{ 
		enInfo->curCompInfo[ci] = &(enInfo->compInfo[ci]);
	}
	if (enInfo->compsInScan == 1) { enInfo->MCUmembership [0] = 0; } 
	else 
	{
		if (enInfo->compsInScan > 4) 
		{ 
		  return; 
		}
		for (ci = 0; ci < enInfo->compsInScan; ci++) 
		{ 
			enInfo->MCUmembership [ci] = ci;
		}
	}  
    numMCU = 0;
    readimBufferOffset = 0;
	maxMcu = enInfo->imageWidth * enInfo->imageHeight; 
	inputFileBytes = 0; 
	if (optimi == 1)
	{
		InitMcuTable (maxMcu, enInfo->compsInScan);
		for (i = 0; i < maxMcu; i++) 
		{
			mcu = MakeMCU ();
			for (j = 0; j < enInfo->compsInScan; j++) 
			{ 
			  if (enInfo->dataPrecision == 8) 
			    mcu [j] = (Ushort)  readimBuffer [readimBufferOffset++]; 
			  else 
			    mcu [j] = (Ushort) readim16Buffer [readimBufferOffset++];
        c = (int)mcu [j];  
			  if ( c == EOF ) { return; }	
			  if (enInfo->Pt != 0) { mcu[j] >>= enInfo->Pt; }
			} 
		} 
	} 
    if (enInfo->dataPrecision == 8) 
      inputFileBytes += maxMcu * enInfo->compsInScan;
    else 
      inputFileBytes += maxMcu * enInfo->compsInScan * 2;
}
void PmRead ( CompressInfo * enInfo , int optimi ) { int maxMcu ; JpegComponentInfo * compPtr ; int ci , i , j , c ; MCU mcu ; inputFileBytes = 0 ; enInfo -> numComponents = 1 ; enInfo -> compInfo = ( JpegComponentInfo * ) emalloc3 ( enInfo -> numComponents * sizeof ( JpegComponentInfo ) ) ; for ( ci = 0 ; ci < enInfo -> numComponents ; ci ++ ) { compPtr = & ( enInfo -> compInfo [ ci ] ) ; compPtr -> componentId = ci ; compPtr -> componentIndex = ci ; compPtr -> hSampFactor = 1 ; compPtr -> vSampFactor = 1 ; } enInfo -> compsInScan = enInfo -> numComponents ; for ( ci = 0 ; ci < enInfo -> compsInScan ; ci ++ ) { enInfo -> curCompInfo [ ci ] = & ( enInfo -> compInfo [ ci ] ) ; } if ( enInfo -> compsInScan == 1 ) { enInfo -> MCUmembership [ 0 ] = 0 ; } else { if ( enInfo -> compsInScan > 4 ) { return ; } for ( ci = 0 ; ci < enInfo -> compsInScan ; ci ++ ) { enInfo -> MCUmembership [ ci ] = ci ; } } numMCU = 0 ; readimBufferOffset = 0 ; maxMcu = enInfo -> imageWidth * enInfo -> imageHeight ; inputFileBytes = 0 ; if ( optimi == 1 ) { InitMcuTable ( maxMcu , enInfo -> compsInScan ) ; for ( i = 0 ; i < maxMcu ; i ++ ) { mcu = MakeMCU ( ) ; for ( j = 0 ; j < enInfo -> compsInScan ; j ++ ) { if ( enInfo -> dataPrecision == 8 ) mcu [ j ] = ( Ushort ) readimBuffer [ readimBufferOffset ++ ] ; else mcu [ j ] = ( Ushort ) readim16Buffer [ readimBufferOffset ++ ] ; c = ( int ) mcu [ j ] ; if ( c == EOF ) { return ; } if ( enInfo -> Pt != 0 ) { mcu [ j ] >>= enInfo -> Pt ; } } } } if ( enInfo -> dataPrecision == 8 ) inputFileBytes += maxMcu * enInfo -> compsInScan ; else inputFileBytes += maxMcu * enInfo -> compsInScan * 2 ; }
PmRead
                      Read the source image file pointed by inFile.
PmRead Read the source image file pointed by inFile .
/*
		* Initialize inputFileBytes to 2 bytes since magic number is 2 bytes. 
		* Read magic number, cols, rows, and max color level. Convert the
		* color level to precision bits.
		*/ /* Be careful: image must be grayscale */ /*
		* Because JPEG standard (DIS) defined downsampling, in our 
      	* CompressInfo structure, we have sampling factor and an 
      	* index array MCUmembership, in case a MCU contains several 
    	* samples of one color component. But in lossless JPEG, one 
        * normally don't use downsampling.
		*/ /*
		* Set curCompInfo equal to compInfo since these is only 
		* one scan.
		*/ /*
	 * Prepare array indexing MCU components into curCompInfo. 
	 */ /* MAL exit(-1); */ /* else */ /*
		* Alloc mcuTable. Read source image into the table.
		* Apply point transform if Pt!=0. Update the input 
		* file size - inputFileBytes.
		*/ /* really needed some initialization of these @!?! global variables ... */ /* if the psv optimisation is enabled, mcu is loaded */ /* unix compatibility */ /* end for j */ /* end for i */ /* end if optimi */