예제 #1
0
cStringType::cStringType(const char *Text,bool Copy):TextBuffer(NULL),TextBufferSize(0)
{
    if(Copy)
    {
        TextBufferSize=CalculateBufferSize(strlen(Text));
        TextBuffer=(char*)malloc(TextBufferSize*(sizeof(TextBuffer[0])));
        strncpy(TextBuffer,Text,TextBufferSize);
        TextBuffer[TextBufferSize-1]=0;
    }else
    {
        TextBuffer=(char*)Text;
    }
}
예제 #2
0
cStringType::cStringType(const cStringType &Obj,bool Copy)
{
    const char *Text=Obj;
    if(Obj.TextBufferSize)//если там динамический буфер то надо копировать ибо там буфер может сменится
        Copy=true;
    if(Copy)
    {
        TextBufferSize=CalculateBufferSize(strlen(Text));
        TextBuffer=(char*)malloc(TextBufferSize*(sizeof(TextBuffer[0])));
        strncpy(TextBuffer,Text,TextBufferSize);
        TextBuffer[TextBufferSize-1]=0;
    }else
    {
        TextBuffer=(char*)Text;
    }
}
예제 #3
0
void cStringType::OptimizeMemory()
{
    if(TextBufferSize==0)
        return;
    size_t Len=strlen(TextBuffer);
    Len=CalculateBufferSize(Len);
    if(TextBufferSize!=Len)
    {
        TextBufferSize=Len;
        if(TextBuffer)
        {
            TextBuffer=(char*)realloc(TextBuffer,TextBufferSize*sizeof(TextBuffer[0]));
        }else
            TextBuffer=(char*)malloc(TextBufferSize*sizeof(TextBuffer[0]));
    }
}
예제 #4
0
void cStringType::PrepareSize(size_t S)
{
    if(S==0)//need same size like now
    {
        S=GetLength();
    }
    S++;
    if(TextBufferSize<S)
    {
        char *SaveBuffer=NULL;
        if(TextBufferSize==0)//указатель на константную строку
        {
            SaveBuffer=TextBuffer;
            TextBuffer=NULL;
            if(SaveBuffer)
            {
                size_t l=strlen(SaveBuffer)+1;
                if(l>S)
                    S=l;
            }
        }
        TextBufferSize=CalculateBufferSize(S);
        if(TextBuffer)
        {
            TextBuffer=(char*)realloc(TextBuffer,TextBufferSize*sizeof(TextBuffer[0]));
        }else
        {
            //char *SaveBuffer=TextBuffer;
            TextBuffer=(char*)malloc(TextBufferSize*sizeof(TextBuffer[0]));
            TextBuffer[0]=0;
            if(SaveBuffer)
                strncpy(TextBuffer,SaveBuffer,TextBufferSize);
            TextBuffer[TextBufferSize-1]=0;
        }
    }
}
예제 #5
0
int CameraPrepareBuffer(P_CAMERA_DMA_BUFFER_INFO pBufInfo, int BufferType)        // allocate DMA buffer
{
    int i,size;
    int sizeY,sizeC;

    RETAILMSG(CAM_INOUT,(TEXT("++++++++++++++++++CameraPrepareBuffer\n")));


    if(BufferType == VIDEO_CAPTURE_BUFFER)
    {
        size = CalculateBufferSize(Video_Buffer.Width, Video_Buffer.Height, Video_Buffer.Format);
        Video_Buffer.FrameSize = size;
        Video_Buffer.Size = size * MAX_HW_FRAMES;
        RETAILMSG(CAM_MSG,(TEXT("Video_Buffer.Width=%d Video_Buffer.Height=%d Video_Buffer.Size=%d  Video_Buffer.Format=%d\n"),Video_Buffer.Width, Video_Buffer.Height, Video_Buffer.Size, Video_Buffer.Format));

        if(Video_Buffer.Size > CAPTURE_BUFFER_SIZE)
        {
            RETAILMSG(CAM_ERR,(TEXT("Video size is larger than buffer size\n")));
            return FALSE;
        }

        for(i=0;i<MAX_HW_FRAMES;i++)
        {
            pBufInfo[i].VirtAddr = (DWORD)pCodecVirtAddr + size*i;
            pBufInfo[i].size = size;
            pBufInfo[i].pY = (DWORD*)((DWORD)(PhysCodecAddr.LowPart) + size*i);
        }

        if(OUTPUT_CODEC_YCBCR420 == Video_Buffer.Format)
        {
            sizeY = Video_Buffer.Width*Video_Buffer.Height;
            sizeC = Video_Buffer.Width*Video_Buffer.Height/4;
            for(i=0;i<MAX_HW_FRAMES;i++)
            {
                pBufInfo[i].pCb = (DWORD*)((DWORD)pBufInfo[i].pY + sizeY);
                pBufInfo[i].pCr = (DWORD*)((DWORD)pBufInfo[i].pCb + sizeC);
            }
        }

    }
    else if(BufferType == STILL_CAPTURE_BUFFER)
    {
        size = CalculateBufferSize(Still_Buffer.Width, Still_Buffer.Height, Still_Buffer.Format);
        Still_Buffer.FrameSize = size;
        Still_Buffer.Size = size;
        RETAILMSG(CAM_MSG,(TEXT("Still_Buffer.Width=%d Still_Buffer.Height=%d Still_Buffer.Size=%d  Still_Buffer.Format=%d\n"),Still_Buffer.Width, Still_Buffer.Height, Still_Buffer.Size, Still_Buffer.Format));


        if(Still_Buffer.Size > CAPTURE_BUFFER_SIZE)
        {
            RETAILMSG(CAM_ERR,(TEXT("Still size is larger than buffer size\n")));
            return FALSE;
        }

        pBufInfo[0].VirtAddr = (DWORD)pCodecVirtAddr;
        pBufInfo[0].size = size;
        pBufInfo[0].pY = (DWORD*)(PhysCodecAddr.LowPart);


        if(OUTPUT_CODEC_YCBCR420 == Still_Buffer.Format)
        {
            sizeY = Still_Buffer.Width*Still_Buffer.Height;
            sizeC = Still_Buffer.Width*Still_Buffer.Height/4;
            pBufInfo[0].pCb = (DWORD*)((DWORD)pBufInfo[0].pY + sizeY);
            pBufInfo[0].pCr = (DWORD*)((DWORD)pBufInfo[0].pCb + sizeC);

        }
    }
    else if(BufferType == PREVIEW_CAPTURE_BUFFER)
    {
        size = CalculateBufferSize(Preview_Buffer.Width, Preview_Buffer.Height, Preview_Buffer.Format);
        Preview_Buffer.FrameSize = size;
        Preview_Buffer.Size = size * MAX_HW_FRAMES;
        RETAILMSG(CAM_MSG,(TEXT("Preview_Buffer.Width=%d Preview_Buffer.Height=%d Preview_Buffer.Size=%d Preview_Buffer.Format=%d\n"),Preview_Buffer.Width, Preview_Buffer.Height, Preview_Buffer.Size, Preview_Buffer.Format));

        if(Preview_Buffer.Size > PREVIEW_BUFFER_SIZE)
        {
            RETAILMSG(CAM_ERR,(TEXT("Preview size is larger than buffer size\n")));
            return FALSE;
        }

        for(i=0;i<MAX_HW_FRAMES;i++)
        {
            pBufInfo[i].VirtAddr = (DWORD)pPreviewVirtAddr + size*i;
            pBufInfo[i].size = size;
            pBufInfo[i].pY = (DWORD*)((DWORD)(PhysPreviewAddr.LowPart) + size*i);
        }

        if(OUTPUT_CODEC_YCBCR420 == Preview_Buffer.Format)
        {
            sizeY = Preview_Buffer.Width*Preview_Buffer.Height;
            sizeC = Preview_Buffer.Width*Preview_Buffer.Height/4;
            for(i=0;i<MAX_HW_FRAMES;i++)
            {
                pBufInfo[i].pCb = (DWORD*)((DWORD)pBufInfo[i].pY + sizeY);
                pBufInfo[i].pCr = (DWORD*)((DWORD)pBufInfo[i].pCb + sizeC);
            }
        }
    }
    else
    {
        return FALSE;
    }

    RETAILMSG(CAM_INOUT,(TEXT("------------------CameraPrepareBuffer\n")));
    return TRUE;
}
예제 #6
0
파일: scihlpr.cpp 프로젝트: mingpen/OpenNT
INT
MapUnicodeServiceClassInfoToAnsi(
    IN     LPWSASERVICECLASSINFOW Source,
    IN OUT LPDWORD                lpTargetSize,
    IN     LPWSASERVICECLASSINFOA Target
    )
{
    DWORD RequiredBufferSize;
    LPBYTE FreeSpace;
    INT    StringLen;
    DWORD  Index;

    __try {
        // Find the size of buffer we will need
        RequiredBufferSize = CalculateBufferSize(
            TRUE, // Ansi Source
            Source);
        if (RequiredBufferSize > *lpTargetSize){
            *lpTargetSize = RequiredBufferSize;
            return(WSAEFAULT);
        } //if

        // Copy known size portions of buffer

        // Toplevel structure
        FreeSpace = (LPBYTE)Target;
        CopyMemory(Target,
                   Source,
                   sizeof(WSASERVICECLASSINFOA));
        FreeSpace += sizeof(WSASERVICECLASSINFOA);

        // The array of WSANSCLASSINFO's
        Target->lpClassInfos = (LPWSANSCLASSINFOA)FreeSpace;
        CopyMemory(Target->lpClassInfos,
                   Source->lpClassInfos,
                   (sizeof(WSANSCLASSINFOA) * Source->dwCount));
        FreeSpace += (sizeof(WSANSCLASSINFOA) * Source->dwCount);

        // The service class ID GUID
        Target->lpServiceClassId = (LPGUID)FreeSpace;
        CopyMemory(Target->lpServiceClassId,
                   Source->lpServiceClassId,
                   sizeof(GUID));
        FreeSpace += sizeof(GUID);

        // Copy variable portion

        Target->lpszServiceClassName = (LPSTR)FreeSpace;
        StringLen = WideCharToMultiByte(
            CP_ACP,                          // CodePage (Ansi)
            0,                               // dwFlags
            Source->lpszServiceClassName,    // lpWideCharStr
            -1,                              // cchWideChar
            NULL         ,                   // lpMultiByteStr
            0,                               // cchMultiByte
            NULL,                            // lpDefaultChar
            NULL);                           // lpUsedDefaultChar

        FreeSpace += (StringLen+1);
        WideCharToMultiByte(
            CP_ACP,                          // CodePage (Ansi)
            0,                               // dwFlags
            Source->lpszServiceClassName,    // lpWideCharStr
            -1,                              // cchWideChar
            Target->lpszServiceClassName,    // lpMultiByteStr
            StringLen,                       // cchMultiByte
            NULL,                            // lpDefaultChar
            NULL);                           // lpUsedDefaultChar

        for (Index=0;Index < Source->dwCount ;Index++ ){
            LPWSTR SourceString;
            LPSTR TargetString;

            SourceString = Source->lpClassInfos[Index].lpszName;
            Target->lpClassInfos[Index].lpszName = (LPSTR)FreeSpace;
            TargetString = Target->lpClassInfos[Index].lpszName;

            StringLen = WideCharToMultiByte(
                CP_ACP,                          // CodePage (Ansi)
                0,                               // dwFlags
                SourceString,                    // lpWideCharStr
                -1,                              // cchWideChar
                NULL         ,                   // lpMultiByteStr
                0,                               // cchMultiByte
                NULL,                            // lpDefaultChar
                NULL);                           // lpUsedDefaultChar

            FreeSpace += (StringLen+1);
            WideCharToMultiByte(
                CP_ACP,                          // CodePage (Ansi)
                0,                               // dwFlags
                SourceString,                    // lpWideCharStr
                -1,                              // cchWideChar
                TargetString,                    // lpMultiByteStr
                StringLen,                       // cchMultiByte
                NULL,                            // lpDefaultChar
                NULL);                           // lpUsedDefaultChar

            Target->lpClassInfos[Index].lpValue = FreeSpace;
            CopyMemory(
                Target->lpClassInfos[Index].lpValue,
                Source->lpClassInfos[Index].lpValue,
                Source->lpClassInfos[Index].dwValueSize);
            FreeSpace += Source->lpClassInfos[Index].dwValueSize;
        } //for
        return(ERROR_SUCCESS);
    }
    __except (WS2_EXCEPTION_FILTER()) {
        return (WSAEFAULT);
    }
}