Created
May 8, 2023 10:32
-
-
Save tvd12/610bb94712a4711822247b4b48e8bf9a to your computer and use it in GitHub Desktop.
findinidata_one.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CCTexture2D *Kgetinidata::findinidata_one(char *nFileName,int nFrameIndex,int *mCurwidth, int *mCurheight,int *mFrams,SPRFRAMSINFO *nSprInfo,int m_converType) | |
| { | |
| if (!nFileName || !nFileName[0]) | |
| return NULL; | |
| if (!strstr(nFileName,".spr")) | |
| return NULL; | |
| SPROFFS* pOffsTable = NULL; | |
| SPRHEAD* pSprHeader = NULL; | |
| SPRFRAME* pFrameData = NULL; | |
| CCTexture2D* nTextureOld=NULL; | |
| unsigned int nfleddwid = 0; | |
| short nImagePosition = -1; | |
| int bSingleFrameLoad = false; | |
| unsigned int nSingFrameSize = 0; | |
| pSprHeader = (SPRHEAD*)m_ImageStore.GetImage(nFileName,nfleddwid,nImagePosition,nFrameIndex,ISI_T_SPR,(void*&)pFrameData,(void*&)pOffsTable,bSingleFrameLoad,nSingFrameSize,m_converType); | |
| if (pSprHeader == NULL || pFrameData==NULL) | |
| return NULL; | |
| if (!bSingleFrameLoad && pOffsTable==NULL) | |
| return NULL; | |
| bool nIsClear = false; | |
| if (nSprInfo) | |
| { | |
| if (pSprHeader->Reserved[1]==1 || pSprHeader->Reserved[1]==2) | |
| { | |
| if (!strstr(nFileName,"”Œœ∑◊ ‘¥")) | |
| { | |
| nIsClear = true; | |
| nSprInfo->nIsClear = 0; | |
| } | |
| else | |
| nSprInfo->nIsClear = 0; | |
| } | |
| nSprInfo->mFrams = pSprHeader->Frames; | |
| nSprInfo->pHwidth = pSprHeader->Width; | |
| nSprInfo->pHheight = pSprHeader->Height; | |
| nSprInfo->pHCenterX = pSprHeader->CenterX; | |
| nSprInfo->pHCenterY = pSprHeader->CenterY; | |
| nSprInfo->nInterval = pSprHeader->nInterval; | |
| nSprInfo->pFwidth = pFrameData->Width; | |
| nSprInfo->pFheight = pFrameData->Height; | |
| nSprInfo->pFoffsetX = pFrameData->OffsetX; | |
| nSprInfo->pFoffsetY = pFrameData->OffsetY; | |
| } | |
| *mFrams = pSprHeader->Frames; | |
| char nSprFilePath[64]={0}; | |
| nSprInfo->nIDwid = nfleddwid; | |
| unsigned int nFielpahtdwid = nfleddwid;//g_FileName2Id(nFileName); | |
| t_sprintf(nSprFilePath,"%u-%d",nFielpahtdwid,nFrameIndex); | |
| if (nTextureOld = CCTextureCache::sharedTextureCache()->isFileExist(nSprFilePath)) | |
| { | |
| if(mCurwidth) | |
| *mCurwidth =(int)pFrameData->Width;//pSprHeader->Width; | |
| if(mCurheight) | |
| *mCurheight=(int)pFrameData->Height;//pSprHeader->Height; | |
| nSprInfo->nIsClear = 0; | |
| return nTextureOld; | |
| } | |
| KPAL24* m_pPal24=NULL; | |
| KPAL24 pPalette[256]; //Palette_Colour | |
| memset(pPalette,0,sizeof(pPalette)); | |
| if (m_ReadModel) | |
| { | |
| m_pPal24 = (KPAL24*)GET_SPR_PALETTE(pSprHeader);//(&pSprHeader[1]); | |
| memcpy(&pPalette, m_pPal24, sizeof(KPAL24)*pSprHeader->Colors); | |
| } | |
| SPRFRAME* pFrame = NULL; | |
| unsigned char* decdata = NULL; | |
| if (!bSingleFrameLoad && !pOffsTable) | |
| return NULL; | |
| if (!bSingleFrameLoad) | |
| pFrame = (SPRFRAME*)pFrameData;//(SPRFRAME*)((char*)pOffsTable + sizeof(SPROFFS)*pSprHeader->Frames + pOffsTable[nFrameIndex].Offset); | |
| else | |
| pFrame = (SPRFRAME*)pFrameData;//(SPRFRAME*)m_ImageStore.GetSprFrameData(nFileName,nfleddwid,nImagePosition,nFrameIndex,nSingFrameSize); | |
| if (pFrame==NULL) | |
| return NULL; | |
| unsigned int height = pFrame->Height; | |
| unsigned int width = pFrame->Width; | |
| //WORD* mPalette =(WORD*)m_Palette;//(WORD*)GetPalette();????? ???24? | |
| unsigned int datalength = 0; | |
| if (bSingleFrameLoad) | |
| datalength = nSingFrameSize; | |
| else | |
| datalength = pOffsTable[nFrameIndex].Length; | |
| unsigned int curdecposition = 0; | |
| unsigned int decdatalen = width * height*4; | |
| decdata = (unsigned char*)malloc((size_t)decdatalen); | |
| if (!decdata) | |
| return NULL; | |
| memset(decdata, 0, sizeof(decdata)); | |
| int n=0,calpha; | |
| unsigned char alpha; | |
| unsigned int temppos = 0; | |
| unsigned int nByteCount = 0; // ???????? | |
| unsigned int nPixelCount = 0; // ????????? | |
| unsigned int nWidth =pFrame->Width; //m_pFrameInfo[nFrame].nWidth; // ??????? | |
| unsigned int nHeight = pFrame->Height;// m_pFrameInfo[nFrame].nHeight; // ??????? | |
| unsigned int nTotlePixelNum = nWidth * nHeight; // ????????? | |
| unsigned int nFrameLen = datalength-8;//m_pFrameInfo[nFrame].nRawDataLen; //?????????? | |
| BYTE *pData = pFrame->Sprite;//m_pFrameInfo[nFrame].pRawData; //??????????? | |
| BYTE pixelNum, pixelColor; | |
| BYTE *pTexData = decdata;//(BYTE*)LockedRect.pBits; // ????????????? | |
| BYTE *pTexLine = pTexData;// ??????????????? | |
| for(;;) | |
| { | |
| pixelNum = *pData++; | |
| alpha = *pData++; | |
| nByteCount += 2; | |
| nPixelCount += pixelNum; | |
| if(alpha == 0) | |
| { | |
| for(int l=0; l<pixelNum; l++) | |
| { | |
| *((unsigned int*)pTexLine) = 0; | |
| pTexLine += 4; | |
| } | |
| } | |
| else | |
| { | |
| for(int l=0; l<pixelNum; l++) | |
| { | |
| pixelColor = *pData++; | |
| int R = pPalette[pixelColor].Red; | |
| int G = pPalette[pixelColor].Green; | |
| int B = pPalette[pixelColor].Blue; | |
| if (nIsClear || nSprInfo->nIsClear) | |
| { | |
| /*int maxVer = MAX(pPalette[pixelColor].Red, pPalette[pixelColor].Green); | |
| maxVer = MAX(maxVer, pPalette[pixelColor].Blue);*/ | |
| int maxVer = R>G?(R>B?R:B):(G>B?G:B); | |
| int alphaVer = MIN(alpha, maxVer); | |
| if (nSprInfo->nModel) | |
| { | |
| *pTexLine++ = R; | |
| *pTexLine++ = G; | |
| *pTexLine++ = B; | |
| *pTexLine++ = alphaVer; | |
| } | |
| else | |
| { | |
| int subVer = (254 - maxVer)/8; | |
| *pTexLine++ = R+subVer; | |
| *pTexLine++ = G+subVer; | |
| *pTexLine++ = B+subVer; | |
| *pTexLine++ = alphaVer; | |
| } | |
| } | |
| else | |
| { | |
| *pTexLine++ = R; | |
| *pTexLine++ = G; | |
| *pTexLine++ = B; | |
| *pTexLine++ = alpha; | |
| } | |
| } | |
| nByteCount += pixelNum; | |
| } | |
| if(nByteCount >= nFrameLen) //???????????????? | |
| break; | |
| } | |
| if (decdata) | |
| nTextureOld = CCTextureCache::sharedTextureCache()->addImageWihtData(nSprFilePath,decdata,datalength,width,height,CCSizeMake((float)(width), (float)(height))); | |
| if(mCurwidth) | |
| *mCurwidth = (int)width; | |
| if(mCurheight) | |
| *mCurheight = (int)height; | |
| if (decdata) | |
| { | |
| free(decdata); | |
| decdata =NULL; | |
| } | |
| _Return: | |
| nSprInfo->nIsClear = 0; | |
| return nTextureOld; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment