Changeset 494 for GraphicTest/Packages/bgrabitmap/bgrastreamlayers.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrastreamlayers.pas
r472 r494 17 17 implementation 18 18 19 uses BGRABitmapTypes, BGRACompressableBitmap, zstream, BGRAReadLzp, BGRAWriteLzp; 19 uses BGRABitmapTypes, BGRACompressableBitmap, zstream, BGRAReadLzp, BGRAWriteLzp, 20 BGRAUTF8; 20 21 21 22 procedure SaveLayeredBitmapToStream(AStream: TStream; ALayers: TBGRACustomLayeredBitmap); … … 37 38 StreamMaxLayerCount = 4096; 38 39 StreamMaxHeaderSize = 256; 39 40 {$i winstream.inc}41 40 42 41 function CheckStreamForLayers(AStream: TStream): boolean; … … 91 90 92 91 //header size 93 HeaderSize:= WinReadLongint(AStream);92 HeaderSize:= LEReadLongint(AStream); 94 93 if (HeaderSize < 12) or (HeaderSize > StreamMaxHeaderSize) then 95 94 raise exception.Create('Invalid header size'); 96 95 LayerStackStartPosition := AStream.Position + HeaderSize; 97 96 98 NbLayers:= WinReadLongint(AStream);97 NbLayers:= LEReadLongint(AStream); 99 98 if (NbLayers < 0) or (NbLayers > StreamMaxLayerCount) then 100 99 raise exception.Create('Invalid layer count'); 101 100 102 ASelectedLayerIndex:= WinReadLongint(AStream);101 ASelectedLayerIndex:= LEReadLongint(AStream); 103 102 if (ASelectedLayerIndex < -1) or (ASelectedLayerIndex >= NbLayers) then 104 103 raise exception.Create('Selected layer out of bounds'); 105 104 106 StackOption := WinReadLongint(AStream);105 StackOption := LEReadLongint(AStream); 107 106 result.LinearBlend := (StackOption and 1) = 1; 108 107 if (StackOption and 2) = 2 then Compression := lzpRLE else Compression:= lzpZStream; … … 112 111 for i := 0 to NbLayers-1 do 113 112 begin 114 LayerHeaderSize:= WinReadLongint(AStream);113 LayerHeaderSize:= LEReadLongint(AStream); 115 114 LayerHeaderPosition := AStream.Position; 116 115 LayerBitmapPosition := LayerHeaderPosition + LayerHeaderSize; … … 126 125 if AStream.Position <= LayerBitmapPosition-4 then 127 126 begin 128 LayerOption := WinReadLongint(AStream);127 LayerOption := LEReadLongint(AStream); 129 128 LayerVisible := (LayerOption and 1) = 1; 130 129 end; 131 130 if AStream.Position <= LayerBitmapPosition-4 then 132 LayerBlendOp := TBlendOperation( WinReadLongint(AStream));131 LayerBlendOp := TBlendOperation(LEReadLongint(AStream)); 133 132 134 133 if AStream.Position <= LayerBitmapPosition-8 then 135 134 begin 136 LayerOffset := Point( WinReadLongint(AStream),WinReadLongint(AStream));135 LayerOffset := Point(LEReadLongint(AStream),LEReadLongint(AStream)); 137 136 if AStream.Position <= LayerBitmapPosition-4 then 138 137 begin 139 LayerId := WinReadLongint(AStream);138 LayerId := LEReadLongint(AStream); 140 139 LayerIdFound := true; 141 140 end; 142 141 if AStream.Position <= LayerBitmapPosition-4 then 143 LayerOpacity := WinReadLongint(AStream) shr 8;142 LayerOpacity := LEReadLongint(AStream) shr 8; 144 143 end; 145 144 if AStream.Position <= LayerBitmapPosition-4 then 146 145 begin 147 LayerBitmapSize := WinReadLongint(AStream);146 LayerBitmapSize := LEReadLongint(AStream); 148 147 LayerEndPosition:= LayerBitmapPosition+LayerBitmapSize; 149 148 end; … … 186 185 raise exception.Create('Selected layer out of bounds'); 187 186 AStream.Write(StreamHeader[1], length(StreamHeader)); 188 WinWriteLongint(AStream, 12); //header size189 WinWriteLongint(AStream, ALayers.NbLayers);190 WinWriteLongint(AStream, ASelectedLayerIndex);187 LEWriteLongint(AStream, 12); //header size 188 LEWriteLongint(AStream, ALayers.NbLayers); 189 LEWriteLongint(AStream, ASelectedLayerIndex); 191 190 StackOption := 0; 192 191 if ALayers.LinearBlend then StackOption := StackOption or 1; 193 192 if ACompression = lzpRLE then StackOption:= StackOption or 2; 194 WinWriteLongint(AStream, StackOption);193 LEWriteLongint(AStream, StackOption); 195 194 //end of header 196 195 … … 198 197 begin 199 198 LayerHeaderSizePosition:= AStream.Position; 200 WinWriteLongint(AStream, 0); //header size not computed yet199 LEWriteLongint(AStream, 0); //header size not computed yet 201 200 LayerHeaderPosition := AStream.Position; 202 201 203 202 LayerOption := 0; 204 203 if ALayers.LayerVisible[i] then LayerOption:= LayerOption or 1; 205 WinWriteLongint(AStream, LayerOption);206 WinWriteLongint(AStream, Longint(ALayers.BlendOperation[i]));207 WinWriteLongint(AStream, ALayers.LayerOffset[i].x);208 WinWriteLongint(AStream, ALayers.LayerOffset[i].y);209 WinWriteLongint(AStream, ALayers.LayerUniqueId[i]);210 WinWriteLongint(AStream, integer(ALayers.LayerOpacity[i])*$101);204 LEWriteLongint(AStream, LayerOption); 205 LEWriteLongint(AStream, Longint(ALayers.BlendOperation[i])); 206 LEWriteLongint(AStream, ALayers.LayerOffset[i].x); 207 LEWriteLongint(AStream, ALayers.LayerOffset[i].y); 208 LEWriteLongint(AStream, ALayers.LayerUniqueId[i]); 209 LEWriteLongint(AStream, integer(ALayers.LayerOpacity[i])*$101); 211 210 LayerBitmapSizePosition:=AStream.Position; 212 WinWriteLongint(AStream, 0);211 LEWriteLongint(AStream, 0); 213 212 LayerBitmapPosition:=AStream.Position; 214 213 LayerHeaderSize := LayerBitmapPosition - LayerHeaderPosition; 215 214 AStream.Position:= LayerHeaderSizePosition; 216 WinWriteLongint(AStream, LayerHeaderSize);215 LEWriteLongint(AStream, LayerHeaderSize); 217 216 //end of layer header 218 217 … … 231 230 raise exception.Create('Image too big'); 232 231 AStream.Position:= LayerBitmapSizePosition; 233 WinWriteLongint(AStream, BitmapSize);232 LEWriteLongint(AStream, BitmapSize); 234 233 AStream.Position:= LayerBitmapPosition+BitmapSize; 235 234 end;
Note:
See TracChangeset
for help on using the changeset viewer.