Beispiel #1
0
AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
  ALsizei offset, ALsizei samples,
  ALenum channels, ALenum type, ALvoid *data)
{
    ALCdevice *device;
    ALCcontext *context;
    ALbuffer *albuf;
    ALsizei align;

    context = GetContextRef();
    if(!context) return;

    device = context->Device;
    LockBuffersRead(device);
    if((albuf=LookupBuffer(device, buffer)) == NULL)
        SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
    if(!(samples >= 0 && offset >= 0))
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    if(IsValidType(type) == AL_FALSE)
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);

    ReadLock(&albuf->lock);
    align = ATOMIC_LOAD_SEQ(&albuf->PackAlign);
    if(SanitizeAlignment(type, &align) == AL_FALSE)
    {
        ReadUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    }
    if(channels != (ALenum)albuf->FmtChannels)
    {
        ReadUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
    }
    if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset)
    {
        ReadUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    }
    if((samples%align) != 0)
    {
        ReadUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    }

    /* offset -> byte offset */
    offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType);
    ConvertData(data, type, (char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
                ChannelsFromFmt(albuf->FmtChannels), samples, align);
    ReadUnlock(&albuf->lock);

done:
    UnlockBuffersRead(device);
    ALCcontext_DecRef(context);
}
	void ConvertAllData()
	{
		allDataUE->enabledCount = 0;

		for (int i = 0; i < 4; i++)
		{
			allDataUE->controllers[i] = ConvertData(&allData->controllers[i]);
			if (allDataUE->controllers[i].enabled){
				allDataUE->enabledCount++;
			}
		}
	}
/**
 * @brief UpiRestoreData
 *
 *  Restore data from system to IC routine
 *
 * @para  data  address of BackupDataType
 * @return  BACKUP_BOOL_TRUE if success
 */
_backup_bool_ UpiRestoreData(BackupDataType *data)
{
  _backup_bool_ rtn;
  _backup_u32_ driverVer;
  SystemDataType *orgSysData;
  _backup_s32_ tmp32;

  /// [AT-PM] : Create buffer ; 02/21/2013
  #ifndef UG31XX_SHELL_ALGORITHM
    orgSysData = &CheckBackupFile_orgSysData;
  #else   ///< else of UG31XX_SHELL_ALGORITHM
    orgSysData = (SystemDataType *)upi_malloc(sizeof(SystemDataType));
  #endif  ///< end of UG31XX_SHELL_ALGORITHM
  upi_memcpy(orgSysData, ptrSysData, sizeof(SystemDataType));

  /// [AT-PM] : Get data from file ; 02/21/2013
  #if defined (uG31xx_OS_WINDOWS)
  rtn = read_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize);
  #else  ///< else of defined (uG31xx_OS_WINDOWS)
  rtn = read_backup_file(ptrBackupFileName, data->backupBuffer, data->backupBufferSize);
  #endif ///< end of defined (uG31xx_OS_WINDOWS)
  if(rtn == _UPI_FALSE_)
  {
    UG31_LOGE("[%s]: Read data from backup file fail.\n", __func__);
    #ifdef  UG31XX_SHELL_ALGORITHM
      upi_free(orgSysData);
    #endif  ///< end of UG31XX_SHELL_ALGORITHM
    return (BACKUP_BOOL_FALSE);
  }
  driverVer = ConvertData(data);
  UG31_LOGI("[%s]: Driver version = %d\n", __func__, (int)driverVer);

  /// [AT-PM] : Keep following information ; 01/22/2014
  ptrSysData->timeTagFromIC = orgSysData->timeTagFromIC;
  ptrSysData->tableUpdateIdxFromIC = orgSysData->tableUpdateIdxFromIC;

  /// [AT-PM] : Check abnormal condition ; 01/22/2014
  if((data->backupVolt1 != 0) && (data->backupVolt2 != 0))
  {
    tmp32 = (_backup_s32_)data->backupVolt1;
    tmp32 = tmp32 - data->backupVolt2;
    if((tmp32 < RESTORE_ABNORMAL_VOLT_RANGE_UPBND) && (tmp32 > RESTORE_ABNORMAL_VOLT_RANGE_LWBND))
    {
      ptrSysData->rmFromIC = orgSysData->rmFromIC;
      ptrSysData->fccFromIC = orgSysData->fccFromIC;
      ptrSysData->rsocFromIC = orgSysData->rsocFromIC;
    }
  }
  #ifdef  UG31XX_SHELL_ALGORITHM
    upi_free(orgSysData);
  #endif  ///< end of UG31XX_SHELL_ALGORITHM
  return (BACKUP_BOOL_TRUE);
}
Beispiel #4
0
int CPerlModule::Exec(char *buff, int buff_size, const char *arg, const char *sub_name)
{
#ifdef PAYGUIDE_PERL
	if (broken!=0)
		return -2;
	//char *args[] = { NULL };
	int val=0;
	sem_wait(&lock);


	//call_argv(sub_name, G_DISCARD | G_NOARGS, args);
	val=ConvertData(buff, buff_size, arg, strlen(arg), sub_name);
	sem_post(&lock);
	return val;
#else
	return 0;
#endif
}
Beispiel #5
0
/*
 * LoadData
 *
 * Loads the specified data into the buffer, using the specified formats.
 * Currently, the new format must be 32-bit float, and must have the same
 * channel configuration as the original format. This does NOT handle
 * compressed formats (eg. IMA4).
 */
static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint freq, ALenum OrigFormat, ALenum NewFormat)
{
    ALuint NewBytes = aluBytesFromFormat(NewFormat);
    ALuint NewChannels = aluChannelsFromFormat(NewFormat);
    ALuint OrigBytes = aluBytesFromFormat(OrigFormat);
    ALuint OrigChannels = aluChannelsFromFormat(OrigFormat);
    ALuint64 newsize, allocsize;
    ALvoid *temp;

    assert(NewBytes == 4);
    assert(NewChannels == OrigChannels);

    if ((size%(OrigBytes*OrigChannels)) != 0)
        return AL_INVALID_VALUE;

    // Allocate extra padding samples
    newsize = size / OrigBytes;
    allocsize = (BUFFER_PADDING*NewChannels + newsize)*NewBytes;
    if(allocsize > INT_MAX)
        return AL_OUT_OF_MEMORY;

    temp = realloc(ALBuf->data, allocsize);
    if(!temp) return AL_OUT_OF_MEMORY;
    ALBuf->data = temp;

    // Samples are converted here
    ConvertData(ALBuf->data, data, OrigBytes, newsize);

    ALBuf->format = NewFormat;
    ALBuf->eOriginalFormat = OrigFormat;
    ALBuf->size = newsize*NewBytes;
    ALBuf->frequency = freq;

    ALBuf->LoopStart = 0;
    ALBuf->LoopEnd = newsize / NewChannels;

    ALBuf->OriginalSize = size;
    ALBuf->OriginalAlign = OrigBytes * OrigChannels;

    return AL_NO_ERROR;
}
Beispiel #6
0
/*
 * LoadData
 *
 * Loads the specified data into the buffer, using the specified formats.
 * Currently, the new format must be 16-bit, and must have the same channel
 * configuration as the original format. This does NOT handle compressed
 * formats (eg. IMA4).
 */
static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint freq, ALenum OrigFormat, ALenum NewFormat)
{
    ALuint NewChannels = aluChannelsFromFormat(NewFormat);
    ALuint OrigBytes = aluBytesFromFormat(OrigFormat);
    ALuint OrigChannels = aluChannelsFromFormat(OrigFormat);
    ALsizei padding = 2;
    ALvoid *temp;

    assert(aluBytesFromFormat(NewFormat) == 2);
    assert(NewChannels == OrigChannels);

    if ((size%(OrigBytes*OrigChannels)) != 0)
    {
        alSetError(AL_INVALID_VALUE);
        return;
    }

    // Samples are converted to 16 bit here
    size /= OrigBytes;
    temp = realloc(ALBuf->data, (padding*NewChannels + size) * sizeof(ALshort));
    if(temp)
    {
        ALBuf->data = temp;
        ConvertData(ALBuf->data, data, OrigBytes, size);

        memset(&(ALBuf->data[size]), 0, padding*NewChannels*sizeof(ALshort));

        ALBuf->format = NewFormat;
        ALBuf->eOriginalFormat = OrigFormat;
        ALBuf->size = size*sizeof(ALshort);
        ALBuf->frequency = freq;
        ALBuf->padding = padding;
    }
    else
        alSetError(AL_OUT_OF_MEMORY);
}
JBoolean
JXSelectionData::Convert
	(
	const Atom		requestType,
	Atom*			returnType,
	unsigned char**	data,
	JSize*			dataLength,
	JSize*			bitsPerBlock
	)
	const
{
	JXSelectionManager* selMgr = GetSelectionManager();

	// TARGETS

	if (requestType == selMgr->GetTargetsXAtom())
		{
		const JSize atomCount = itsTypeList->GetElementCount();
		assert( atomCount > 0 );

		*returnType   = XA_ATOM;
		*bitsPerBlock = sizeof(Atom)*8;
		*dataLength   = sizeof(Atom)*atomCount;

		*data = new unsigned char [ *dataLength ];
		if (*data == NULL)
			{
			return kJFalse;
			}

		Atom* atomData = reinterpret_cast<Atom*>(*data);
		for (JIndex i=1; i<=atomCount; i++)
			{
			atomData[i-1] = itsTypeList->GetElement(i);
			}

		return kJTrue;
		}

	// TIMESTAMP

	else if (requestType == selMgr->GetTimeStampXAtom())
		{
		*returnType   = XA_INTEGER;
		*bitsPerBlock = sizeof(Time)*8;
		*dataLength   = sizeof(Time);

		*data = new unsigned char [ *dataLength ];
		if (*data == NULL)
			{
			return kJFalse;
			}

		*(reinterpret_cast<Time*>(*data)) = itsStartTime;

		return kJTrue;
		}

	// everything else

	else
		{
		Resolve();
		return ConvertData(requestType, returnType,
						   data, dataLength, bitsPerBlock);
		}
}
Beispiel #8
0
/*
*    alBufferSubDataEXT(ALuint buffer,ALenum format,ALvoid *data,ALsizei offset,ALsizei length)
*
*    Fill buffer with audio data
*/
ALvoid ALAPIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length)
{
    ALCcontext *Context;
    ALbuffer *ALBuf;

    Context = alcGetCurrentContext();
    SuspendContext(Context);

    if(alIsBuffer(buffer) && buffer != 0)
    {
        ALBuf = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffer);
        if(ALBuf->data == NULL)
        {
            // buffer does not have any data
            alSetError(AL_INVALID_NAME);
        }
        else if(length < 0 || offset < 0 || (length > 0 && data == NULL))
        {
            // data is NULL or offset/length is negative
            alSetError(AL_INVALID_VALUE);
        }
        else
        {
            switch(format)
            {
                case AL_FORMAT_REAR8:
                case AL_FORMAT_REAR16:
                case AL_FORMAT_REAR32: {
                    ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 :
                                        ((format==AL_FORMAT_REAR16) ? 2 :
                                         4));

                    if(ALBuf->eOriginalFormat != AL_FORMAT_REAR8 &&
                       ALBuf->eOriginalFormat != AL_FORMAT_REAR16 &&
                       ALBuf->eOriginalFormat != AL_FORMAT_REAR32)
                    {
                        alSetError(AL_INVALID_ENUM);
                        break;
                    }

                    if(ALBuf->size/4/sizeof(ALshort) < (ALuint)offset+length)
                    {
                        alSetError(AL_INVALID_VALUE);
                        break;
                    }

                    ConvertDataRear(&ALBuf->data[offset*4], data, OrigBytes, length*2);
                }   break;

                case AL_FORMAT_MONO_IMA4:
                case AL_FORMAT_STEREO_IMA4: {
                    int Channels = aluChannelsFromFormat(ALBuf->format);

                    if(ALBuf->eOriginalFormat != format)
                    {
                        alSetError(AL_INVALID_ENUM);
                        break;
                    }

                    if((offset%65) != 0 || (length%65) != 0 ||
                       ALBuf->size/Channels/sizeof(ALshort) < (ALuint)offset+length)
                    {
                        alSetError(AL_INVALID_VALUE);
                        break;
                    }

                    ConvertDataIMA4(&ALBuf->data[offset*Channels], data, Channels, length/65*Channels);
                }   break;

                default: {
                    ALuint Channels = aluChannelsFromFormat(format);
                    ALuint Bytes = aluBytesFromFormat(format);

                    if(Channels != aluChannelsFromFormat(ALBuf->format))
                    {
                        alSetError(AL_INVALID_ENUM);
                        break;
                    }

                    if(ALBuf->size/Channels/sizeof(ALshort) < (ALuint)offset+length)
                    {
                        alSetError(AL_INVALID_VALUE);
                        break;
                    }

                    ConvertData(&ALBuf->data[offset*Channels], data, Bytes, length*Channels);
                }   break;
            }
        }
    }
    else
    {
        // Invalid Buffer Name
        alSetError(AL_INVALID_NAME);
    }

    ProcessContext(Context);
}
/**
 * @brief CheckBackupFile
 *
 *  Check backup file is consisted with IC or not
 *
 * @para  data  address of BackupDataType
 * @return  CHECK_BACKUP_FILE_STS
 */
_backup_u8_ CheckBackupFile(BackupDataType *data)
{
  CapacityDataType *orgCapData;
  SystemDataType *orgSysData;
  _upi_bool_ rtn;
  _backup_u32_ driverVer;
  _backup_u8_ rtnU8;
  _backup_u16_ volt1;
  _backup_u16_ volt2;

  /// [AT-PM] : Create buffer ; 02/21/2013
  #ifndef UG31XX_SHELL_ALGORITHM
    orgCapData = &CheckBackupFile_orgCapData;
    orgSysData = &CheckBackupFile_orgSysData;
  #else   ///< else of UG31XX_SHELL_ALGORITHM
    orgCapData = (CapacityDataType *)upi_malloc(sizeof(CapacityDataType));
    orgSysData = (SystemDataType *)upi_malloc(sizeof(SystemDataType));
  #endif  ///< end of UG31XX_SHELL_ALGORITHM
  upi_memcpy(orgCapData, data->capData, sizeof(CapacityDataType));
  upi_memcpy(orgSysData, data->sysData, sizeof(SystemDataType));
  volt1 = data->backupVolt1;
  volt2 = data->backupVolt2;

  /// [AT-PM] : Get data from file ; 02/21/2013
  rtn = read_backup_file(data->backupFileName, data->backupBuffer, data->backupBufferSize);
  if(rtn == _UPI_FALSE_)
  {
    UG31_LOGD("[%s]: Read data from backup file fail.\n", __func__);
    #ifdef  UG31XX_SHELL_ALGORITHM
      upi_free(orgCapData);
      upi_free(orgSysData);
    #endif  ///< end of UG31XX_SHELL_ALGORITHM
    return (CHECK_BACKUP_FILE_STS_READ_FAIL);
  }
  driverVer = ConvertData(data);

  /// [AT-PM] : Following information is not checked ; 02/21/2013
  data->sysData->rmFromIC = orgSysData->rmFromIC;
  data->sysData->timeTagFromIC = orgSysData->timeTagFromIC;
  data->sysData->deltaCapFromIC = orgSysData->deltaCapFromIC;
  data->sysData->adc1ConvTime = orgSysData->adc1ConvTime;
  data->capData->preDsgCharge = orgCapData->preDsgCharge;
  
  /// [AT-PM] : Check data ; 02/21/2013
  if(driverVer != UG31XX_DRIVER_VERSION)
  {
    UG31_LOGN("[%s]: Backup file version mismatched.\n", __func__);
    rtnU8 = CHECK_BACKUP_FILE_STS_VERSION_MISMATCH;
  }
  else if((upi_memcmp(data->backupCustomerSelfDef, data->sysData->ggbParameter->customerSelfDef, CELL_PARAMETER_STRING_LENGTH) != 0) ||
           (upi_memcmp(data->backupProjectSelfDef, data->sysData->ggbParameter->projectSelfDef, CELL_PARAMETER_STRING_LENGTH) != 0))
  {
    UG31_LOGN("[%s]: Backup file cell information mismatched.\n", __func__);
    rtnU8 = CHECK_BACKUP_FILE_STS_VERSION_MISMATCH;
  }
  else if((upi_memcmp(orgCapData, data->capData, sizeof(CapacityDataType)) != 0) ||
          (upi_memcmp(orgSysData, data->sysData, sizeof(SystemDataType)) != 0) ||
          (volt1 != data->backupVolt1) ||
          (volt2 != data->backupVolt2))
  {
    UG31_LOGN("[%s]: Backup file needs to be updated\n", __func__);
    rtnU8 = CHECK_BACKUP_FILE_STS_NEED_UPDATE;
  }
  else
  {
    rtnU8 = CHECK_BACKUP_FILE_STS_PASS;
  }
  #ifdef  UG31XX_SHELL_ALGORITHM
    upi_free(orgCapData);
    upi_free(orgSysData);
  #endif  ///< end of UG31XX_SHELL_ALGORITHM
  return (rtnU8);
}
Beispiel #10
0
/*
 * LoadData
 *
 * Loads the specified data into the buffer, using the specified formats.
 * Currently, the new format must have the same channel configuration as the
 * original format.
 */
ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc)
{
    enum FmtChannels DstChannels = FmtMono;
    enum FmtType DstType = FmtByte;
    ALuint NewChannels, NewBytes;
    ALuint64 newsize;

    if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE)
        return AL_INVALID_ENUM;
    if((long)SrcChannels != (long)DstChannels)
        return AL_INVALID_ENUM;

    NewChannels = ChannelsFromFmt(DstChannels);
    NewBytes = BytesFromFmt(DstType);

    newsize = frames;
    newsize *= NewBytes;
    newsize *= NewChannels;
    if(newsize > INT_MAX)
        return AL_OUT_OF_MEMORY;

    WriteLock(&ALBuf->lock);
    if(ReadRef(&ALBuf->ref) != 0)
    {
        WriteUnlock(&ALBuf->lock);
        return AL_INVALID_OPERATION;
    }

    /* Round up to the next 16-byte multiple. This could reallocate only when
     * increasing or the new size is less than half the current, but then the
     * buffer's AL_SIZE would not be very reliable for accounting buffer memory
     * usage, and reporting the real size could cause problems for apps that
     * use AL_SIZE to try to get the buffer's play length.
     */
    newsize = (newsize+15) & ~0xf;
    if(newsize != ALBuf->BytesAlloc)
    {
        void *temp = al_calloc(16, (size_t)newsize);
        if(!temp && newsize)
        {
            WriteUnlock(&ALBuf->lock);
            return AL_OUT_OF_MEMORY;
        }
        al_free(ALBuf->data);
        ALBuf->data = temp;
        ALBuf->BytesAlloc = (ALuint)newsize;
    }

    if(data != NULL)
        ConvertData(ALBuf->data, (enum UserFmtType)DstType, data, SrcType, NewChannels, frames, align);

    if(storesrc)
    {
        ALBuf->OriginalChannels = SrcChannels;
        ALBuf->OriginalType     = SrcType;
        if(SrcType == UserFmtIMA4)
        {
            ALsizei byte_align = ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels);
            ALBuf->OriginalSize  = frames / align * byte_align;
            ALBuf->OriginalAlign = align;
        }
        else if(SrcType == UserFmtMSADPCM)
        {
            ALsizei byte_align = ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels);
            ALBuf->OriginalSize  = frames / align * byte_align;
            ALBuf->OriginalAlign = align;
        }
        else
        {
            ALBuf->OriginalSize  = frames * FrameSizeFromUserFmt(SrcChannels, SrcType);
            ALBuf->OriginalAlign = 1;
        }
    }
    else
    {
        ALBuf->OriginalChannels = (enum UserFmtChannels)DstChannels;
        ALBuf->OriginalType     = (enum UserFmtType)DstType;
        ALBuf->OriginalSize     = frames * NewBytes * NewChannels;
        ALBuf->OriginalAlign    = 1;
    }

    ALBuf->Frequency = freq;
    ALBuf->FmtChannels = DstChannels;
    ALBuf->FmtType = DstType;
    ALBuf->Format = NewFormat;

    ALBuf->SampleLen = frames;
    ALBuf->LoopStart = 0;
    ALBuf->LoopEnd = ALBuf->SampleLen;

    WriteUnlock(&ALBuf->lock);
    return AL_NO_ERROR;
}
Beispiel #11
0
BOOL PSPrint(
	LPIMAGE lpImage,
	LPFRAME lpFrame,
	BYTE    cSep,
	int     xSrc,
	int     ySrc,
	int     dxSrc,
	int     dySrc,
	int     xDest,
	int     yDest,
	int     dxDest,
	int     dyDest,
	int     iPrResX,
	int     iPrResY )
{
int y, yline, ystart, ylast, x, depth;
LFIXED yrate, yoffset;
LPTR lpBuffer[5], p1Buf, p2Buf, p3Buf, p4Buf;
LPSTR lpAngle, lpRuling;
LPTR lpImageData;
BOOL Negative, Asciize;
STRING szAngle, szRuling;
long lSize;
LPFRAME lpBaseFrame;

#define C_ANGLE Halftone.ScreenAngle[0]
#define M_ANGLE Halftone.ScreenAngle[1]
#define Y_ANGLE Halftone.ScreenAngle[2]
#define K_ANGLE Halftone.ScreenAngle[3]
#define C_RULING Halftone.ScreenRuling[0]
#define M_RULING Halftone.ScreenRuling[1]
#define Y_RULING Halftone.ScreenRuling[2]
#define K_RULING Halftone.ScreenRuling[3]

ProgressBegin(1,0);

lpAngle = szAngle;
lpRuling = szRuling;
Negative = Page.Negative;
Asciize = !Page.BinaryPS;

PS_ID( IDS_PS_DICTDEF );

/* Send the definition of the read data function */
if ( Asciize )
{
	PS_ID( IDS_PS_HEXDATA );
}
else
{
	PS_ID( IDS_PS_BINDATA );
}

if ( !Halftone.DoHalftoning )
	goto HalftoningDone;

/* Send the definition of the spot function */
if ( Halftone.DotShape == IDC_ELLIPSEDOT )
	{
	PS_ID( IDS_PS_ELLDOT1 );
	PS_ID( IDS_PS_ELLDOT2 );
	}
else
if ( Halftone.DotShape == IDC_SQUAREDOT )
	{
	PS_ID( IDS_PS_SQUDOT );
	}
else
if ( Halftone.DotShape == IDC_CIRCLEDOT )
	{
	PS_ID( IDS_PS_CIRDOT );
	}
else
if ( Halftone.DotShape == IDC_TRIANGLEDOT )
	{
	PS_ID( IDS_PS_TRIDOT );
	}
else
if ( Halftone.DotShape == IDC_PROPELLERDOT )
	{
	PS_ID( IDS_PS_PROPDOT );
	}

if ( Page.OutputType == IDC_PRINT_BLACKSEPS ||
     Page.OutputType == IDC_PRINT_GRAY )
	{ // Setup the "image" screen angles and freqs based on the sep
	if ( cSep == 'C' )
		{
		FixedAscii( C_ANGLE,  lpAngle,  -2 );
		FixedAscii( C_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'M' )
		{
		FixedAscii( M_ANGLE,  lpAngle,  -2 );
		FixedAscii( M_RULING, lpRuling, -2 );
		}
	else
	if ( cSep == 'Y' )
		{
		FixedAscii( Y_ANGLE,  lpAngle,  -2 );
		FixedAscii( Y_RULING, lpRuling, -2 );
		}
	else
	//if ( cSep == 'K' || cSep == 'X' || !cSep )
		{
		FixedAscii( K_ANGLE,  lpAngle,  -2 );
		FixedAscii( K_RULING, lpRuling, -2 );
		}
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	}
else
	{ // Setup the "colorimage" screen angles and frequencies
	PS_ID( IDS_PS_COLOREXT );
	PS_ID( IDS_PS_STARTBLOCK );

	FixedAscii( C_RULING, lpRuling, -2 );
	FixedAscii( C_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( M_RULING, lpRuling, -2 );
	FixedAscii( M_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( Y_RULING, lpRuling, -2 );
	FixedAscii( Y_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );

	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSPOT, lpRuling, lpAngle );
	PS_ID( IDS_PS_SETCOLORSCREEN );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	FixedAscii( K_RULING, lpRuling, -2 );
	FixedAscii( K_ANGLE,  lpAngle,  -2 );
	PS_ID2( IDS_PS_SETSCREEN, lpRuling, lpAngle );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	}

HalftoningDone:

// Setup a null transfer curve unless doing seps w/black ink (image operator)
if ( Page.OutputType == IDC_PRINT_BLACKSEPS )
{
	PS_ID( IDS_PS_BLACKSEPS );
}
else
if ( Page.OutputType == IDC_PRINT_COLORSEPS )
{
	PS_ID( IDS_PS_COLORSEPS );
}
else
{
	PS_ID( IDS_PS_NOINVERT );
}

PS_ID( IDS_PS_CHECKINVERT );

/* Send the destination point (x,y) in spots */
PS_ID2( IDS_PS_TRANSLATE, xDest, yDest );

/* Send the destination size (w,h) in spots */
PS_ID2( IDS_PS_SCALE, dxDest, dyDest );

if (lpImage)
	lpBaseFrame =  ImgGetBaseEditFrame(lpImage);
else 
	lpBaseFrame = lpFrame;
/* Compute how many pixels we're going to send */
/* Never send more than 16 pixels per halftone grid (or 4/grid in x and y) */
if (depth = FrameDepth( lpBaseFrame ))
	{
	if ( iPrResX < 600 )
		dxDest /= 4;
	else	dxDest /= 8;
	if ( iPrResY < 600 )
		dyDest /= 4;
	else	dyDest /= 8;
	}

if (depth == 0) depth = 1;

/* Let the printer do any upsizing */
if ( dySrc < dyDest )
	{
	yrate = UNITY;
	dxDest = dxSrc;
	dyDest = dySrc;
	}
else yrate = FGET( dySrc, dyDest );

/* Send the definition for the line buffers */
PS_ID1( IDS_PS_LINE1, dxDest );
PS_ID1( IDS_PS_LINE2, dxDest );
PS_ID1( IDS_PS_LINE3, dxDest );
PS_ID1( IDS_PS_LINE4, dxDest );
PS_ID1( IDS_PS_LINE5, dxDest );

if ( cSep ) // Plane at a time
{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
	if ( Page.OutputType == IDC_PRINT_COLORSEPS )
	{
		PS_ID( IDS_PS_DOCOLORSEPDEF );
	}
	else
	{
		PS_ID( IDS_PS_NOCOLORSEPDEF );
	}

	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLORSEPVAL );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	if ( cSep == 'C' )
	{
		PS_ID( IDS_PS_SEPCYAN );
	}
	else
	if ( cSep == 'M' )
	{
		PS_ID( IDS_PS_SEPMAGENTA );
	}
	else
	if ( cSep == 'Y' )
	{
		PS_ID( IDS_PS_SEPYELLOW );
	}
	else
	if ( cSep == 'K' || cSep == 'X' )
	{
		PS_ID( IDS_PS_SEPBLACK );
	}

	PS_ID( IDS_PS_COLORIMAGE4 );

	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_IMAGE );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}
else
if ( Page.Type == IDC_PRINTER_IS_CMYK )
{
	if (Page.OutputType == IDC_PRINT_COLORGRAY)
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );

				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );

				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_GETLINE4 );
					PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_POP );
				PS_ID( IDS_PS_ENDBLOCK );

				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_STARTBLOCK );
						PS_ID( IDS_PS_GETLINE4 );
						PS_ID( IDS_PS_GETLINE5 );
					PS_ID( IDS_PS_ENDBLOCK );
					PS_ID( IDS_PS_IMAGE );
				PS_ID( IDS_PS_ENDBLOCK );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
	else
	{
		PS_ID( IDS_PS_DOIMAGEDEF );
		PS_ID( IDS_PS_COLOREXT );

		// Start color image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_GETLINE1 );
				PS_ID( IDS_PS_GETLINE2 );
				PS_ID( IDS_PS_GETLINE3 );
				PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_COLORIMAGE4 );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		// Start gray image proc
		PS_ID( IDS_PS_STARTBLOCK );
			PS_ID( IDS_PS_STARTBLOCK );
				PS_ID( IDS_PS_STARTBLOCK );
					PS_ID( IDS_PS_DUMPLINE1 );
					PS_ID( IDS_PS_DUMPLINE2 );
					PS_ID( IDS_PS_DUMPLINE3 );
					PS_ID( IDS_PS_GETLINE4 );
				PS_ID( IDS_PS_ENDBLOCK );
				PS_ID( IDS_PS_NOIMAGE );
			PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_ENDBLOCK );

		PS_ID( IDS_PS_IFELSE );
		PS_ID( IDS_PS_DEF );
	}
}
else
if ( Page.Type == IDC_PRINTER_IS_RGB )
{
	PS_ID( IDS_PS_DOIMAGEDEF );
	PS_ID( IDS_PS_COLOREXT );

	// Start color image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_GETLINE1 );
	PS_ID( IDS_PS_GETLINE2 );
	PS_ID( IDS_PS_GETLINE3 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE4 );
	}

	PS_ID( IDS_PS_COLORIMAGE3 );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );

	// Start gray image proc
	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_STARTBLOCK );

	PS_ID( IDS_PS_STARTBLOCK );
	PS_ID( IDS_PS_DUMPLINE1 );
	PS_ID( IDS_PS_DUMPLINE2 );

	if ( Page.OutputType == IDC_PRINT_COLORGRAY )
	{
		PS_ID( IDS_PS_DUMPLINE3 );
		PS_ID( IDS_PS_GETLINE4 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_IMAGE );
	}
	else
	{
		PS_ID( IDS_PS_GETLINE3 );
		PS_ID( IDS_PS_ENDBLOCK );
		PS_ID( IDS_PS_NOIMAGE );
	}
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_ENDBLOCK );
	PS_ID( IDS_PS_IFELSE );
	PS_ID( IDS_PS_DEF );
}

/* Send the inline image's size, packing, and transform */
PS_ID5( IDS_PS_TRANSFORM, dxDest, dyDest, 8, dxDest, dyDest );

if ( !Asciize )
{
	// The size must include the doimage command that follows
	lSize = (long)dxDest * dyDest * depth;
	PS_ID1( IDS_PS_BEGINBINARY, lSize + 9 + 2 );
}

PS_ID( IDS_PS_DOIMAGE ); // Should be 9 characters

for ( x=0; x<5; x++ )
	lpBuffer[x] = NULL;

if (!AllocLines((LPPTR)&lpImageData, 1, dxSrc, depth))
{
	ProgressEnd();
	return(FALSE);
}

if (!AllocLines((LPPTR)&lpBuffer[0], 1, dxDest, depth))
{
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

if (!AllocLines((LPPTR)&lpBuffer[1], 4, dxDest, 1))
{
	FreeUp(lpBuffer[0]);
	FreeUp( lpImageData );
	ProgressEnd();
	return( FALSE );
}

p1Buf  = lpBuffer[1];
p2Buf  = lpBuffer[2];
p3Buf  = lpBuffer[3];
p4Buf  = lpBuffer[4];

ystart  = ySrc;
yline   = -1;
yoffset = (long)yrate>>1;

for (y=0; y<dyDest; y++)
{
	if (AstralClockCursor( y, dyDest, YES ))
	{
		fAbortPrint = YES;
		break;
	}

	/* Check for user input to abort dialog box */
	(*lpAbortTest)(hPrinterDC, 0);
	if ( fAbortPrint )
		break;

	ylast = yline;
#ifdef WIN32
	yline = ystart + WHOLE( yoffset );
#else
	yline = ystart + HIWORD( yoffset );
#endif
	yoffset += yrate;
	if ( yline != ylast )
	{
		LFIXED rate;

		if (lpImage)
			ImgGetLine( lpImage, NULL, xSrc, yline, dxSrc, lpImageData );
		else
			copy(FramePointer(lpBaseFrame, xSrc, yline, NO), lpImageData, dxSrc*depth);
		rate = FGET( dxSrc, dxDest );

		FrameSample(
			lpBaseFrame,
			lpImageData,
			0,
			lpBuffer[0],
			0,
			dxDest,
			rate);
	}

	if ( cSep )
	{ // cSep is either 'C', 'M', 'Y', 'K', 'X'(gray) or NULL
		if (cSep != 'X')
		{
			LPTR lpOutBuf;
			int  iPlaneOffset;

			switch(cSep)
			{
				case 'C' : lpOutBuf = p1Buf; iPlaneOffset = 0; break;
				case 'M' : lpOutBuf = p2Buf; iPlaneOffset = 1; break;
				case 'Y' : lpOutBuf = p3Buf; iPlaneOffset = 2; break;
				case 'K' : lpOutBuf = p4Buf; iPlaneOffset = 3; break;
			}

			switch(depth)
			{
				case 0 :
				case 1 :
					lpOutBuf = (LPTR)lpBuffer[0];
				break;

				case 3 :
					ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
						p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
				break;

				case 4 :
				{
					LPTR lpSrc  = (LPTR)lpBuffer[0];
					LPTR lpDst  = lpOutBuf;
					int  iCount = dxDest;

					lpSrc += iPlaneOffset;

					while(iCount-- > 0)
					{
						*lpDst++ = *lpSrc;
						lpSrc += 4;
					}
				}
				break;
			}

			if (Negative)
				negate(lpOutBuf, (long)dxDest);
			if ( !SendPSData( Asciize, lpOutBuf, dxDest ) )
				goto ErrorExit;
		}
		else
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );
			if (Negative)
				negate(p1Buf, (long)dxDest);
			CorrectGray( p1Buf, dxDest, YES, YES );
			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_CMYK )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
				copy( lpBuffer[0], p4Buf, dxDest );
			break;

			case 3 :
				ClrRGBtoCMYK( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf,p4Buf,dxDest,YES);
			break;

			case 4 :
			{
				LPTR lpSrc  = (LPTR)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				LPTR lpDst4 = p4Buf;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					*lpDst1++ = *lpSrc++;
					*lpDst2++ = *lpSrc++;
					*lpDst3++ = *lpSrc++;
					*lpDst4++ = *lpSrc++;
				}
			}
			break;
		}

		if (Negative)
		{
			negate(p1Buf, (long)dxDest);
			negate(p2Buf, (long)dxDest);
			negate(p3Buf, (long)dxDest);
			negate(p4Buf, (long)dxDest);
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;
		if ( !SendPSData( Asciize, p4Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
	else if ( Page.Type == IDC_PRINTER_IS_RGB )
	{
		switch(depth)
		{
			case 0 :
			case 1 :
				copy( lpBuffer[0], p1Buf, dxDest );
				copy( lpBuffer[0], p2Buf, dxDest );
				copy( lpBuffer[0], p3Buf, dxDest );
			break;

			case 3 :
				UnshuffleRGB( (LPRGB)lpBuffer[0],
					p1Buf, p2Buf, p3Buf, dxDest );
			break;

			case 4 :
			{
				LPCMYK lpCMYK = (LPCMYK)lpBuffer[0];
				LPTR lpDst1 = p1Buf;
				LPTR lpDst2 = p2Buf;
				LPTR lpDst3 = p3Buf;
				RGBS rgb;
				int  iCount = dxDest;

				while(iCount-- > 0)
				{
					CMYKtoRGB(lpCMYK->c, lpCMYK->m, lpCMYK->y, lpCMYK->k, &rgb);
					lpCMYK++;

					*lpDst1++ = rgb.red;
					*lpDst2++ = rgb.green;
					*lpDst3++ = rgb.blue;
				}
			}
			break;
		}

		if (Negative)
		{
			negate( p1Buf, dxDest );
			negate( p2Buf, dxDest );
			negate( p3Buf, dxDest );
		}

		if ( !SendPSData( Asciize, p1Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p2Buf, dxDest ) )
			goto ErrorExit;

		if ( !SendPSData( Asciize, p3Buf, dxDest ) )
			goto ErrorExit;

		if ( Page.OutputType == IDC_PRINT_COLORGRAY )
		{
			ConvertData( (LPTR)lpBuffer[0], depth, dxDest, p1Buf, 1 );

			if (Negative)
				negate(p1Buf, (long)dxDest);

			CorrectGray( p1Buf, dxDest, YES, YES);

			if ( !SendPSData( Asciize, p1Buf, dxDest ) )
				goto ErrorExit;
		}
	}
}

if ( !Asciize )
{
	PS_ID( IDS_PS_ENDBINARY );
}

/* Send the save restore command */
PS_ID( IDS_PS_MYSAVERESTORE );
PS_ID( IDS_PS_END );

ErrorExit:

if ( lpBuffer[0] )
	FreeUp(lpBuffer[0]);
if ( lpBuffer[1] )
	FreeUp(lpBuffer[1]);
if ( lpImageData )
	FreeUp( lpImageData );
ProgressEnd();
return( TRUE );
}
Beispiel #12
0
/*>int main(int argc, char **argv)
   -------------------------------
   Main program for scanning a loop against a set of cluster definitions

   26.07.95 Original    By: ACRM
   31.07.95 Moved all result printing into PrintClusterInfo()
*/
int main(int argc, char **argv)
{
   char    datafile[MAXBUFF],
           pdbfile[MAXBUFF],
           startres[16],
           lastres[16];
   int     retval = 0,
           NData,
           NLoopData,
           NMedians,
           method,
           NClusters,
           VecLength,
           TheCluster;
   BOOL    CATorsions = TRUE,
           Error      = FALSE,
           Verbose    = FALSE;
   REAL    **data     = NULL,
           **LoopData = NULL,
           dist;
   CLUSTER *clusters  = NULL,
           *medians   = NULL;
   
   gOutfp = stdout;

   if(ParseCmdLine(argc, argv, datafile, pdbfile, startres, lastres, 
                   &CATorsions, &Verbose))
   {
      if((data=ReadClusterFile(datafile, CATorsions, &method, 
                               &NData, &VecLength, 
                               &clusters, &NClusters,
                               &medians,  &NMedians))!=NULL)
      {
         if(HandleLoopSpec(pdbfile, startres, lastres, CATorsions, FALSE))
         {
            if((LoopData=ConvertData(gDataList,&NLoopData,CATorsions))
               !=NULL)
            {
               TheCluster = MatchCluster(data, NData, VecLength, 
                                         clusters, NClusters, 
                                         LoopData[0], CATorsions, 
                                         method, &Error);
               if(TheCluster == 0 && Error)
               {
                  fprintf(stderr,"Cluster matching failed (memory)\n");
                  retval = 1;
               }
               else
               {
                  dist = MinDistInCluster(data, NData, VecLength, 
                                          clusters, LoopData[0], 
                                          ABS(TheCluster));
                  PrintClusterInfo(TheCluster, medians, NMedians, dist,
                                   Verbose);
               }
            }
            else
            {
               fprintf(stderr,"Unable to get torsion data from loop\n");
               retval = 1;
            }
         }
         else
         {
            fprintf(stderr,"Failure in reading loop\n");
            retval = 1;
         }
      }
      else
      {
         fprintf(stderr,"Error reading cluster file: %s\n",datafile);
         retval = 1;
      }
   }
   else
   {
      Usage();
   }

   CleanUp(data, NData, VecLength, LoopData, NLoopData, VecLength);

   return(retval);
}
Beispiel #13
0
int TiffWriteFrame(
	int      oFile,
	LPSTR     lpFileName,
	LPOBJECT lpObject,
	LPFRAME  lpFrame,
	LPRECT   lpRect,
	int      flag,
	BOOL     fCompressed,
	BOOL     bEscapable)
{
	TAG    tag;
	int    y, bpl, npix, nlin, ofp;
	LPLONG lngptr,boffptr;
	LPWORD shtptr;
	DWORD  byteoffset;
	WORD   i, numtags, photomet, samples;
	BYTE   bpp;
	LPWORD lpRed, lpGreen, lpBlue;
	RGBS   RGBmap[256];
	LPTR   lp, lpBuffer, lpOutputPointer, lpImgScanline;
	FNAME  temp;
	RECT   rSave;
	BOOL   compressInit;
#ifdef STATIC16 // only in new framelib
	CFrameTypeConvert FrameTypeConvert;
	FRMTYPEINFO SrcTypeInfo;	
	FRMTYPEINFO DstTypeInfo;	
#endif

	lpBuffer      = NULL;
	lpImgScanline = NULL;

	if (!lpFrame)
		return( -1 );

	ProgressBegin(1,0);

	if ((ofp = oFile) < 0)
		bEscapable = !FileExists(lpFileName);

	if ((ofp = oFile) < 0 && (ofp = _lcreat(lpFileName,0)) < 0)
	{
		Message( IDS_EWRITE, lpFileName );
		goto Exit;
	}

	if (lpRect)
		rSave = *lpRect;
	else
	{
		rSave.top    = rSave.left = 0;
		rSave.bottom = FrameYSize(lpFrame)-1;
		rSave.right  = FrameXSize(lpFrame)-1;
	}

	npix = RectWidth(&rSave);
	nlin = RectHeight(&rSave);

	switch(flag)
	{
		case IDC_SAVELA :
		case IDC_SAVESP :
			bpp      = 1;
			bpl      = ((npix + 7) / 8);
			numtags  = 11;
			photomet = 1;
			samples  = 1;
		break;

		case IDC_SAVECT :
			bpp      = 8;
			bpl      = npix;
			numtags  = 11;
			photomet = 1;
			samples  = 1;
		break;

		case IDC_SAVE4BITCOLOR :
		case IDC_SAVE8BITCOLOR :
			bpp      = 8;
			bpl      = npix;
			numtags  = 12;
			photomet = 3;
			samples  = 1;
		break;

		case IDC_SAVE24BITCOLOR :
			bpp      = 24;
			bpl      = npix * 3;
			numtags  = 11;
			photomet = 2;
			samples  = 3;
		break;

		case IDC_SAVE32BITCOLOR :
			bpp      = 32;
			bpl      = npix * 4;
			numtags  = 11;
			photomet = 5;
			samples  = 4;
		break;

		default :
			goto Exit;
		break;
	}

	compressInit = NO;

	if ( bpp == 1 )
	{
		AllocLines( &lpBuffer,      1, npix, 2 );
		AllocLines( &lpImgScanline, 1, npix, 1 );
	}
	else
	{
		AllocLines( &lpBuffer,      1, max(bpl, FrameByteWidth(lpFrame)), 1 );
		AllocLines( &lpImgScanline, 1, max(bpl, FrameByteWidth(lpFrame)), 1 );
	}

	if ( !lpBuffer || !lpImgScanline )
	{
		Message( IDS_EMEMALLOC );
		_lclose( ofp );
		goto Exit;
	}

	/* first location where any extra data can be stored */
	/* 10 byte header + all tag data (12 bytes each) + 4 bytes (null ifd) */
	byteoffset = 10 + (numtags * sizeof(TAG)) + 4;

	shtptr = (LPWORD)LineBuffer[0];
	SetNextWord(&shtptr, 0x4949);   /* byte order is LSB,MSB */
	SetNextWord(&shtptr, 0x2a);     /* tiff version number */
	SetNextWord(&shtptr, 8);        /* byte offset to first image file directory LSW */
	SetNextWord(&shtptr, 0);        /* byte offset to first image file directory MSW */
	SetNextWord(&shtptr, numtags);  /* number of entries in IFD */

	tag.tagno  = 0xff;    /* tag 0xff, subfile type */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = 1;       /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x100;   /* tag 0x100, number of pixels */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = npix;    /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x101;   /* tag 0x101, number of lines */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = nlin;    /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x102;   /* tag 0x102, bits per sample */
	tag.type   = 3;       /* field type is short */
	tag.length = samples; /* number of values */

	if ( samples == 3 || samples == 4)
	{
		tag.value = byteoffset;	/* deferred value */
		byteoffset += (samples*sizeof(short));
	}
	else
		tag.value = bpp;  /* value */

#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x103;   /* tag 0x103, compression */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = (fCompressed ? 5:1); /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x106;	  /* tag 0x106,photometric inter.(0 = black) */
	tag.type   = 3;	      /* field type is short */
	tag.length = 1;	      /* number of values */
	tag.value  = photomet;	/* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x111;   /* tag 0x111, strip byte offsets */
	tag.type   = 4;       /* field type is long */
	tag.length = 1;       /* number of values */
	tag.value  = 0;       /* dummy location of the start of image data */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	boffptr = (LPLONG)(shtptr+4);  // make boffptr point at tag.value
	shtptr += 6;

	tag.tagno  = 0x115;   /* tag 0x115, samples per pixel*/
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = samples; /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11a;   /* tag 0x11a, xresolution */
	tag.type   = 5;       /* field type is rational */
	tag.length = 1;       /* number of values */
	tag.value = byteoffset;	/* deferered value */
	byteoffset += 8;
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11b;   /* tag 0x11b, yresolution */
	tag.type   = 5;       /* field type is rational */
	tag.length = 1;       /* number of values */
	tag.value  = byteoffset; /* deferred value */
	byteoffset += 8;
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	tag.tagno  = 0x11c;   /* tag 0x11c, planar configuration */
	tag.type   = 3;       /* field type is short */
	tag.length = 1;       /* number of values */
	tag.value  = 1;       /* value */
#ifdef _MAC
	SwapTag(&tag);
#endif	
	lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
	shtptr += 6;

	if ( photomet == 3 ) // Palette color map
	{
		tag.tagno  = 0x140;      /* tag 0x140, colormap */
		tag.type   = 3;          /* field type is short */
		tag.length = 3*256;      /* number of values */
		tag.value  = byteoffset; /* value */
		byteoffset += (2*3*256);
#ifdef _MAC
	SwapTag(&tag);
#endif	
		lmemcpy((LPTR)shtptr,(LPTR)&tag.tagno,12);
		shtptr += 6;
	}

	// Copy the NULL Image File Directory pointer
	SetNextWord(&shtptr, 0); /* pointer to next IFD */
	SetNextWord(&shtptr, 0);

	// Copy out the Bits Per Sample, if multiple samples
	if ( samples == 3 )  // The bits per pixel per sample
	{
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
	}

	// Copy out the Bits Per Sample, if multiple samples
	if ( samples == 4 )  // The bits per pixel per sample
	{
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
		SetNextWord(&shtptr, 8);
	}

	// Copy out the X and Y resolution fields
	lngptr = (LPLONG)shtptr;

#ifdef PPVIDEO
	SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* xreso numerator */
	SetNextLong(&lngptr, 2);							/* xreso denominator */
	SetNextLong(&lngptr, FrameResolution(lpFrame) * 2); /* yreso numerator */
	SetNextLong(&lngptr, 2);							/* yreso denominator */
#else
	SetNextLong(&lngptr, FrameResolution(lpFrame));		/* xreso numerator */
	SetNextLong(&lngptr, 1);							/* xreso denominator */
	SetNextLong(&lngptr, FrameResolution(lpFrame));		/* yreso numerator */
	SetNextLong(&lngptr, 1);							/* yreso denominator */
#endif

	*boffptr = byteoffset;
#ifdef _MAC
	swapl((LPDWORD)boffptr);
#endif	

	// Write out the tags, the bpp, and the resolutions
	i = (LPTR)lngptr - (LPTR)LineBuffer[0];
	if ( _lwrite(ofp, LineBuffer[0], i) != i )
		goto BadWrite;

	// Write the color palette, if necessary
	if ( photomet == 3 ) // Palette color map
	{
		if (!OptimizeBegin(lpObject, lpFrame, RGBmap, 256, 
			NULL /*(LPROC)AstralClockCursor*/,  // No Progress report
			NO, Convert.fOptimize, Convert.fScatter, Convert.fDither, npix))
			goto BadWrite;

		lpRed   = (LPWORD)LineBuffer[0];
		lpGreen = lpRed   + 256;
		lpBlue  = lpGreen + 256;
		for ( i=0; i<256; i++ )
		{
			*lpRed++   = (WORD)RGBmap[i].red   << 8;
			*lpGreen++ = (WORD)RGBmap[i].green << 8;
			*lpBlue++  = (WORD)RGBmap[i].blue  << 8;
		}
		if ( _lwrite(ofp, LineBuffer[0], 2*3*256) != 2*3*256 )
			goto BadWrite;
	}

	if ( fCompressed )
	{
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Initialize */
			goto BadWrite;
		compressInit = YES;
	}

	switch(bpp)
	{
		case 1 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameDepth(lpFrame) == 0)
				{
					if (flag == IDC_SAVESP)
						diffuse( 0, i, 0, NULL, lp, npix, lpBuffer );
					else
						con2la( lp, npix, lpBuffer );
				}
				else
				{
					ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer+npix, 1 );
					if ( flag == IDC_SAVESP )
						diffuse( 0, i, 0, NULL, lpBuffer+npix, npix, lpBuffer );
					else
						con2la( lpBuffer+npix, npix, lpBuffer );
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 8 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameDepth(lpFrame) == 0)
				{
					if ( photomet == 3 ) // If we are storing palette color
						OptimizeData(0, y, npix, lp, lpBuffer, 1 );
					else
						ConvertData( lp, 1, npix, lpBuffer, 1 );
				}
				else
				{
					if ( photomet == 3 ) // If we are storing palette color
						OptimizeData(0, y, npix, lp, lpBuffer, FrameDepth(lpFrame));
					else
						ConvertData( lp, FrameDepth(lpFrame), npix, lpBuffer, 1 );
				}
					
				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpBuffer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpBuffer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 24 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameType(lpFrame) != FDT_RGBCOLOR)
				{
					if (FrameType(lpFrame) != FDT_LINEART)
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FrameType(lpFrame);
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_RGBCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FrameType(lpFrame), NULL,
							y,
							(LPTR)lpBuffer, FDT_RGBCOLOR, NULL,
							npix);
#endif							
					}
					else
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FDT_GRAYSCALE;
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_RGBCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FDT_GRAYSCALE, NULL,
							y,
							(LPTR)lpBuffer, FDT_RGBCOLOR, NULL,
							npix);
#endif							
					}

					lpOutputPointer = lpBuffer;
				}
				else
				{
					lpOutputPointer = lp;
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;

		case 32 :
			for( y=rSave.top; y<=rSave.bottom; y++ )
			{
				if (AstralClockCursor( y-rSave.top, nlin, bEscapable ))
					goto Cancelled;

				if ( lpObject )
				{
					if (!ImgGetLine( NULL, lpObject, rSave.left, y,
						(rSave.right - rSave.left) + 1, lpImgScanline))
						goto BadRead;
					lp = lpImgScanline;
				}
				else
				{
					if ( !(lp = FramePointer( lpFrame, rSave.left, y, NO )) )
						goto BadRead;
				}

				if (FrameType(lpFrame) != FDT_CMYKCOLOR)
				{
					if (FrameType(lpFrame) != FDT_LINEART)
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FrameType(lpFrame);
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_CMYKCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FrameType(lpFrame), NULL,
							y,
							(LPTR)lpBuffer, FDT_CMYKCOLOR, NULL,
							npix);
#endif							
					}
					else
					{
#ifdef STATIC16
						SrcTypeInfo.DataType = FDT_GRAYSCALE;
						SrcTypeInfo.ColorMap = NULL;
						SrcTypeInfo.DataType = FDT_CMYKCOLOR;
						SrcTypeInfo.ColorMap = NULL;

						FrameTypeConvert.Init(SrcTypeInfo, DstTypeInfo, npix);
						FrameTypeConvert.ConvertData((LPTR)lp, (LPTR)lpBuffer, y, npix);
#else					
						FrameTypeConvert(
							(LPTR)lp, FDT_GRAYSCALE, NULL,
							y,
							(LPTR)lpBuffer, FDT_CMYKCOLOR, NULL,
							npix);
#endif							
					}

					lpOutputPointer = lpBuffer;
				}
				else
				{
					lpOutputPointer = lp;
				}

				if ( fCompressed )
				{
					if ( CompressLZW( ofp, lpOutputPointer, bpl ) < 0 )
						goto BadWrite;
				}
				else
				{
					if ( _lwrite( ofp, (LPSTR)lpOutputPointer, bpl ) != bpl )
						goto BadWrite;
				}
			}
		break;
	}

	if ( compressInit )
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */
			goto BadWrite;

	compressInit = NO;
	OptimizeEnd();

	if (ofp != oFile)
		_lclose(ofp);

	if (lpBuffer)
		FreeUp( lpBuffer );

	if (lpImgScanline)
		FreeUp( lpImgScanline );

	ProgressEnd();

	return( 0 );

BadWrite:
	Message( IDS_EWRITE, lpFileName );
	goto BadTiff;

BadRead:
	Message( IDS_EREAD, (LPTR)Control.RamDisk );

Cancelled:
BadTiff:
	if ( compressInit )
		if ( CompressLZW( ofp, NULL, 0 ) < 0 ) /* Terminate */
			goto BadWrite;

	compressInit = NO;

	OptimizeEnd();

	if (ofp != oFile)
		_lclose(ofp);

	lstrcpy(temp,lpFileName);
	FileDelete(temp);

Exit:

	if (lpBuffer)
		FreeUp( lpBuffer );

	if (lpImgScanline)
		FreeUp( lpImgScanline );

	ProgressEnd();

	return( -1 );
}
Beispiel #14
0
/*
*    alBufferSubDataEXT(ALuint buffer,ALenum format,ALvoid *data,ALsizei offset,ALsizei length)
*
*    Fill buffer with audio data
*/
AL_API ALvoid AL_APIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length)
{
    ALCcontext *Context;
    ALCdevice  *device;
    ALbuffer   *ALBuf;

    Context = GetContextSuspended();
    if(!Context) return;

    device = Context->Device;
    if((ALBuf=LookupBuffer(device->BufferMap, buffer)) == NULL)
        alSetError(Context, AL_INVALID_NAME);
    else
    {
        if(Context->SampleSource)
        {
            ALintptrEXT offset;

            if(Context->SampleSource->state == MAPPED)
            {
                alSetError(Context, AL_INVALID_OPERATION);
                ProcessContext(Context);
                return;
            }

            offset = (const ALubyte*)data - (ALubyte*)NULL;
            data = Context->SampleSource->data + offset;
        }

        if(length < 0 || offset < 0 || (length > 0 && data == NULL))
            alSetError(Context, AL_INVALID_VALUE);
        else if(ALBuf->eOriginalFormat != format)
            alSetError(Context, AL_INVALID_ENUM);
        else if(offset+length < offset ||
                offset+length > ALBuf->OriginalSize ||
                (offset%ALBuf->OriginalAlign) != 0 ||
                (length%ALBuf->OriginalAlign) != 0)
            alSetError(Context, AL_INVALID_VALUE);
        else
        {
            switch(format)
            {
                case AL_FORMAT_MONO8:
                case AL_FORMAT_MONO16:
                case AL_FORMAT_MONO_FLOAT32:
                case AL_FORMAT_MONO_DOUBLE_EXT:
                case AL_FORMAT_STEREO8:
                case AL_FORMAT_STEREO16:
                case AL_FORMAT_STEREO_FLOAT32:
                case AL_FORMAT_STEREO_DOUBLE_EXT:
                case AL_FORMAT_QUAD8_LOKI:
                case AL_FORMAT_QUAD16_LOKI:
                case AL_FORMAT_QUAD8:
                case AL_FORMAT_QUAD16:
                case AL_FORMAT_QUAD32:
                case AL_FORMAT_51CHN8:
                case AL_FORMAT_51CHN16:
                case AL_FORMAT_51CHN32:
                case AL_FORMAT_61CHN8:
                case AL_FORMAT_61CHN16:
                case AL_FORMAT_61CHN32:
                case AL_FORMAT_71CHN8:
                case AL_FORMAT_71CHN16:
                case AL_FORMAT_71CHN32: {
                    ALuint Bytes = aluBytesFromFormat(format);

                    offset /= Bytes;
                    length /= Bytes;

                    ConvertData(&ALBuf->data[offset], data, Bytes, length);
                }   break;

                case AL_FORMAT_REAR8:
                case AL_FORMAT_REAR16:
                case AL_FORMAT_REAR32: {
                    ALuint Bytes = ((format==AL_FORMAT_REAR8) ? 1 :
                                    ((format==AL_FORMAT_REAR16) ? 2 :
                                     4));

                    offset /= Bytes;
                    offset *= 2;
                    length /= Bytes;
                    length *= 2;

                    ConvertDataRear(&ALBuf->data[offset], data, Bytes, length);
                }   break;

                case AL_FORMAT_MONO_IMA4:
                case AL_FORMAT_STEREO_IMA4: {
                    int Channels = aluChannelsFromFormat(ALBuf->format);

                    // offset -> sample*channel offset, length -> block count
                    offset /= 36;
                    offset *= 65;
                    length /= ALBuf->OriginalAlign;

                    ConvertDataIMA4(&ALBuf->data[offset], data, Channels, length);
                }   break;

                case AL_FORMAT_MONO_MULAW:
                case AL_FORMAT_STEREO_MULAW:
                case AL_FORMAT_QUAD_MULAW:
                case AL_FORMAT_51CHN_MULAW:
                case AL_FORMAT_61CHN_MULAW:
                case AL_FORMAT_71CHN_MULAW:
                    ConvertDataMULaw(&ALBuf->data[offset], data, length);
                    break;

                case AL_FORMAT_REAR_MULAW:
                    offset *= 2;
                    length *= 2;
                    ConvertDataMULawRear(&ALBuf->data[offset], data, length);
                    break;

                default:
                    alSetError(Context, AL_INVALID_ENUM);
                    break;
            }
        }
    }

    ProcessContext(Context);
}
Beispiel #15
0
AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei offset, ALsizei length)
{
    enum UserFmtChannels srcchannels;
    enum UserFmtType srctype;
    ALCdevice *device;
    ALCcontext *context;
    ALbuffer *albuf;
    ALuint byte_align;
    ALuint channels;
    ALuint bytes;
    ALsizei align;

    context = GetContextRef();
    if(!context) return;

    device = context->Device;
    if((albuf=LookupBuffer(device, buffer)) == NULL)
        SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
    if(!(length >= 0 && offset >= 0))
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    if(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE)
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);

    WriteLock(&albuf->lock);
    align = albuf->UnpackAlign;
    if(SanitizeAlignment(srctype, &align) == AL_FALSE)
    {
        WriteUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    }
    if(srcchannels != albuf->OriginalChannels || srctype != albuf->OriginalType)
    {
        WriteUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
    }
    if(align != albuf->OriginalAlign)
    {
        WriteUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
    }

    if(albuf->OriginalType == UserFmtIMA4)
    {
        byte_align  = (albuf->OriginalAlign-1)/2 + 4;
        byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
    }
    else if(albuf->OriginalType == UserFmtMSADPCM)
    {
        byte_align  = (albuf->OriginalAlign-2)/2 + 7;
        byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
    }
    else
    {
        byte_align  = albuf->OriginalAlign;
        byte_align *= FrameSizeFromUserFmt(albuf->OriginalChannels,
                                           albuf->OriginalType);
    }

    if(offset > albuf->OriginalSize || length > albuf->OriginalSize-offset ||
       (offset%byte_align) != 0 || (length%byte_align) != 0)
    {
        WriteUnlock(&albuf->lock);
        SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
    }

    channels = ChannelsFromFmt(albuf->FmtChannels);
    bytes = BytesFromFmt(albuf->FmtType);
    /* offset -> byte offset, length -> sample count */
    offset = offset/byte_align * channels*bytes;
    length = length/byte_align * albuf->OriginalAlign;

    ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
                data, srctype, channels, length, align);
    WriteUnlock(&albuf->lock);

done:
    ALCcontext_DecRef(context);
}
Beispiel #16
0
void DetectMTCNN::Predict(const JImage &im_src, const RectF &roi,
                          VecBoxF *boxes, std::vector<VecPointF> *Gpoints) {
  boxes->clear(), Gpoints->clear();
  net_p_boxes_.clear(), net_r_boxes_.clear(), net_o_boxes_.clear();
  float crop_h = roi.h <= 1 ? roi.h * im_src.h_ : roi.h;
  float crop_w = roi.w <= 1 ? roi.w * im_src.w_ : roi.w;
  CalculateScales(crop_h, crop_w, factor_, max_side_, min_side_, &scales_);

  for (auto scale : scales_) {
    auto scale_h = static_cast<int>(std::ceil(crop_h * scale));
    auto scale_w = static_cast<int>(std::ceil(crop_w * scale));
    net_p_in_shape_[2] = scale_w, net_p_in_shape_[3] = scale_h;
    net_p_in_data_.resize(1 * 3 * scale_w * scale_h);
    ConvertData(im_src, net_p_in_data_.data(), roi, 3, scale_h, scale_w, 1,
                true);
    VecBoxInfo boxes_p;
    Process_net_p(net_p_in_data_.data(), net_p_in_shape_, thresholds_[0], scale,
                  &boxes_p);
    net_p_boxes_.insert(net_p_boxes_.end(), boxes_p.begin(), boxes_p.end());
  }
  net_p_boxes_ = NMS(net_p_boxes_, 0.7);
  BoxRegression(net_p_boxes_);
  Box2SquareWithConstrain(net_p_boxes_, crop_h, crop_w);
  if (net_p_boxes_.empty()) {
    return;
  }

  net_r_in_shape_[0] = static_cast<int>(net_p_boxes_.size());
  net_r_in_data_.resize(net_r_in_shape_[0] * net_r_in_num_);
  for (int n = 0; n < net_p_boxes_.size(); ++n) {
    const auto &net_12_box = net_p_boxes_[n].box;
    ConvertData(im_src, net_r_in_data_.data() + n * net_r_in_num_,
                net_12_box.RectFloat(), net_r_in_c_, net_r_in_h_, net_r_in_w_,
                1, true);
  }
  Process_net_r(net_r_in_data_.data(), net_r_in_shape_, thresholds_[1],
                net_p_boxes_, &net_r_boxes_);
  net_r_boxes_ = NMS(net_r_boxes_, 0.7);
  BoxRegression(net_r_boxes_);
  Box2SquareWithConstrain(net_r_boxes_, crop_h, crop_w);
  if (net_r_boxes_.empty()) {
    return;
  }

  net_o_in_shape_[0] = static_cast<int>(net_r_boxes_.size());
  net_o_in_data_.resize(net_o_in_shape_[0] * net_o_in_num_);
  for (int n = 0; n < net_r_boxes_.size(); ++n) {
    const auto &net_24_box = net_r_boxes_[n].box;
    ConvertData(im_src, net_o_in_data_.data() + n * net_o_in_num_,
                net_24_box.RectFloat(), net_o_in_c_, net_o_in_h_, net_o_in_w_,
                1, true);
  }
  Process_net_o(net_o_in_data_.data(), net_o_in_shape_, thresholds_[2],
                net_r_boxes_, &net_o_boxes_);
  BoxRegression(net_o_boxes_);
  net_o_boxes_ = NMS(net_o_boxes_, 0.7, true);
  BoxWithConstrain(net_o_boxes_, crop_h, crop_w);

  for (const auto &box_info : net_o_boxes_) {
    boxes->push_back(box_info.box);
    VecPointF mark_points;
    for (int k = 0; k < 5; ++k) {
      mark_points.emplace_back(box_info.landmark[2 * k],
                               box_info.landmark[2 * k + 1]);
    }
    Gpoints->push_back(mark_points);
  }
}
Beispiel #17
0
/*
 * LoadData
 *
 * Loads the specified data into the buffer, using the specified formats.
 * Currently, the new format must have the same channel configuration as the
 * original format.
 */
ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc)
{
    ALuint NewChannels, NewBytes;
    enum FmtChannels DstChannels;
    enum FmtType DstType;
    ALuint64 newsize;
    ALvoid *temp;

    if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE ||
       (long)SrcChannels != (long)DstChannels)
        return AL_INVALID_ENUM;

    NewChannels = ChannelsFromFmt(DstChannels);
    NewBytes = BytesFromFmt(DstType);

    newsize = frames;
    newsize *= NewBytes;
    newsize *= NewChannels;
    if(newsize > INT_MAX)
        return AL_OUT_OF_MEMORY;

    WriteLock(&ALBuf->lock);
    if(ReadRef(&ALBuf->ref) != 0)
    {
        WriteUnlock(&ALBuf->lock);
        return AL_INVALID_OPERATION;
    }

    temp = realloc(ALBuf->data, (size_t)newsize);
    if(!temp && newsize)
    {
        WriteUnlock(&ALBuf->lock);
        return AL_OUT_OF_MEMORY;
    }
    ALBuf->data = temp;

    if(data != NULL)
        ConvertData(ALBuf->data, (enum UserFmtType)DstType, data, SrcType, NewChannels, frames, align);

    if(storesrc)
    {
        ALBuf->OriginalChannels = SrcChannels;
        ALBuf->OriginalType     = SrcType;
        if(SrcType == UserFmtIMA4)
        {
            ALsizei byte_align = ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels);
            ALBuf->OriginalSize  = frames / align * byte_align;
            ALBuf->OriginalAlign = align;
        }
        else if(SrcType == UserFmtMSADPCM)
        {
            ALsizei byte_align = ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels);
            ALBuf->OriginalSize  = frames / align * byte_align;
            ALBuf->OriginalAlign = align;
        }
        else
        {
            ALBuf->OriginalSize  = frames * FrameSizeFromUserFmt(SrcChannels, SrcType);
            ALBuf->OriginalAlign = 1;
        }
    }
    else
    {
        ALBuf->OriginalChannels = (enum UserFmtChannels)DstChannels;
        ALBuf->OriginalType     = (enum UserFmtType)DstType;
        ALBuf->OriginalSize     = frames * NewBytes * NewChannels;
        ALBuf->OriginalAlign    = 1;
    }

    ALBuf->Frequency = freq;
    ALBuf->FmtChannels = DstChannels;
    ALBuf->FmtType = DstType;
    ALBuf->Format = NewFormat;

    ALBuf->SampleLen = frames;
    ALBuf->LoopStart = 0;
    ALBuf->LoopEnd = ALBuf->SampleLen;

    WriteUnlock(&ALBuf->lock);
    return AL_NO_ERROR;
}
Beispiel #18
0
DWORD CReg::ProcessLine(LPBYTE buf, DWORD size)
{_STTEX();
	DWORD i = 0;

	// Check for key name
	if ( buf[ i ] == '[' )
	{	
		i++; // Skip '['

		// Allocate memory
		LPBYTE name = new BYTE[ size + 1 ];
		if ( name == NULL ) return 0;

		// Read key name
		DWORD x = 0;
		while ( i < size && buf[ i ] != 0 && buf[ i ] != ']' &&
				buf[ i ] >= ' ' && buf[ i ] <= '~' )
			name[ x++ ] = buf[ i++ ];
		name[ x ] = 0;		

		// Add this key
		m_pCurKey = AddKey( (char*)name );

		delete [] name;

		// Skip line
		i = NextLine( buf, size, i );

		return i;

	} // end if

	// Allocate scratch memory
	LPBYTE data = new BYTE[ size + 1 ];
	if ( data == NULL ) return 0;

	// Old file type
	if ( m_pCurKey == NULL )
	{
		// Get name
		i += GetToken( data, size, &buf[ i ], size, '=' );

		// skip '='
		i++;

		char value[ 1024 ];
		CWinFile::GetFileNameFromPath( (char*)data, value );
		CWinFile::GetPathFromFileName( (char*)data, (char*)data );

		// Create key
		LPREGKEY prf = AddKey( (char*)data );

		// Check for NULL value
		if ( buf[ i ] != '=' ) prf->key->Set( value, "" );
			
		else
		{
			// Get the data
			i += GetToken( data, size, &buf[ i ], size - i, 0 );

			// Check for default value
			if ( *value == '@' ) prf->key->Set( "", (char*)data );

			// Add string
			prf->key->Set( value, (char*)data );

		} // end else

	} // end if

	else
	{
		BOOL bDefault = ( buf[ i ] == '@' );
		
		// Get name
		i += GetToken( data, size, &buf[ i ], size - i, '=' );

		// Check for NULL value
		if ( buf[ i ] != '=' ) 
			m_pCurKey->key->Add( REG_SZ, (LPCTSTR)data, "", 0 );

		else
		{
			// skip '='
			i++;

			char value[ 1024 ];
			if ( bDefault ) *value = 0;
			else strcpy_sz( value, (char*)data );

			DWORD dsize = size, type = 0;
			DWORD c = ConvertData( &type, data, &dsize, &buf[ i ], size - i );
			i += c;

			// Add reg value
			m_pCurKey->key->Add( type, value, data, dsize );

		} // end else

	} // end else

	// Release memory
	delete [] data;

	// Next line
	i = NextLine( buf, size, i );

	return i;
}