// 比較のコード生成 static void cmp(int jcc) { if (isCnst0(stkPtr) && // Src が定数 0 で flgPtr==stkPtr-1) { // Dst の評価がフラグにあれば // 何もしない } else if (isCnst0(stkPtr-1) && // Dst が定数の 0 で flgPtr==stkPtr) { // Src の評価がフラグにあれば jcc = swapJcc(jcc); // フラグ値判断用の Jcc 変更 } else { // Src, Dst の両方が定数 0 以外 if ((topSta==ACC || topSta==RVAR) && // Src がどれかレジスタにあり secSta!=ACC && secSta!=RVAR && // Dst がメモリオペランドなら secSta!=STK && secSta!=FLAG ) { // (CNST,GVAR,LVAR,PRM,...) jcc = swapJcc(jcc); // 条件を逆にし SwapInt(topSta, secSta); // Dst と Src を入れ替える SwapInt(topAux, secAux); } clearFlg(); // フラグ値の変化にそなえる if (secSta!=RVAR) loadStk(1); // Dst を Acc にロード if (topSta==STK||topSta==FLAG) loadStk(0); // 直接演算不可ならロード calReg("CMP", secAux, stkPtr); // 比較を行う } if (isAcc(stkPtr)) relAcc(topAux); // Src が Acc を使用中なら解放 if (isAcc(stkPtr-1)) relAcc(secAux); // Dst が Acc を使用中なら解放 popStk(2); // 一旦、スタックを解放 if (accCnt>=AccSIZ) outStk(); // Acc に空きがなければ作り pushStk(FLAG, allocAcc()); // 結果 (FLAG, Acc) を記録する flgPtr = stkPtr; // フラグが値を持っている flgJcc = jcc; // 論理値に変換するための Jcc }
// 左右逆順になっても良い演算で少し効率アップ static void rcal(char *op) { if (topSta==ACC && secSta!=ACC && // Src がAccで Dst がAcc以外の secSta!=STK && secSta!=FLAG) { // 直接演算可のオペランドなら SwapInt(topSta, secSta); // Src と Dst を交換し SwapInt(topAux, secAux); } cal(op); // 通常の演算手順で処理 }
ILboolean iSaveRleSgi(ILubyte *Data) { ILuint c, i, y, j; ILubyte *ScanLine = NULL, *CompLine = NULL; ILuint *StartTable = NULL, *LenTable = NULL; ILuint TableOff, DataOff = 0; ScanLine = (ILubyte*)ialloc(iCurImage->Width); CompLine = (ILubyte*)ialloc(iCurImage->Width * 2); // Absolute worst case. StartTable = (ILuint*)ialloc(iCurImage->Height * iCurImage->Bpp * sizeof(ILuint)); LenTable = (ILuint*)ialloc(iCurImage->Height * iCurImage->Bpp * sizeof(ILuint)); if (!ScanLine || !StartTable || !LenTable) { ifree(ScanLine); ifree(CompLine); ifree(StartTable); ifree(LenTable); return IL_FALSE; } // These just contain dummy values at this point. TableOff = itellw(); iwrite(StartTable, sizeof(ILuint), iCurImage->Height * iCurImage->Bpp); iwrite(LenTable, sizeof(ILuint), iCurImage->Height * iCurImage->Bpp); DataOff = itellw(); for (c = 0; c < iCurImage->Bpp; c++) { for (y = 0; y < iCurImage->Height; y++) { i = y * iCurImage->Bps + c; for (j = 0; j < iCurImage->Width; j++, i += iCurImage->Bpp) { ScanLine[j] = Data[i]; } ilRleCompressLine(ScanLine, iCurImage->Width, 1, CompLine, LenTable + iCurImage->Height * c + y, IL_SGICOMP); iwrite(CompLine, 1, *(LenTable + iCurImage->Height * c + y)); } } iseek(TableOff, IL_SEEK_SET); j = iCurImage->Height * iCurImage->Bpp; for (y = 0; y < j; y++) { StartTable[y] = DataOff; StartTable[y] = SwapInt(StartTable[y]); DataOff += LenTable[y]; LenTable[y] = SwapInt(LenTable[y]); } iwrite(StartTable, sizeof(ILuint), iCurImage->Height * iCurImage->Bpp); iwrite(LenTable, sizeof(ILuint), iCurImage->Height * iCurImage->Bpp); ifree(ScanLine); ifree(CompLine); ifree(StartTable); ifree(LenTable); return IL_TRUE; }
static bool_t ProcessRawInfo(video* Video,char* Bits,char* RawBits,int Width,int Height,int Pitch,int* Offset,bool_t MovedSIP) { int Dir = GetOrientation(); Video->Pitch = Pitch; if (Width > Height) // native landscape device Dir = CombineDir(Dir,DIR_SWAPXY|DIR_MIRRORUPDOWN,0); // trust GetBits() if it's inside the Raw buffer if (Bits >= RawBits && Bits < RawBits + Height*Pitch) return 0; if (!MovedSIP && Dir==0) // assuming working GetBits() with RotM in native mode return 0; if (Dir & DIR_SWAPXY) SwapInt(&Video->Width,&Video->Height); if (Width > Height) // native landscape device { if ((Dir & DIR_SWAPXY)==0 ? GetHandedness() : (Dir & DIR_MIRRORLEFTRIGHT)!=0) *Offset = (Width-Video->Width)*(Video->Pixel.BitCount >> 3); } else { // native portrait device if ((Dir & DIR_SWAPXY) && MovedSIP) // don't adjust for RotM (SIP stays on native bottom)
void SortInt(int *value0, int *value1) { if(*value1 < *value0) { SwapInt(value0, value1); } }
void Shuffle(int *array, int count) { int i; for (i = 0; i < count; i++) { int r = RandomInt(0, count - 1); SwapInt(&array[i], &array[r]); } }
void Shuffle(int *deck, int size) { int i; for(i = 0; i < size; i++){ deck[i] = i; /* Deal a deck ! */ } for(i = 0; i < size/2; i++){ /* shuffle the deck */ SwapInt(& deck[Rnd(0, size - 1)], & deck[Rnd(0, size - 1)]); } }
void BubbleSort(int n,int x[]) { // (Modify this function so that the lines about to be swapped are drawn red) int i,j; for(i=0; i<n; i++) { for(j=i+1; j<n; j++) { Show(n, x, i, j); if(x[i]>x[j]) { SwapInt(x[i],x[j]); } } } Show(n,x,-1,-1); // You can leave this line as is. You’ll see the first line red in the end. }
/* In order to get anything measurable at all, we have to call it * a lot of times, so we run loop of several million iterations * so we have some validity to our numbers. */ int main(int argc, char **argv) { int i, nums[2]; if (argc < 2) { printf("This programs needs an argument for which version to use.\n"); printf("Either int for hard-code or any for generic.\n"); exit(-1); } if (strcmp(argv[1], "int") == 0) { for (i = 0; i < NUM_TRIALS; i++) SwapInt(&nums[0], &nums[1]); } else if (strcmp(argv[1], "any") == 0) { for (i = 0; i < NUM_TRIALS; i++) SwapAny(&nums[0], &nums[1], sizeof(nums[0])); } else { printf("Not a valid choice! int or any only.\n"); exit(-1); } return 0; }
static int Init(gapi* p) { GXDisplayProperties Info; video GDI; int Caps = QueryPlatform(PLATFORM_CAPS); if (!p->Opened) { ShowError(p->Overlay.Node.Class,GAPI_ID,GAPI_OPEN_ERROR); return ERR_NOT_SUPPORTED; // don't show device error } Info = p->Info; if (Info.cxWidth == GetSystemMetrics(SM_CXSCREEN) && Info.cyHeight < GetSystemMetrics(SM_CYSCREEN)) { // HPC devices we need the taskbar counted in the height too RECT WorkArea; SystemParametersInfo(SPI_GETWORKAREA,0,&WorkArea,0); if (WorkArea.top == 0 && WorkArea.bottom == Info.cyHeight) Info.cyHeight = GetSystemMetrics(SM_CYSCREEN); } p->Overlay.Output.Format.Video.Direction = 0; p->Overlay.Output.Format.Video.Aspect = ASPECT_ONE; if (Info.ffFormat & kfPalette) { QueryDesktop(&GDI); p->Overlay.Output.Format.Video.Pixel.Flags = PF_PALETTE; p->Overlay.Output.Format.Video.Pixel.BitCount = Info.cBPP; p->Overlay.Output.Format.Video.Pixel.Palette = GDI.Pixel.Palette; } else if (Info.ffFormat & kfDirect444) DefaultRGB(&p->Overlay.Output.Format.Video.Pixel,Info.cBPP,4,4,4,0,0,0); else if (Info.ffFormat & kfDirect565) { if (Caps & CAPS_ONLY12BITRGB) DefaultRGB(&p->Overlay.Output.Format.Video.Pixel,Info.cBPP,4,4,4,1,2,1); else DefaultRGB(&p->Overlay.Output.Format.Video.Pixel,Info.cBPP,5,6,5,0,0,0); } else if (Info.ffFormat & kfDirect555) DefaultRGB(&p->Overlay.Output.Format.Video.Pixel,Info.cBPP,5,5,5,0,0,0); else if (Info.ffFormat & kfDirect888) DefaultRGB(&p->Overlay.Output.Format.Video.Pixel,Info.cBPP,8,8,8,0,0,0); if (Info.ffFormat & kfDirectInverted) p->Overlay.Output.Format.Video.Pixel.Flags |= PF_INVERTED; // get signed x/y pitches in bits Info.cbxPitch <<= 3; Info.cbyPitch <<= 3; // one pitch is probably zero when BPP<8 if (!Info.cbxPitch) if (Info.cbyPitch < 0) Info.cbxPitch = -Info.cBPP; else Info.cbxPitch = Info.cBPP; else if (!Info.cbyPitch) if (Info.cbxPitch < 0) Info.cbyPitch = Info.cBPP; else Info.cbyPitch = -Info.cBPP; // one of the pitches absolute value must be BPP if (abs(Info.cbyPitch) < abs(Info.cbxPitch)) { if (abs(Info.cbxPitch) < Info.cyHeight*Info.cBPP && abs(Info.cbxPitch) >= Info.cxWidth*Info.cBPP) //swapped gapi resolution SwapInt(&Info.cxWidth,&Info.cyHeight); Info.ffFormat |= kfLandscape; Info.cbyPitch = Info.cbyPitch<0 ? -Info.cBPP : Info.cBPP; } else { if (abs(Info.cbyPitch) < Info.cxWidth*Info.cBPP && abs(Info.cbyPitch) >= Info.cyHeight*Info.cBPP) //swapped gapi resolution SwapInt(&Info.cxWidth,&Info.cyHeight); Info.ffFormat &= ~kfLandscape; Info.cbxPitch = Info.cbxPitch<0 ? -Info.cBPP : Info.cBPP; } p->Overlay.Output.Format.Video.Width = Info.cxWidth; p->Overlay.Output.Format.Video.Height = Info.cyHeight; // we need the physical start of the framebuffer p->AdjustPtr = 0; if (Info.cbxPitch<0) p->AdjustPtr += (Info.cbxPitch * (Info.cxWidth-1)) >> 3; if (Info.cbyPitch<0) p->AdjustPtr += (Info.cbyPitch * (Info.cyHeight-1)) >> 3; if (Info.ffFormat & kfLandscape) { p->Overlay.Output.Format.Video.Direction |= DIR_SWAPXY; p->Overlay.Output.Format.Video.Pitch = abs(Info.cbxPitch) >> 3; SwapInt(&p->Overlay.Output.Format.Video.Width,&p->Overlay.Output.Format.Video.Height); if (Info.cbxPitch<0) p->Overlay.Output.Format.Video.Direction |= DIR_MIRRORUPDOWN; if (Info.cbyPitch<0) p->Overlay.Output.Format.Video.Direction |= DIR_MIRRORLEFTRIGHT; }
static int Init(benchresult* p) { node* Player = Context()->Player; node* Platform = Context()->Platform; node* Format; node* Input; node* VOutput; node* AOutput; winunit y; int i; int Frames; int Samples; int Bytes; tick_t Tick; tick_t OrigTick; point SizeSrc; point SizeDst; packetformat Video; packetformat Audio; tchar_t Buffer[256]; fraction f; p->TimeDate = GetTimeDate(); Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format)); Player->Get(Player,PLAYER_INPUT,&Input,sizeof(Input)); VOutput = NULL; AOutput = NULL; OrigTick = 0; Frames = 0; Samples = 0; Bytes = 0; memset(&Video,0,sizeof(Video)); memset(&Audio,0,sizeof(Audio)); stprintf_s(p->Log,TSIZEOF(p->Log),LangStrDef(BENCHRESULT_ID,BENCHRESULT_LOG),Context()->ProgramName,Context()->ProgramVersion); tcscat_s(p->Log,TSIZEOF(p->Log),T("\n\n")); if (Format) { int No; pin Pin; packetformat PacketFormat; Format->Get(Format,FORMAT_FILEPOS,&Bytes,sizeof(Bytes)); for (No=0;Format->Get(Format,FORMAT_STREAM+No,&Pin,sizeof(Pin))==ERR_NONE;++No) if (Pin.Node && Format->Get(Format,(FORMAT_STREAM+No)|PIN_FORMAT,&PacketFormat,sizeof(PacketFormat))==ERR_NONE) { if (PacketFormat.Type == PACKET_VIDEO) { Video = PacketFormat; Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput)); if (VOutput) VOutput->Get(VOutput,OUT_TOTAL,&Frames,sizeof(Frames)); } if (PacketFormat.Type == PACKET_AUDIO) { Audio = PacketFormat; Player->Get(Player,PLAYER_AOUTPUT,&AOutput,sizeof(AOutput)); if (AOutput) { packetformat Format; AOutput->Get(AOutput,OUT_TOTAL,&Samples,sizeof(Samples)); if (AOutput->Get(AOutput,OUT_INPUT|PIN_FORMAT,&Format,sizeof(Format))==ERR_NONE && Format.Type == PACKET_AUDIO) { if (Format.Format.Audio.Bits>=8) Samples /= Format.Format.Audio.Bits/8; if (!(Format.Format.Audio.Flags & PCM_PLANES) && Format.Format.Audio.Channels) Samples /= Format.Format.Audio.Channels; } } } } } y = 4; Player->Get(Player,PLAYER_BENCHMARK,&Tick,sizeof(Tick)); if (Frames && Video.PacketRate.Num) OrigTick = Scale64(Frames,(int64_t)Video.PacketRate.Den*TICKSPERSEC,Video.PacketRate.Num); else if (Samples && Audio.Format.Audio.SampleRate) OrigTick = Scale(Samples,TICKSPERSEC,Audio.Format.Audio.SampleRate); if (Tick && OrigTick) { f.Num = OrigTick; f.Den = Tick; FractionToString(Buffer,TSIZEOF(Buffer),&f,1,2); AddItem(p,&y,BENCHRESULT_SPEED,Buffer); } if (Frames) { IntToString(Buffer,TSIZEOF(Buffer),Frames,0); AddItem(p,&y,BENCHRESULT_FRAMES,Buffer); } if (Samples) { IntToString(Buffer,TSIZEOF(Buffer),Samples,0); AddItem(p,&y,BENCHRESULT_SAMPLES,Buffer); } if (Bytes) { IntToString(Buffer,TSIZEOF(Buffer),Bytes/1024,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" KB")); AddItem(p,&y,BENCHRESULT_BYTES,Buffer); } y += 6; tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); TickToString(Buffer,TSIZEOF(Buffer),Tick,0,1,0); AddItem(p,&y,BENCHRESULT_TIME,Buffer); if (Frames && Tick) { f.Num = Frames; f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,2); AddItem(p,&y,BENCHRESULT_FPS,Buffer); } if (Samples && Tick) { f.Num = Samples; f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); AddItem(p,&y,BENCHRESULT_SRATE,Buffer); } if (Bytes && Tick) { f.Num = Scale(Bytes,8,1000); f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; if (f.Den && (f.Num/f.Den) > 1000) { Simplify(&f,MAX_INT,MAX_INT/1024); f.Den *= 1000; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s")); } else { FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s")); } AddItem(p,&y,BENCHRESULT_BANDWIDTH,Buffer); } y += 6; tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); if (OrigTick) { TickToString(Buffer,TSIZEOF(Buffer),OrigTick,0,1,0); AddItem(p,&y,BENCHRESULT_ORIG_TIME,Buffer); } if (Video.PacketRate.Num) { FractionToString(Buffer,TSIZEOF(Buffer),&Video.PacketRate,0,2); AddItem(p,&y,BENCHRESULT_ORIG_FPS,Buffer); } if (Audio.Format.Audio.SampleRate) { IntToString(Buffer,TSIZEOF(Buffer),Audio.Format.Audio.SampleRate,0); AddItem(p,&y,BENCHRESULT_ORIG_SRATE,Buffer); } if (Bytes && OrigTick) { f.Num = Scale(Bytes,8,1000); f.Den = OrigTick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; if (f.Den && (f.Num/f.Den) > 1000) { f.Den *= 1000; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s")); } else { FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s")); } AddItem(p,&y,BENCHRESULT_ORIG_BANDWIDTH,Buffer); } if (Frames && Samples) { y += 9; WinLabel(&p->Win,&y,-1,-1,LangStr(BENCHRESULT_ID,BENCHRESULT_MSG),11,0,NULL); } tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); if (Input && Input->Get(Input,STREAM_URL,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,BENCHRESULT_ID,BENCHRESULT_URL,Buffer); if (Input && Input->Get(Input,STREAM_LENGTH,&i,sizeof(i))==ERR_NONE) { IntToString(Buffer,TSIZEOF(Buffer),i,0); AddLog(p,BENCHRESULT_ID,BENCHRESULT_FILESIZE,Buffer); } if (Platform) { if (Platform->Get(Platform,PLATFORM_TYPE,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_TYPE,Buffer); if (Platform->Get(Platform,PLATFORM_VERSION,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_VERSION,Buffer); if (Platform->Get(Platform,PLATFORM_OEMINFO,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_OEMINFO,Buffer); ThreadSleep(GetTimeFreq()/10); if (Platform->Get(Platform,PLATFORM_CPUMHZ,&i,sizeof(i))==ERR_NONE) { IntToString(Buffer,TSIZEOF(Buffer),i,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mhz")); AddLog(p,PLATFORM_ID,PLATFORM_CPUMHZ,Buffer); } } if (VOutput) { tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(VOutput->Class,NODE_NAME)); if (VOutput->Get(VOutput,OUT_OUTPUT|PIN_FORMAT,&Video,sizeof(Video))==ERR_NONE) { if (Video.Format.Video.Direction & DIR_SWAPXY) SwapInt(&Video.Format.Video.Width,&Video.Format.Video.Height); stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dx%d %dbits"),Video.Format.Video.Width,Video.Format.Video.Height,Video.Format.Video.Pixel.BitCount); } if (QueryAdvanced(ADVANCED_SLOW_VIDEO)) tcscat_s(Buffer,TSIZEOF(Buffer),T(" Slow")); if (QueryAdvanced(ADVANCED_COLOR_LOOKUP)) tcscat_s(Buffer,TSIZEOF(Buffer),T(" Lookup")); AddLog(p,PLAYER_ID,PLAYER_VOUTPUT,Buffer); } if (Player->Get(Player,PLAYER_BENCHMARK_SRC,&SizeSrc,sizeof(point))==ERR_NONE && Player->Get(Player,PLAYER_BENCHMARK_DST,&SizeDst,sizeof(point))==ERR_NONE && SizeSrc.x>0 && SizeSrc.y>0) { stprintf_s(Buffer,TSIZEOF(Buffer),T("%dx%d -> %dx%d"),SizeSrc.x,SizeSrc.y,SizeDst.x,SizeDst.y); AddLog(p,BENCHRESULT_ID,BENCHRESULT_ZOOM,Buffer); } if (AOutput) { tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(AOutput->Class,NODE_NAME)); if (AOutput->Get(AOutput,OUT_OUTPUT|PIN_FORMAT,&Audio,sizeof(Audio))==ERR_NONE) stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dHz %dBits %dCh."),Audio.Format.Audio.SampleRate,Audio.Format.Audio.Bits,Audio.Format.Audio.Channels); AddLog(p,PLAYER_ID,PLAYER_AOUTPUT,Buffer); } return ERR_NONE; }
static int Update(ge2d* p) { blitfx OvlFX = p->p.FX; video Buffer; if (p->p.Overlay) PALMCALL0(API.GE2DHideOverlay); p->SoftFX = p->p.FX; p->SoftFX.ScaleX = SCALE_ONE; // scale handled by hardware p->SoftFX.ScaleY = SCALE_ONE; OvlFX.Direction = 0; //align to 100% if (OvlFX.ScaleX > SCALE_ONE-(SCALE_ONE/16) && OvlFX.ScaleX < SCALE_ONE+(SCALE_ONE/16) && OvlFX.ScaleY > SCALE_ONE-(SCALE_ONE/16) && OvlFX.ScaleY < SCALE_ONE+(SCALE_ONE/16)) { OvlFX.ScaleX = SCALE_ONE; OvlFX.ScaleY = SCALE_ONE; } if (p->SoftFX.Direction & DIR_SWAPXY) SwapInt(&OvlFX.ScaleX,&OvlFX.ScaleY); memset(&Buffer,0,sizeof(Buffer)); Buffer.Pixel.Flags = PF_YUV420; Buffer.Width = p->p.Input.Format.Video.Width; Buffer.Height = p->p.Input.Format.Video.Height; Buffer.Direction = CombineDir(p->p.InputDirection,p->p.OrigFX.Direction,p->p.Output.Format.Video.Direction); if (Buffer.Direction & DIR_SWAPXY) SwapInt(&Buffer.Width,&Buffer.Height); Buffer.Pitch = Buffer.Width; for (;;) { VirtToPhy(&p->p.Viewport,&p->p.DstAlignedRect,&p->p.Output.Format.Video); VirtToPhy(NULL,&p->OverlayRect,&Buffer); AnyAlign(&p->p.DstAlignedRect, &p->OverlayRect, &OvlFX, 2, 1, SCALE_ONE/256, SCALE_ONE*256); if ((OvlFX.ScaleX != SCALE_ONE || OvlFX.ScaleY != SCALE_ONE) && (p->p.DstAlignedRect.Width != p->OverlayRect.Width && p->p.DstAlignedRect.Height != p->OverlayRect.Height)) { if (!AllocBuffer(&p->Scale,p->p.DstAlignedRect.Width,p->p.DstAlignedRect.Height,&p->ScaleSize)) { // fallback to 100% OvlFX.ScaleX = SCALE_ONE; OvlFX.ScaleY = SCALE_ONE; continue; } } else FreeBuffer(&p->Scale,&p->ScaleSize); break; } VirtToPhy(NULL,&p->p.SrcAlignedRect,&p->p.Input.Format.Video); BlitRelease(p->p.Soft); p->p.Soft = BlitCreate(&Buffer,&p->p.Input.Format.Video,&p->SoftFX,&p->p.Caps); BlitAlign(p->p.Soft,&p->OverlayRect,&p->p.SrcAlignedRect); if (!AllocBuffer(&p->Buffer,p->OverlayRect.Width,p->OverlayRect.Height,&p->BufferSize)) return ERR_OUT_OF_MEMORY; Buffer.Width = p->OverlayRect.Width; Buffer.Height = p->OverlayRect.Height; Buffer.Pitch = Buffer.Width; p->OverlayRect.x = 0; p->OverlayRect.y = 0; BlitRelease(p->p.Soft); p->p.Soft = BlitCreate(&Buffer,&p->p.Input.Format.Video,&p->SoftFX,&p->p.Caps); BlitAlign(p->p.Soft,&p->OverlayRect,&p->p.SrcAlignedRect); if (!p->Scale.format) // no scaling -> adjust dst rectangle with soft yuv blitting alignement { p->p.DstAlignedRect.x += (p->p.DstAlignedRect.Width - p->OverlayRect.Width) >> 1; p->p.DstAlignedRect.y += (p->p.DstAlignedRect.Height - p->OverlayRect.Height) >> 1; p->p.DstAlignedRect.Width = p->OverlayRect.Width; p->p.DstAlignedRect.Height = p->OverlayRect.Height; }
ILboolean iReadRleSgi(iSgiHeader *Head) { #ifdef __LITTLE_ENDIAN__ ILuint ixTable; #endif ILuint ChanInt = 0; ILuint ixPlane, ixHeight,ixPixel, RleOff, RleLen; ILuint *OffTable=NULL, *LenTable=NULL, TableSize, Cur; ILubyte **TempData=NULL; if (!iNewSgi(Head)) return IL_FALSE; TableSize = Head->YSize * Head->ZSize; OffTable = (ILuint*)ialloc(TableSize * sizeof(ILuint)); LenTable = (ILuint*)ialloc(TableSize * sizeof(ILuint)); if (OffTable == NULL || LenTable == NULL) goto cleanup_error; if (iread(OffTable, TableSize * sizeof(ILuint), 1) != 1) goto cleanup_error; if (iread(LenTable, TableSize * sizeof(ILuint), 1) != 1) goto cleanup_error; #ifdef __LITTLE_ENDIAN__ // Fix the offset/len table (it's big endian format) for (ixTable = 0; ixTable < TableSize; ixTable++) { *(OffTable + ixTable) = SwapInt(*(OffTable + ixTable)); *(LenTable + ixTable) = SwapInt(*(LenTable + ixTable)); } #endif //__LITTLE_ENDIAN__ // We have to create a temporary buffer for the image, because SGI // images are plane-separated. */ TempData = (ILubyte**)ialloc(Head->ZSize * sizeof(ILubyte*)); if (TempData == NULL) goto cleanup_error; imemclear(TempData, Head->ZSize * sizeof(ILubyte*)); // Just in case ialloc fails then cleanup_error. for (ixPlane = 0; ixPlane < Head->ZSize; ixPlane++) { TempData[ixPlane] = (ILubyte*)ialloc(Head->XSize * Head->YSize * Head->Bpc); if (TempData[ixPlane] == NULL) goto cleanup_error; } // Read the Planes into the temporary memory for (ixPlane = 0; ixPlane < Head->ZSize; ixPlane++) { for (ixHeight = 0, Cur = 0; ixHeight < Head->YSize; ixHeight++, Cur += Head->XSize * Head->Bpc) { RleOff = OffTable[ixHeight + ixPlane * Head->YSize]; RleLen = LenTable[ixHeight + ixPlane * Head->YSize]; // Seeks to the offset table position iseek(RleOff, IL_SEEK_SET); if (iGetScanLine((TempData[ixPlane]) + (ixHeight * Head->XSize * Head->Bpc), Head, RleLen) != Head->XSize * Head->Bpc) { ilSetError(IL_ILLEGAL_FILE_VALUE); goto cleanup_error; } } } // DW: Removed on 05/25/2002. /*// Check if an alphaplane exists and invert it if (Head->ZSize == 4) { for (ixPixel=0; (ILint)ixPixel<Head->XSize * Head->YSize; ixPixel++) { TempData[3][ixPixel] = TempData[3][ixPixel] ^ 255; } }*/ // Assemble the image from its planes for (ixPixel = 0; ixPixel < iCurImage->SizeOfData; ixPixel += Head->ZSize * Head->Bpc, ChanInt += Head->Bpc) { for (ixPlane = 0; (ILint)ixPlane < Head->ZSize * Head->Bpc; ixPlane += Head->Bpc) { iCurImage->Data[ixPixel + ixPlane] = TempData[ixPlane][ChanInt]; if (Head->Bpc == 2) iCurImage->Data[ixPixel + ixPlane + 1] = TempData[ixPlane][ChanInt + 1]; } } #ifdef __LITTLE_ENDIAN__ if (Head->Bpc == 2) sgiSwitchData(iCurImage->Data, iCurImage->SizeOfData); #endif ifree(OffTable); ifree(LenTable); for (ixPlane = 0; ixPlane < Head->ZSize; ixPlane++) { ifree(TempData[ixPlane]); } ifree(TempData); return IL_TRUE; cleanup_error: ifree(OffTable); ifree(LenTable); if (TempData) { for (ixPlane = 0; ixPlane < Head->ZSize; ixPlane++) { ifree(TempData[ixPlane]); } ifree(TempData); } return IL_FALSE; }