Changed frame numbering to only alter hashes if they are in the filename (not the...
[blender.git] / source / blender / src / screendump.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL 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.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  * Making screendumps.
29  */
30
31 #include <string.h>
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36
37 #include "IMB_imbuf_types.h"
38 #include "IMB_imbuf.h"
39
40 #include "DNA_scene_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_space_types.h"
43
44 #include "BKE_utildefines.h"
45 #include "BKE_global.h"
46 #include "BKE_image.h"
47 #include "BKE_material.h"
48 #include "BKE_sca.h"
49
50 #include "BIF_gl.h"
51 #include "BIF_toolbox.h"
52 #include "BIF_mywindow.h"
53 #include "BIF_screen.h"
54 #include "BIF_toets.h"
55 #include "BIF_interface.h"
56 #include "BIF_writeimage.h"
57
58 #include "BSE_filesel.h"
59
60 #include "mydevice.h"
61
62 static unsigned int *dumprect=0;
63 static int dumpsx, dumpsy;
64
65 void write_screendump(char *name)
66 {
67         ImBuf *ibuf;
68         
69         if(dumprect) {
70
71                 strcpy(G.ima, name);
72                 BLI_convertstringcode(name, G.sce);
73                 BLI_convertstringframe(name, G.scene->r.cfra); /* TODO - is this ever used? */
74                 
75                 /* BKE_add_image_extension() checks for if extension was already set */
76                 if(G.scene->r.scemode & R_EXTENSION) 
77                         if(strlen(name)<FILE_MAXDIR+FILE_MAXFILE-5)
78                                 BKE_add_image_extension(name, G.scene->r.imtype);
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.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
87                         
88                         BKE_write_ibuf(ibuf, name, G.scene->r.imtype, G.scene->r.subimtype, G.scene->r.quality);
89
90                         IMB_freeImBuf(ibuf);
91                         
92                         waitcursor(0);
93                 }
94                 MEM_freeN(dumprect);
95                 dumprect= NULL;
96         }
97 }
98
99 /* get dump from frontbuffer */
100 void BIF_screendump(int fscreen)
101 {
102         extern int uiIsMenu(int *x, int *y, int *sizex, int *sizey);
103         int ismenu;
104         static int wasmenu= 0;
105         int x=0, y=0;
106         char imstr[64];
107
108         /* this sets dumpsx/y to zero if ismenu==0 */
109         ismenu= uiIsMenu(&x, &y, &dumpsx, &dumpsy);
110         
111         if(wasmenu && !ismenu) {
112                 save_image_filesel_str(imstr);
113                 strcat(imstr, " (Menu)");
114                 activate_fileselect(FILE_SPECIAL, imstr, G.ima, write_screendump);
115                 wasmenu= 0;
116                 return;
117         }
118         
119         if(dumprect) MEM_freeN(dumprect);
120         dumprect= NULL;
121         
122         if((G.qual & LR_SHIFTKEY) || fscreen) { /* full screen */
123                 x= 0;
124                 y= 0;
125                 
126                 dumpsx= G.curscreen->sizex;
127                 dumpsy= G.curscreen->sizey;
128                 
129         } 
130         else {
131                 if(ismenu==0) { /* a window */
132                         //int win= mywinget();
133
134                         //bwin_getsuborigin(win, &x, &y);
135                         //bwin_getsize(win, &dumpsx, &dumpsy);
136                         x= curarea->totrct.xmin;
137                         y= curarea->totrct.ymin;
138                         dumpsx= curarea->totrct.xmax-x;
139                         dumpsy= curarea->totrct.ymax-y;
140                 }
141         }
142         
143         if (dumpsx && dumpsy) {
144                 
145                 dumprect= MEM_mallocN(sizeof(int)*dumpsx*dumpsy, "dumprect");
146                 glReadBuffer(GL_FRONT);
147                 glReadPixels(x, y, dumpsx, dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
148                 glFinish();
149                 glReadBuffer(GL_BACK);
150                 
151                 if(ismenu==0) {
152                         wasmenu= 0;
153                         save_image_filesel_str(imstr);
154                         activate_fileselect(FILE_SPECIAL, imstr, G.ima, write_screendump);
155                 }
156                 else wasmenu= 1;
157         }
158
159 }