MCPcopy Create free account
hub / github.com/DentonW/DevIL / encLine

Function encLine

DevIL/src-IL/src/il_pcx.cpp:687–737  ·  view source on GitHub ↗

This subroutine encodes one scanline and writes it to a file. It returns number of bytes written into outBuff, 0 if failed.

Source from the content-addressed store, hash-verified

685// This subroutine encodes one scanline and writes it to a file.
686// It returns number of bytes written into outBuff, 0 if failed.
687ILuint encLine(ILubyte *inBuff, ILint inLen, ILubyte Stride)
688{
689 ILubyte _this, last;
690 ILint srcIndex, i;
691 ILint total;
692 ILubyte runCount; // max single runlength is 63
693 total = 0;
694 runCount = 1;
695 last = *(inBuff);
696
697 // Find the pixel dimensions of the image by calculating
698 //[XSIZE = Xmax - Xmin + 1] and [YSIZE = Ymax - Ymin + 1].
699 //Then calculate how many bytes are in a "run"
700
701 for (srcIndex = 1; srcIndex < inLen; srcIndex++) {
702 inBuff += Stride;
703 _this = *(++inBuff);
704 if (_this == last) { // There is a "run" in the data, encode it
705 runCount++;
706 if (runCount == 63) {
707 if (! (i = encput(last, runCount)))
708 return (0);
709 total += i;
710 runCount = 0;
711 }
712 }
713 else { // No "run" - _this != last
714 if (runCount) {
715 if (! (i = encput(last, runCount)))
716 return(0);
717 total += i;
718 }
719 last = _this;
720 runCount = 1;
721 }
722 } // endloop
723
724 if (runCount) { // finish up
725 if (! (i = encput(last, runCount)))
726 return (0);
727 if (inLen % 2)
728 iputc(0);
729 return (total + i);
730 }
731 else {
732 if (inLen % 2)
733 iputc(0);
734 }
735
736 return (total);
737}
738
739#endif//IL_NO_PCX

Callers 1

iSavePcxInternalFunction · 0.85

Calls 1

encputFunction · 0.85

Tested by

no test coverage detected