Subversion Repositories Kolibri OS

Rev

Rev 6746 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 1024 * 420
  2. #include "../lib/kolibri.h"
  3. #include "../lib/strings.h"
  4. #include "../lib/mem.h"
  5. #include "../lib/gui.h"
  6.  
  7. #include "../lib/obj/libimg.h"
  8.  
  9. #ifndef AUTOBUILD
  10.         #include "lang.h--"
  11. #endif
  12.  
  13. /* === DATA === */
  14.  
  15. proc_info Form;
  16.  
  17. dword b_screen,
  18.       preview;
  19.  
  20. int b_screen_length,
  21.     preview_width,
  22.     preview_height,
  23.     preview_length;
  24.  
  25. enum {
  26.         BTN_MAKE_SCREENSHOT=10,
  27.         BTN_SAVE
  28. };
  29.  
  30. #define TOOLBAR_H 50;
  31.  
  32. /* === CODE === */
  33.  
  34.  
  35. void main()
  36. {      
  37.         char id;
  38.         b_screen_length = screen.width * screen.height * 3;
  39.         preview_width  = screen.width / 2;
  40.         preview_height = screen.height / 2;
  41.         preview_length = b_screen_length / 2;  
  42.  
  43.         b_screen  = malloc(b_screen_length);
  44.         preview = malloc(b_screen_length/2);
  45.  
  46.         loop() switch(WaitEvent())
  47.         {
  48.         case evButton:
  49.                 id = GetButtonID();
  50.                 if (id == CLOSE_BTN) ExitProcess();
  51.                 if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
  52.                 if (id == BTN_SAVE) EventSaveFile();
  53.                 break;
  54.  
  55.         case evKey:
  56.                 GetKeys();
  57.                 if (SCAN_CODE_KEY_S == key_scancode) EventSaveFile();
  58.                 if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
  59.                 break;
  60.      
  61.         case evReDraw:
  62.                 system.color.get();
  63.                 DefineAndDrawWindow(screen.width/4, screen.height/4,
  64.                         preview_width + 9, preview_height + skin_height + TOOLBAR_H,
  65.                         0x74, 0, "EasyShot v0.3",0);
  66.                 GetProcessInfo(#Form, SelfInfo);
  67.                 if (Form.status_window>2) break;
  68.                 DrawBar(0, 0, Form.cwidth, TOOLBAR_H-4, system.color.work);
  69.                 DrawStandartCaptButton(10, 10, BTN_MAKE_SCREENSHOT, "Take a screenshot");
  70.                 _PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
  71.                 if (ESDWORD[preview]==0) {
  72.                         WriteTextB(Form.cwidth/2 - 90, Form.cheight/2+10, 0x90, 0xFFFfff, "There will be a preview");
  73.                 }
  74.                 else {
  75.                         DrawStandartCaptButton(200, 10, BTN_SAVE, "Save");
  76.                 }
  77.         }
  78. }
  79.  
  80. void EventTakeScreenshot() {
  81.         MinimizeWindow();
  82.         pause(100);
  83.         CopyScreen(b_screen, 0, 0, screen.width, screen.height);
  84.         ZoomImageTo50percent();
  85.         ActivateWindow(GetProcessSlot(Form.ID));
  86.         //_PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
  87. }
  88.  
  89. void EventSaveFile()
  90. {
  91.         SaveFile(b_screen, screen.width, screen.height, "/tmp0/1/screen.png");
  92. }
  93.  
  94. void SaveFile(dword _image, _w, _h, _path)
  95. {
  96.         dword encoded_data=0;
  97.         dword encoded_size=0;
  98.         dword image_ptr = 0;
  99.        
  100.         image_ptr = create_image(Image_bpp24, _w, _h);
  101.  
  102.         if (image_ptr == 0) {
  103.                 notify("'Error saving file, probably not enought memory!' -E");
  104.         }
  105.         else {
  106.                 EDI = image_ptr;
  107.                 memmov(EDI._Image.Data, _image, _w * _h * 3);
  108.  
  109.                 encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size);
  110.  
  111.                 img_destroy stdcall(image_ptr);
  112.  
  113.                 if(encoded_data == 0) {
  114.                         notify("'Error saving file, incorrect data!' -E");
  115.                 }
  116.                 else {
  117.                         if (WriteFile(encoded_size, encoded_data, _path) == 0) {
  118.                                 notify("'File saved as /rd/1/saved_image.png' -O");
  119.                         }
  120.                         else {
  121.                                 notify("'Error saving file, probably not enought space on ramdisk!' -E");
  122.                         }
  123.                 }
  124.         }
  125. }
  126.  
  127. void ZoomImageTo50percent() {
  128.         dword point_x,
  129.               item_h= screen.width * 3,
  130.               s_off = preview + 3,
  131.               b_off = b_screen + 6,
  132.               b_off_r,
  133.               b_off_g,
  134.               b_off_b,
  135.               rez_r,
  136.               rez_g,
  137.               rez_b;
  138.  
  139.         while( (s_off <= preview + preview_length) && (b_off <= b_screen + b_screen_length ) ) {
  140.                
  141.                 if (b_off <= b_screen + item_h) || (b_off >= b_screen + b_screen_length - item_h)
  142.                 {
  143.                         ESBYTE[s_off]   = ESBYTE[b_off];
  144.                         ESBYTE[s_off+1] = ESBYTE[b_off+1];
  145.                         ESBYTE[s_off+2] = ESBYTE[b_off+2];
  146.                 }
  147.                 else
  148.                 {
  149.                         // line[x].R = (line[x+1].R + line[x].R + line[x-1].R + line1[x].R + line2[x].R) / 5;
  150.                         // line[x].G = (line[x+1].G + line[x].G + line[x-1].G + line1[x].G + line2[x].G) / 5;
  151.                         // line[x].B = (line[x+1].B + line[x].B + line[x-1].B + line1[x].B + line2[x].B) / 5
  152.                         b_off_r = b_off;
  153.                         b_off_g = b_off + 1;
  154.                         b_off_b = b_off + 2;
  155.                         rez_r = ESBYTE[b_off_r+3] + ESBYTE[b_off_r] + ESBYTE[b_off_r-3] + ESBYTE[b_off_r-item_h] + ESBYTE[b_off_r+item_h] / 5;
  156.                         rez_g = ESBYTE[b_off_g+3] + ESBYTE[b_off_g] + ESBYTE[b_off_g-3] + ESBYTE[b_off_g-item_h] + ESBYTE[b_off_g+item_h] / 5;
  157.                         rez_b = ESBYTE[b_off_b+3] + ESBYTE[b_off_b] + ESBYTE[b_off_b-3] + ESBYTE[b_off_b-item_h] + ESBYTE[b_off_b+item_h] / 5;
  158.                         ESBYTE[s_off] = rez_r;
  159.                         ESBYTE[s_off+1] = rez_g;
  160.                         ESBYTE[s_off+2] = rez_b;
  161.  
  162.                 }
  163.        
  164.                 s_off+=3;
  165.                 b_off+=6;
  166.  
  167.                 point_x+=2;
  168.                 if (point_x >= screen.width)
  169.                 {
  170.                         b_off += item_h;
  171.                         point_x = 0;
  172.                 }
  173.         }
  174. }
  175.  
  176.  
  177. stop:
  178.