Blender V2.27

rotate.c

00001 
00032 #include "BLI_blenlib.h"
00033 #include "BLI_utildefines.h"
00034 
00035 
00036 #include "MEM_guardedalloc.h"
00037 
00038 #include "imbuf.h"
00039 #include "IMB_imbuf_types.h"
00040 #include "IMB_imbuf.h"
00041 
00042 #include "IMB_allocimbuf.h"
00043 
00044 void IMB_flipy(struct ImBuf * ibuf)
00045 {
00046         int x, y;
00047 
00048         if (ibuf == NULL) return;
00049 
00050         if (ibuf->rect) {
00051                 unsigned int *top, *bottom, *line;
00052 
00053                 x = ibuf->x;
00054                 y = ibuf->y;
00055 
00056                 top = ibuf->rect;
00057                 bottom = top + ((y-1) * x);
00058                 line= MEM_mallocN(x*sizeof(int), "linebuf");
00059         
00060                 y >>= 1;
00061 
00062                 for(;y>0;y--) {
00063                         memcpy(line, top, x*sizeof(int));
00064                         memcpy(top, bottom, x*sizeof(int));
00065                         memcpy(bottom, line, x*sizeof(int));
00066                         bottom -= x;
00067                         top+= x;
00068                 }
00069 
00070                 MEM_freeN(line);
00071         }
00072 
00073         if (ibuf->rect_float) {
00074                 float *topf=NULL, *bottomf=NULL, *linef=NULL;
00075 
00076                 x = ibuf->x;
00077                 y = ibuf->y;
00078 
00079                 topf= ibuf->rect_float;
00080                 bottomf = topf + 4*((y-1) * x);
00081                 linef= MEM_mallocN(4*x*sizeof(float), "linebuff");
00082 
00083                 y >>= 1;
00084 
00085                 for(;y>0;y--) {
00086                         memcpy(linef, topf, 4*x*sizeof(float));
00087                         memcpy(topf, bottomf, 4*x*sizeof(float));
00088                         memcpy(bottomf, linef, 4*x*sizeof(float));
00089                         bottomf -= 4*x;
00090                         topf+= 4*x;
00091                 }
00092 
00093                 MEM_freeN(linef);
00094         }
00095 }
00096 
00097 void IMB_flipx(struct ImBuf * ibuf)
00098 {
00099         short x, y, xr, xl, yi;
00100         float px_f[4];
00101         
00102         if (ibuf == NULL) return;
00103 
00104         x = ibuf->x;
00105         y = ibuf->y;
00106 
00107         if (ibuf->rect) {
00108                 for(yi=y-1;yi>=0;yi--) {
00109                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
00110                                 SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]);
00111                         }
00112                 }
00113         }
00114         
00115         if (ibuf->rect_float) {
00116                 for(yi=y-1;yi>=0;yi--) {
00117                         for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
00118                                 memcpy(&px_f, &ibuf->rect_float[((x*yi)+xr)*4], 4*sizeof(float));
00119                                 memcpy(&ibuf->rect_float[((x*yi)+xr)*4], &ibuf->rect_float[((x*yi)+xl)*4], 4*sizeof(float));
00120                                 memcpy(&ibuf->rect_float[((x*yi)+xl)*4], &px_f, 4*sizeof(float));
00121                         }
00122                 }
00123         }
00124 }