| 319 | /*----------------------------------------------------------------------------*/ |
| 320 | |
| 321 | ILint iGetScanLine(ILubyte *ScanLine, iSgiHeader *Head, ILuint Length) |
| 322 | { |
| 323 | ILushort Pixel, Count; // For current pixel |
| 324 | ILuint BppRead = 0, CurPos = 0, Bps = Head->XSize * Head->Bpc; |
| 325 | |
| 326 | while (BppRead < Length && CurPos < Bps) |
| 327 | { |
| 328 | Pixel = 0; |
| 329 | if (iread(&Pixel, Head->Bpc, 1) != 1) |
| 330 | return -1; |
| 331 | |
| 332 | #ifndef __LITTLE_ENDIAN__ |
| 333 | iSwapUShort(&Pixel); |
| 334 | #endif |
| 335 | |
| 336 | if (!(Count = (Pixel & 0x7f))) // If 0, line ends |
| 337 | return CurPos; |
| 338 | if (Pixel & 0x80) { // If top bit set, then it is a "run" |
| 339 | if (iread(ScanLine, Head->Bpc, Count) != Count) |
| 340 | return -1; |
| 341 | BppRead += Head->Bpc * Count + Head->Bpc; |
| 342 | ScanLine += Head->Bpc * Count; |
| 343 | CurPos += Head->Bpc * Count; |
| 344 | } |
| 345 | else { |
| 346 | if (iread(&Pixel, Head->Bpc, 1) != 1) |
| 347 | return -1; |
| 348 | #ifndef __LITTLE_ENDIAN__ |
| 349 | iSwapUShort(&Pixel); |
| 350 | #endif |
| 351 | if (Head->Bpc == 1) { |
| 352 | while (Count--) { |
| 353 | *ScanLine = (ILubyte)Pixel; |
| 354 | ScanLine++; |
| 355 | CurPos++; |
| 356 | } |
| 357 | } |
| 358 | else { |
| 359 | while (Count--) { |
| 360 | *(ILushort*)ScanLine = Pixel; |
| 361 | ScanLine += 2; |
| 362 | CurPos += 2; |
| 363 | } |
| 364 | } |
| 365 | BppRead += Head->Bpc + Head->Bpc; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | return CurPos; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | /*----------------------------------------------------------------------------*/ |
no test coverage detected