home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / navody / DICOMSRC.ZIP / lsjpeg.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-31  |  21KB  |  503 lines

  1. unit lsjpeg;
  2. //{$DEFINE MRICRO}
  3. interface
  4. uses dialogs,sysutils,windows;
  5. type
  6.     HufRA = record
  7.            HufSz,HufCode,HufVal: Integer;
  8.     end;
  9.     ByteRA = array [1..1] of byte;
  10.     Bytep = ^ByteRA;
  11.     ByteRA0 = array [0..0] of byte;
  12.     Bytep0 = ^ByteRA0;
  13.     WordRA = array [1..1] of Word;
  14.     Wordp = ^WordRA;
  15. {$IFDEF MRICRO}
  16.     SmallIntRA = array [1..1] of SmallInt;
  17.     SMallIntp = ^SmallIntRA;
  18. {$ELSE}
  19.     SmallIntRA0 = array [0..0] of SmallInt;
  20.     SMallIntp0 = ^SmallIntRA0;
  21. {$ENDIF}
  22. {$IFDEF MRICRO}
  23. procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP; var lImgRAz: ByteP;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
  24. {$ELSE}
  25. procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
  26. {$ENDIF}
  27. implementation
  28.  
  29. {$IFDEF MRICRO}
  30. procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP; var lImgRAz: ByteP; lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
  31. {$ELSE}
  32. procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
  33. {$ENDIF}
  34.  
  35. label
  36.      666 {EOF};
  37.   var
  38.     lRawRA: bytep;
  39.     lImgRA: WordP;
  40.     lLineStart,lPredicted,lRestartSegmentSz,
  41.     lSz,k,Code,Si,lIncX,lIncY,lInc,lPredA,lPredB,lCurrentByteVal,lCurrentBitPos,btS1,btS2, btMarkerType,
  42.     DHTnLi,DHTtcth,SOFprecision,lMaxHufSi,lMaxHufVal,SOSpttrans, SOFnf,SOFarrayPos,SOSns,SOSarrayPos,SOSss,SOSse,SOSahal:integer;//byte;
  43.     lDecode,lImgStart,lRawSz,lRawPos,lItems,SOFydim, SOFxdim: integer;
  44.     DHTLiRA,DHTstartRA: array [0..31] of integer;//byte;
  45.     lHufRA: array [0..31] of HufRA;
  46.     lSegmentLength,lSegmentEnd,lI: integer;
  47.     lImgTypeC3,lHdrOK: boolean;
  48.  
  49. function ReadBit: integer;
  50. begin
  51.      if lCurrentBitPos > 8 then begin
  52.         if lCurrentByteVal = $FF then begin
  53.            inc(lRawPos);
  54.            if (lRawRA[lRawPos] <> 0) {and (lEOFX = 0)} then begin
  55.              //while (lRawRA[lRawPos] <> $D9) and (lRawRA[lRawPos] <> 0) do
  56.              //      inc(lRawPos);
  57.              {if (lRawRA[lRawPos] >= $D0) and (lRawRA[lRawPos] <= $D7) then begin
  58.                    lRestart := lRawPos;
  59.                    //inc(lRawPos); //restart marker
  60.              end;}
  61.               {if  (lRawRA[lRawPos] = $D9) then begin
  62.                   //lEOFX := lIncX;
  63.                   showmessage('end of file');
  64.               end;}
  65. //if lRabbi then             showmessage(inttostr(lRawPos) )
  66.                {
  67.               +':'+inttostr(lRawRA[lRawPos+2] )
  68.               +':'+inttostr(lRawRA[lRawPos+3] )
  69.               +':'+inttostr(lRawRA[lRawPos+4] )
  70.               +':'+inttostr(lRawRA[lRawPos+5] )
  71.               +':'+inttostr(lRawRA[lRawPos+6] )
  72.               +'Data is not zero padded.'+inttostr(lRawPos));;}
  73.            end;
  74.            (*error checking: significantly slows function
  75.            {if (lRawRA[lRawPos] <> 0) then begin
  76.               if  (lRawRA[lRawPos] = $D9) and (lEOFX=0) then begin
  77.                lEOFX := lIncX;
  78.               end; { else
  79.                    showmessage('Data is not zero padded.');
  80.                end; }
  81.            end; (**)//not 0 padded
  82.         end; //$FF = skip a byte
  83.         inc(lRawPos);
  84.         if lRawPos < lRawSz then //little time penalty for this check
  85.         lCurrentByteVal := lRawRA[lRawPos];
  86.         result := (lCurrentByteVal shr 7);
  87.         lCurrentBitPos := 2;
  88.      end else begin
  89.          result := 1 and (lCurrentByteVal shr (8-lCurrentBitPos));
  90.          inc(lCurrentBitPos);
  91.      end;
  92. end; (* *)
  93.  
  94. (*function ReadBit: byte;
  95. begin
  96.      if lCurrentBitPos =1 then begin
  97.         if lCurrentByteVal = $FF then begin
  98.            inc(lRawPos);
  99.            lCurrentByteVal := 0;
  100.            if (lRawRA[lRawPos] <> 0) then begin
  101.               if  (lRawRA[lRawPos] = $D9) and (lEOFX=0) then begin
  102.                lEOFX := lIncX;
  103.               end; { else
  104.                    showmessage('Data is not zero padded.');
  105.                end; }
  106.            end; //not 0 padded
  107.         end; //FF
  108.            inc(lRawPos);
  109.            if lRawPos < lRawSz then
  110.            lCurrentByteVal := lRawRA[lRawPos];
  111.            result := (lCurrentByteVal shr 7);
  112.      end else
  113.          result := 1 and (lCurrentByteVal shr (8-lCurrentBitPos));
  114.      inc(lCurrentBitPos);
  115.      if lCurrentBitPos = 9 then lCurrentBitPos := 1;
  116. end;(**)
  117.  
  118. function DecodePixelDifference: integer;//qwsmallint;}
  119. var
  120.    lInput,lInputbits,lHufVal,lDiff,lI: integer;
  121. begin
  122. lHufVal := 666;
  123. lInput := 0;
  124. lInputBits := 0;
  125. repeat
  126.       Inc(lInputBits);
  127.       lInput := lInput shl 1 + ReadBit;
  128.       if DHTLiRA[lInputBits] <> 0 then begin
  129.          for lI := DHTstartRA[lInputBits] to (DHTstartRA[lInputBits]+DHTLiRA[lInputBits]-1) do begin
  130.             if (lInput = lHufRA[lI].HufCode) then
  131.              lHufVal := lHufRA[lI].HufVal;
  132.          end; //check each code
  133.       end; //if possible at this length
  134.       //a if lInputBits >= lMaxHufSi then//exhausted options
  135.       //a   lHufVal := lMaxHufVal;
  136.       if lInputBits >= lMaxHufSi then//exhausted options
  137.          lHufVal := lMaxHufVal;
  138. until (lHufVal < 255){found};
  139.      case lHufVal of
  140.           0: result:= 0;
  141.           1: if ReadBit = 0 then result := -1 else result := 1;
  142.           2..15: begin
  143.                  lDiff := 0;
  144.               if ReadBit = 1 then begin  //read signbit Positive value
  145.                  for lI := 1 to (lHufVal - 1) do
  146.                      lDiff := (lDiff shl 1) + ReadBit;
  147.                  result := lDiff + (1 shl (lHufval-1));
  148.               end else begin
  149.                   for lI := 1 to (lHufVal - 1) do
  150.                      lDiff := (lDiff shl 1) + 1 - ReadBit;
  151.                  result := -(lDiff + (1 shl (lHufval-1)));
  152.                  //lDiff := -(lDiff);
  153.               end;
  154.           end;
  155.           else {16:} result := 32768;
  156.           //else showmessage('Terminal decoder error. HufVal = '+inttostr(lHufVal));//lDiff := -666;
  157.      end; //case HuffVal
  158.      //result := lDiff;
  159. end;
  160.  
  161. procedure ReadByte(var lByte: integer);
  162. begin
  163.      inc(lRawPos);
  164.      lByte := lRawRA[lRawPos];
  165. end;
  166.  
  167. function ReadWord: word;
  168. var
  169.    lbtL1, lbtL2: byte;
  170. begin
  171.      inc(lRawPos);
  172.      lbtL1 := lRawRA[lRawPos];
  173.      inc(lRawPos);
  174.      lbtL2 := lRawRA[lRawPos];
  175.      result := (256 * lbtL1 + lbtL2)
  176. end;
  177.   begin
  178.     lRawSz := lCptSize;
  179.     lRawPos := 0;
  180.     lRestartSegmentSz := 0;
  181.     lImgTypeC3 := false;
  182.     SOFxdim:= 1;
  183.     if lRawSz < 32 then goto 666;
  184.     for lInc := 1 to 16 do
  185.         DHTstartRA[lInc] := 0;
  186.     SOFydim := 1;
  187.     SOSpttrans := 0;
  188.     lHdrOK := false;
  189.     SOFnf := 0;
  190.     SOSns := 0;
  191.     Seek(infp,lCptPosition);
  192.     GetMem( lRawRA, lRawSz);
  193.     BlockRead(infp, lRawRA^, lRawSz);
  194.     ReadByte(btS1);
  195.     ReadByte(btS1);
  196.     repeat
  197.       repeat
  198.             if lRawPos <= lRawSz then ReadByte(btS1);
  199.             if btS1 <> $FF then begin
  200.                goto 666;
  201.             end;
  202.             if lRawPos <= lRawSz then  ReadByte( btMarkerType);
  203.             case btMarkerType of //only process segments with length fields
  204.                  $0,$1,$D0..$D7,$FF: btMarkerType := 0; //0&FF = fillers, $1=TEM,$D0..D7=resync
  205.             end;
  206.       until (lRawPos >= lRawSz) or (btMarkerType <> 0);
  207.       lSegmentLength := ReadWord;
  208.       lSegmentEnd := lRawPos+(lSegmentLength - 2);
  209.       if lSegmentEnd > lRawSz then goto 666;
  210.       if (btMarkerType = $C3)  then
  211.          lImgTypeC3 := true;
  212.        if lverbose then showmessage( {result+}inttohex(btMarkerType,2){':'+inttostr( lSegmentLength )+'@'+inttostr(positon)+' '});
  213.       case btMarkerType of
  214.            $0: ; //filler - ignore
  215.            $C0..$C3,$C5..$CB,$CD..$CF: begin //read SOF FrameHeader
  216.              ReadByte(SOFprecision);
  217.              SOFydim := ReadWord;
  218.              SOFxdim:= ReadWord;
  219.              ReadByte(SOFnf);
  220.              if lverbose then Showmessage('[precision:'+inttostr(SOFprecision)+' X*Y:'+inttostr(SOFxdim)+'*'+inttostr(SOFydim)+'nFrames:'+inttostr(SOFnf)+'] ');
  221.              if (not lImgTypeC3) or (SOFnf > 1) then begin
  222.                  showmessage('Unable to extract this file format.');
  223.              end;
  224.              SOFarrayPos := lRawPos;
  225.              lRawPos := (lSegmentEnd);
  226.            end; //SOF FrameHeader
  227.            $C4: begin //DHT Huffman
  228.               if lverbose then showmessage( 'HuffmanLength'+inttostr(lSegmentLength)+':');
  229.              ReadByte( DHTtcth);
  230.              DHTnLi := 0;
  231.              for lInc := 1 to 16 do begin
  232.                  ReadByte(DHTliRA[lInc]);
  233.                  DHTnLi := DHTnLi +  DHTliRA[lInc];
  234.                  if DHTliRA[lInc] <> 0 then lMaxHufSi := lInc;
  235.              end;
  236.              if DHTnLi > 17 then begin
  237.                 showmessage('Huffman table corrupted.');
  238.                 goto 666;
  239.              end;
  240.              lIncY := 0; //frequency
  241.              for lInc := 1 to 16 do begin //set the huffman size values
  242.                  if DHTliRA[lInc]> 0 then begin
  243.                      DHTstartRA[lInc] := lIncY+1;
  244.                      for lIncX := 1 to DHTliRA[lInc] do begin
  245.                          inc(lIncY);
  246.                          ReadByte(btS1);
  247.                          lHufRA[lIncY].HufVal := btS1;
  248.                          lMaxHufVal := btS1;
  249.                          if (btS1 >= 0) and (btS1 <= 16) then
  250.                            lHufRA[lIncY].HufSz := lInc
  251.                          else begin
  252.                             showmessage('Huffman size array corrupted.');
  253.                             goto 666;
  254.                          end; {}
  255.                      end;
  256.                  end; //Length of size lInc > 0
  257.              end;
  258.              K := 1;
  259.              Code := 0;
  260.              Si := lHufRA[K].HufSz;//HuffSizeRA[1];
  261.              repeat
  262.                    while (Si = lHufRA[K].HufSz) do begin
  263.                          lHufRA[K].HufCode := Code;
  264.                          Code := Code + 1;
  265.                          Inc(K);
  266.                    end;
  267.                    if K <= DHTnLi then begin
  268.                       while lHufRA[K].HufSz > Si do begin
  269.                             Code := Code Shl 1;
  270.                             Si := Si + 1;
  271.                       end; //while Si
  272.                    end; //K <= 17
  273.              until K >= DHTnLi;
  274.              lRawPos := (lSegmentEnd);
  275.            end; //DHT Huffman
  276.             $DD: begin  //Define Restart
  277.                lRestartSegmentSz := Readword;
  278.                lRawPos := (lSegmentEnd);
  279.            end;
  280.            $DA: begin //read SOS Scan Header
  281.              if SOSns > 0 then goto 666; //multiple SOS!
  282.              ReadByte(SOSns);
  283.              //if Ns = 1 then NOT interleaved, else interleaved: see B.2.3
  284.              SOSarrayPos := lRawPos;
  285.              if SOSns > 0 then begin
  286.                  for lInc := 1 to SOSns do begin
  287.                      ReadByte( btS1); //component identifier 1=Y,2=Cb,3=Cr,4=I,5=Q
  288.                      ReadByte(btS2); //horizontal and vertical sampling factors
  289.                  end;
  290.              end;
  291.              ReadByte(SOSss); //predictor selection B.3
  292.              ReadByte( SOSse);
  293.              ReadByte( SOSahal); //lower 4bits= pointtransform
  294.              SOSpttrans := SOSahal and 16;
  295.              if lverbose then Showmessage('[Predictor: '+inttostr(SOSss)+' PointTransform:'+inttostr(SOSahal)+'] ');
  296.              lRawPos := (lSegmentEnd);
  297.            end; //SOS - Scan Header
  298.            else begin //skip marker segment;
  299.                 lRawPos := (lSegmentEnd);
  300.            end;
  301.       end; //case markertype
  302.     until (lRawPos >= lRawSz) or (btMarkerType = $DA); {hexDA=Start of scan}
  303.     lHdrOK := true; //errors goto label 666, so are NOT OK
  304.     lImgStart := lRawPos;
  305. 666:
  306.     if not lHdrOK then begin
  307.        showmessage('Unable to read this file - is it really a JPEG image?');
  308.        exit;
  309.     end;
  310.     lItems :=  SOFxdim*SOFydim;
  311.     if SOFPrecision = 8 then
  312.        lSz := 1
  313.     else
  314.         lSz := 2;
  315.     if (lImgTypeC3) and ((lItems *lSz) = lOutPutSz) then begin //loss compressed huffman tables
  316.        lCurrentByteVal := SOSahal;
  317.        if (lRestartSegmentSz > 0) and ((SOFPrecision<> 8) or (SOSss = 7)) then //add restart support if we evr find any samples to test
  318.           showmessage('This image may uses restart markers. Please contact the author.');
  319.        //z never used lSOI := lRawPos;
  320.        //lnRestart := 0;
  321.        //if (SOFPrecision<> 8) and (SOSss = 7) then showmessage('ABBA : predictor = 7');
  322.        lCurrentByteVal := SOSahal;
  323.        //lEOFX := 0;
  324.        //lRestart := 0;
  325.        lCurrentBitPos := 9; //read in a new byte
  326.        //lCurrentBitPos := 1; //read in a new byte
  327.        lItems :=  SOFxdim*SOFydim;
  328.        lINc := 0;
  329.        lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans);
  330.        //showmessage(inttostr(lpredicted));
  331.        //showmessage(inttostr(SOSss)+'abba'+inttostr(SOFprecision));
  332.        if (SOFPrecision<> 8) then begin //start
  333.           {$IFDEF MRICRO}
  334.           lImgRA := @lOutSmallRA[1];{set to 1 for MRIcro}
  335.           {$ELSE}
  336.           lImgRA := @lOutSmallRA[0];{set to 1 for MRIcro, else 0}
  337.           {$ENDIF}
  338.           FillChar(lImgRA^,lItems*sizeof(word), 0); //zero array
  339.           for lIncX := 1 to SOFxdim do begin
  340.               inc(lInc); //writenext voxel
  341.               if lInc > 1 then lPredicted := lImgRA[lInc-1];
  342.               lImgRA[lInc] := lPredicted+DecodePixelDifference;
  343.           end; //first line: use prev voxel prediction;
  344.           if SOFyDim > 1 then
  345.              for lIncY := 2 to SOFyDim do begin
  346.                  inc(lInc); //write next voxel
  347.                  lPredicted := lImgRA[lInc-SOFxdim];
  348.                  lImgRA[lInc] := lPredicted+DecodePixelDifference;
  349.                  if SOSss = 7 then begin
  350.                     for lIncX := 2 to SOFxdim do begin
  351.                         inc(lInc); //writenext voxel
  352.                         lPredA := lImgRA[lInc-1];
  353.                         lPredB := lImgRA[lInc-SOFxdim];
  354.                         lPredA := (lPredA+lPredB) shr 1;
  355.                         lPredicted := lPredA;
  356.                         lImgRA[lInc] := lPredicted+DecodePixelDifference;
  357.                     end; //for lIncX
  358.                  end else begin //SOSss <> 7 -> predictor
  359.                      for lIncX := 2 to SOFxdim do begin
  360.                          inc(lInc); //writenext voxel
  361.                          lPredicted := lImgRA[lInc-1];
  362.                          lImgRA[lInc] := lPredicted+DecodePixelDifference;
  363.                      end; //for lIncX
  364.                  end;  //SOSss predictor
  365.                  (*if lEOFX <> 0 then begin
  366.                  showmessage('EOF reached prematurely'+inttostr(lRawPos-lSOI)+' X*Y='+inttostr(lEOFX)+'*'+inttostr(lIncY));
  367.                  goto 127;
  368.                  end;*)
  369.              end; //for lIncY
  370.        end else begin //>8bit data; 8 bit follows
  371.               {$IFDEF MRICRO}
  372.               lInc := 1;
  373.               {$ENDIF}
  374.               for lIncX := 1 to SOFxdim do begin //write first line
  375.                   //if lInc > 0 then lPredicted := lImgRAz[lInc-1];
  376.                   lImgRAz[lInc] := lPredicted+DecodePixelDifference;
  377.                   inc(lInc); //writenext voxel
  378.                   lPredicted := lImgRAz[lInc-1];
  379.  
  380.               end; //first line: use prev voxel prediction;
  381.               if lRestartSegmentSz = 0 then lSegmentEnd := lItems
  382.               else lSegmentEnd := lRestartSegmentSz;
  383.               //lLineStart := lInc;
  384.               repeat
  385.                     if lSegmentEnd > lItems then lSegmentEnd := lItems;
  386.                     lLineStart := (((lInc div SOFxDim)+1)* SOFxDim){-1};
  387.                     if lInc > (SOFxDim+1) then
  388.                        lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans)
  389.                     else
  390.                         lPredicted := lImgRAz[lInc-SOFxdim];
  391.                if SOSss = 7 then begin
  392.                     for lInc := lInc to (lSegmentEnd-1) do begin
  393.                       lDecode := DecodePixelDifference;
  394.                       lImgRAz[lInc] := lPredicted+lDecode;
  395.                       if lInc+1 = lLineStart then begin//newline
  396.                         lPredicted := lImgRAz[lInc+1-SOFxdim];
  397.                         lLineStart := lLineStart + SOFxDim;
  398.                       end else begin
  399.                           lPredA := lImgRAz[lInc-1];
  400.                           lPredB := lImgRAz[lInc-SOFxdim];
  401.                           lPredA := (lPredA+lPredB) shr 1;
  402.                           lPredicted := lPredA;
  403.                       //                        lPredicted := lImgRAz[lInc];
  404.                       end;
  405.                       //inc(lInc); //writenext voxel
  406.                     end;
  407.                end else begin //predictor <> 7
  408.                     for lInc := lInc to (lSegmentEnd-1) do begin
  409.                       lDecode := DecodePixelDifference;
  410.                       lImgRAz[lInc] := lPredicted+lDecode;
  411.                       if lInc+1 = lLineStart then begin//newline
  412.                         lPredicted := lImgRAz[lInc+1-SOFxdim];
  413.                         lLineStart := lLineStart + SOFxDim;
  414.                       end else
  415.                         lPredicted := lImgRAz[lInc];
  416.                       //inc(lInc); //writenext voxel
  417.                     end;
  418.                end; //predictor <> 7
  419.                     if (lSegmentEnd+1) < lItems then begin
  420.                         dec(lRawPos);
  421.                         repeat
  422.                               while (lRawRA[lRawPos] <> 255) do
  423.                                     inc(lRawPos);
  424.                               inc(lRawPos);
  425.                         until (lRawRA[lRawPos] >= $D0) and (lRawRA[lRawPos] <= $D7);
  426.                         lCurrentByteVal := 0; //not FF
  427.                         lCurrentBitPos := 9; //read in a new byte
  428.                     end;
  429.                     lSegmentEnd := lSegmentEnd + lRestartSegmentSz;
  430.               until (lRestartSegmentSz < 1) or ((lSegmentEnd-2) > lItems);
  431.  
  432.  
  433.               (*if SOFyDim > 1 then
  434.                  for lIncY := 2 to SOFyDim do begin
  435.                   //for X = 1 use above voxel for predictor, except if Y=1
  436.                   lPredicted := lImgRAz[lInc-SOFxdim];
  437.                   lDecode := DecodePixelDifference;
  438.                   if (lRestart <> 0) then begin
  439.                              lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans);
  440.                              lCurrentBitPos := 9; //read in a new byte
  441.                              lRawPos := lRestart;
  442.                              lDecode := DecodePixelDifference;
  443.                              lRestart := 0;
  444.                               inc(lnRestart);
  445.                               //lRestartRA[lnRestart] := lInc;
  446.                   end;
  447.                   lImgRAz[lInc] := lPredicted+lDecode;
  448.                   inc(lInc); //write next voxel
  449.                   if SOSss = 7 then begin
  450.                      for lIncX := 2 to SOFxdim do begin
  451.                          lPredA := lImgRAz[lInc-1];
  452.                          lPredB := lImgRAz[lInc-SOFxdim];
  453.                          lPredA := (lPredA+lPredB) shr 1;
  454.                          lPredicted := lPredA;
  455.                          lImgRAz[lInc] := lPredicted+DecodePixelDifference;
  456.                          inc(lInc); //writenext voxel
  457.                      end; //for lIncX
  458.                   end else begin //SOSss <> 7  predictor
  459.                       lIncX := 1;
  460.                       while lIncX < SOFXdim do begin
  461.                       //for lIncX := 2 to SOFxdim do begin
  462.                             inc(lIncX);
  463.                           lPredicted := lImgRAz[lInc-1];
  464.                           lDecode := DecodePixelDifference;
  465.                           if (lRestart <> 0) then begin
  466.                              //if lIncX <> 2 then
  467.                              lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans);
  468.                              //lpredicted := 0;
  469.                              lCurrentBitPos := 9; //read in a new byte
  470.                              lRawPos := lRestart;
  471.                              lDecode := DecodePixelDifference;
  472.                              lRestart := 0;
  473.  
  474.                              dec(lInc);
  475.                              inc(lnRestart);
  476.                              //lRestartRA[lnRestart] := lInc;
  477.                              dec(lIncX);
  478.  
  479.                               //showmessage('restart');
  480.                           end;
  481.                           lImgRAz[lInc] := lPredicted+lDecode;
  482.                           //X problem here
  483.                           inc(lInc); //writenext voxel
  484.                       end; //for lIncX
  485.                   end; //SOSss = 7
  486.                  end; //for lIncY *)
  487.            end; //8<>15data type
  488.        end; //ImageType C3 lossless HUFffman compressed
  489.  
  490.        (*if lnRestart > 0 then begin
  491.            lStr := '';
  492.            lSz := 0;
  493.            for k := 1 to lnRestart do begin
  494.                lStr := lStr + inttostr(lRestartRA[k]-lSz)+':';
  495.                lSz := lRestartRA[k];
  496.            end;
  497.            showmessage(lStr);
  498.  
  499.        end; *)
  500. end;
  501.  
  502. end.
  503.