hedgewars/uMisc.pas
branchwebgl
changeset 8026 4a4f21070479
parent 7848 775a72905708
child 9127 e350500c4edb
equal deleted inserted replaced
8023:7de85783b823 8026:4a4f21070479
    47          filename: shortstring;
    47          filename: shortstring;
    48          width, height: LongInt;
    48          width, height: LongInt;
    49          size: QWord;
    49          size: QWord;
    50          end;
    50          end;
    51 
    51 
    52 var conversionFormat: PSDL_PixelFormat;
    52 var conversionFormat : PSDL_PixelFormat;
    53 
    53 
    54 procedure movecursor(dx, dy: LongInt);
    54 procedure movecursor(dx, dy: LongInt);
    55 var x, y: LongInt;
    55 var x, y: LongInt;
    56 begin
    56 begin
    57 if (dx = 0) and (dy = 0) then exit;
    57 if (dx = 0) and (dy = 0) then exit;
    66 // this funtion will be executed in separate thread
    66 // this funtion will be executed in separate thread
    67 function SaveScreenshot(screenshot: pointer): PtrInt;
    67 function SaveScreenshot(screenshot: pointer): PtrInt;
    68 var i: LongInt;
    68 var i: LongInt;
    69     png_ptr: ^png_struct;
    69     png_ptr: ^png_struct;
    70     info_ptr: ^png_info;
    70     info_ptr: ^png_info;
    71     f: file;
    71     f: File;
    72     image: PScreenshot;
    72     image: PScreenshot;
    73 begin
    73 begin
    74 image:= PScreenshot(screenshot);
    74 image:= PScreenshot(screenshot);
    75 
    75 
    76 png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
    76 png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
   139     0, 0, 0, 0,     // number of colors (all)
   139     0, 0, 0, 0,     // number of colors (all)
   140     0, 0, 0, 0      // number of important colors
   140     0, 0, 0, 0      // number of important colors
   141     );
   141     );
   142     image: PScreenshot;
   142     image: PScreenshot;
   143     size: QWord;
   143     size: QWord;
       
   144     writeResult:LongInt;
   144 begin
   145 begin
   145 image:= PScreenshot(screenshot);
   146 image:= PScreenshot(screenshot);
   146 
   147 
   147 size:= image^.Width*image^.Height*4;
   148 size:= image^.Width*image^.Height*4;
   148 
   149 
   166 {$IOCHECKS OFF}
   167 {$IOCHECKS OFF}
   167 Assign(f, image^.filename);
   168 Assign(f, image^.filename);
   168 Rewrite(f, 1);
   169 Rewrite(f, 1);
   169 if IOResult = 0 then
   170 if IOResult = 0 then
   170     begin
   171     begin
   171     BlockWrite(f, head, sizeof(head));
   172     BlockWrite(f, head, sizeof(head), writeResult);
   172     BlockWrite(f, image^.buffer^, size);
   173     BlockWrite(f, image^.buffer^, size, writeResult);
   173     Close(f);
   174     Close(f);
   174     end
   175     end
   175 else
   176 else
   176     begin
   177     begin
   177     //AddFileLog('Error: Could not write to ' + filename);
   178     //AddFileLog('Error: Could not write to ' + filename);
   273 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   274 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   274 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   275 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   275 var convertedSurf: PSDL_Surface;
   276 var convertedSurf: PSDL_Surface;
   276 begin
   277 begin
   277     doSurfaceConversion:= tmpsurf;
   278     doSurfaceConversion:= tmpsurf;
       
   279 {$IFNDEF WEBGL}
   278     if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
   280     if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
   279        (tmpsurf^.format^.bitsperpixel = 24) then
   281        (tmpsurf^.format^.bitsperpixel = 24) then
   280     begin
   282     begin
   281         convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
   283         convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
   282         SDL_FreeSurface(tmpsurf);
   284         SDL_FreeSurface(tmpsurf);
   283         doSurfaceConversion:= convertedSurf;
   285         doSurfaceConversion:= convertedSurf;
   284     end;
   286     end;
       
   287 {$ENDIF}
   285 end;
   288 end;
   286 
   289 
   287 {$IFDEF SDL13}
   290 {$IFDEF SDL13}
   288 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   291 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   289 {$ELSE}
   292 {$ELSE}
   312 procedure freeModule;
   315 procedure freeModule;
   313 begin
   316 begin
   314     SDL_FreeFormat(conversionFormat);
   317     SDL_FreeFormat(conversionFormat);
   315 end;
   318 end;
   316 
   319 
   317 end.
   320 end.