LAST of the c code comment translations... hooray!
[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 HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #ifdef WIN32
41 #include "BLI_winstuff.h"
42 #endif
43
44 #include "MEM_guardedalloc.h"
45
46 #include "BLI_blenlib.h"
47
48 #include "IMB_imbuf_types.h"
49 #include "IMB_imbuf.h"
50
51 #include "DNA_screen_types.h"
52 #include "DNA_space_types.h"
53
54 #include "BKE_utildefines.h"
55 #include "BKE_global.h"
56 #include "BKE_material.h"
57 #include "BKE_sca.h"
58
59 #include "BIF_gl.h"
60 #include "BIF_toolbox.h"
61 #include "BIF_mywindow.h"
62 #include "BIF_screen.h"
63 #include "BIF_toets.h"
64
65 #include "BSE_filesel.h"
66
67 #include "render.h"
68 #include "mydevice.h"
69
70 static unsigned int *dumprect=0;
71 static int dumpsx, dumpsy;
72
73 void write_screendump(char *name);
74
75 void write_screendump(char *name)
76 {
77         ImBuf *ibuf;
78         
79         if(dumprect) {
80
81                 strcpy(G.ima, name);
82                 BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
83                 
84                 if(saveover(name)) {
85                         waitcursor(1);
86                         
87                         ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0, 0);
88                         ibuf->rect= dumprect;
89                         
90                         if(G.scene->r.imtype== R_IRIS) ibuf->ftype= IMAGIC;
91                         else if(G.scene->r.imtype==R_IRIZ) ibuf->ftype= IMAGIC;
92                         else if(G.scene->r.imtype==R_TARGA) ibuf->ftype= TGA;
93                         else if(G.scene->r.imtype==R_RAWTGA) ibuf->ftype= RAWTGA;
94                         else if(G.scene->r.imtype==R_PNG) ibuf->ftype= PNG;
95                         else if(G.scene->r.imtype==R_HAMX) ibuf->ftype= AN_hamx;
96                         else if(ELEM5(G.scene->r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
97                                 ibuf->ftype= JPG|G.scene->r.quality;
98                         }
99                         else ibuf->ftype= TGA;  
100
101                         IMB_saveiff(ibuf, name, IB_rect);
102                         IMB_freeImBuf(ibuf);
103                         
104                         waitcursor(0);
105                 }
106                 MEM_freeN(dumprect);
107                 dumprect= 0;
108         }
109 }
110
111
112 void BIF_screendump(void)
113 {
114         /* get dump from frontbuffer */
115         int x=0, y=0;
116         char imstr[32];
117         
118         dumpsx= 0;
119         dumpsy= 0;
120         
121         if(dumprect) MEM_freeN(dumprect);
122         dumprect= 0;
123         
124         if (G.qual & LR_SHIFTKEY) {
125                 x= 0;
126                 y= 0;
127                 
128                 dumpsx= G.curscreen->sizex;
129                 dumpsy= G.curscreen->sizey;
130                 
131         } 
132         else {
133                 if(mywin_inmenu()) {
134                         mywin_getmenu_rect(&x, &y, &dumpsx, &dumpsy);
135                 } else {
136                         int win= mywinget();
137
138                         bwin_getsuborigin(win, &x, &y);
139                         bwin_getsize(win, &dumpsx, &dumpsy);
140                 }
141         }
142         
143         if (dumpsx && dumpsy) {
144                 save_image_filesel_str(imstr);
145                 
146                 dumprect= MEM_mallocN(sizeof(int)*dumpsx*dumpsy, "dumprect");
147                 glReadBuffer(GL_FRONT);
148                 glReadPixels(x, y, dumpsx, dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
149         
150                 /* open filesel */
151                 
152                 activate_fileselect(FILE_SPECIAL, imstr, G.ima, write_screendump);
153         }       
154 }