Initial revision
[blender.git] / source / blender / src / screendump.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * Making screendumps.
32  */
33
34 #include <string.h>
35
36 #ifdef WIN32
37 #include "BLI_winstuff.h"
38 #endif
39
40 #include "MEM_guardedalloc.h"
41
42 #include "BLI_blenlib.h"
43
44 #include "IMB_imbuf_types.h"
45 #include "IMB_imbuf.h"
46
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49
50 #include "BKE_utildefines.h"
51 #include "BKE_global.h"
52 #include "BKE_material.h"
53 #include "BKE_sca.h"
54
55 #include "BIF_gl.h"
56 #include "BIF_toolbox.h"
57 #include "BIF_mywindow.h"
58 #include "BIF_screen.h"
59 #include "BIF_toets.h"
60
61 #include "BSE_filesel.h"
62
63 #include "render.h"
64 #include "mydevice.h"
65
66 static unsigned int *dumprect=0;
67 static int dumpsx, dumpsy;
68
69 void write_screendump(char *name);
70
71 void write_screendump(char *name)
72 {
73         ImBuf *ibuf;
74         
75         if(dumprect) {
76
77                 strcpy(G.ima, name);
78                 BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
79                 
80                 if(saveover(name)) {
81                         waitcursor(1);
82                         
83                         ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0, 0);
84                         ibuf->rect= dumprect;
85                         
86                         if(G.scene->r.imtype== R_IRIS) ibuf->ftype= IMAGIC;
87                         else if(G.scene->r.imtype==R_IRIZ) ibuf->ftype= IMAGIC;
88                         else if(G.scene->r.imtype==R_TARGA) ibuf->ftype= TGA;
89                         else if(G.scene->r.imtype==R_RAWTGA) ibuf->ftype= RAWTGA;
90                         else if(G.scene->r.imtype==R_PNG) ibuf->ftype= PNG;
91                         else if(G.scene->r.imtype==R_HAMX) ibuf->ftype= AN_hamx;
92                         else if(ELEM5(G.scene->r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
93                                 ibuf->ftype= JPG|G.scene->r.quality;
94                         }
95                         else ibuf->ftype= TGA;  
96
97                         IMB_saveiff(ibuf, name, IB_rect);
98                         IMB_freeImBuf(ibuf);
99                         
100                         waitcursor(0);
101                 }
102                 MEM_freeN(dumprect);
103                 dumprect= 0;
104         }
105 }
106
107
108 void BIF_screendump(void)
109 {
110         /* dump pakken van frontbuffer */
111         int x=0, y=0;
112         char imstr[32];
113         
114         dumpsx= 0;
115         dumpsy= 0;
116         
117         if(dumprect) MEM_freeN(dumprect);
118         dumprect= 0;
119         
120         if (G.qual & LR_SHIFTKEY) {
121                 x= 0;
122                 y= 0;
123                 
124                 dumpsx= G.curscreen->sizex;
125                 dumpsy= G.curscreen->sizey;
126                 
127         } 
128         else {
129                 if(mywin_inmenu()) {
130                         mywin_getmenu_rect(&x, &y, &dumpsx, &dumpsy);
131                 } else {
132                         int win= mywinget();
133
134                         bwin_getsuborigin(win, &x, &y);
135                         bwin_getsize(win, &dumpsx, &dumpsy);
136                 }
137         }
138         
139         if (dumpsx && dumpsy) {
140                 save_image_filesel_str(imstr);
141                 
142                 dumprect= MEM_mallocN(sizeof(int)*dumpsx*dumpsy, "dumprect");
143                 glReadBuffer(GL_FRONT);
144                 glReadPixels(x, y, dumpsx, dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
145         
146                 /* filesel openen */
147                 
148                 activate_fileselect(FILE_SPECIAL, imstr, G.ima, write_screendump);
149         }       
150 }