"UV Test Grid" option in Image Window > Image menu > New, to generate
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 27 Nov 2005 16:21:25 +0000 (16:21 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 27 Nov 2005 16:21:25 +0000 (16:21 +0000)
a colored grid instead of a blank image, for quickly spotting distortion
in UV maps.

source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/src/header_image.c

index 1927ad9bb024fabf06a96605b8c0d6396a20a7e9..1ae5552104c39877a1d6e786200b297f621ac7c5 100644 (file)
@@ -47,7 +47,7 @@ void free_image(struct Image *me);
 void free_image_buffers(struct Image *ima);
 struct Image *add_image(char *name);
 void free_unused_animimages(void);
-struct Image *new_image(int width, int height, char *name);
+struct Image *new_image(int width, int height, char *name, short uvtestgrid);
 
 void makepicstring(char *string, int frame);
 void addImageExtension(char *string);
index 5be1c0ed48ff5143f559a7c817fc6ab7d13d3cc7..c09f68643ce848e311fdef65b238b06d041e1c6c 100644 (file)
@@ -54,6 +54,7 @@
 #include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_arithb.h"
 
 #include "BKE_bmfont.h"
 #include "BKE_packedFile.h"
@@ -148,7 +149,7 @@ Image *add_image(char *name)
        return ima;
 }
 
-Image *new_image(int width, int height, char *name)
+Image *new_image(int width, int height, char *name, short uvtestgrid)
 {
        Image *ima;
                        
@@ -159,6 +160,7 @@ Image *new_image(int width, int height, char *name)
                ImBuf *ibuf;
                unsigned char *rect;
                int x, y;
+               float h=0.0, hoffs=0.0, s=0.9, v=0.6, r, g, b;
 
                strcpy(ima->name, "Untitled");
 
@@ -167,10 +169,30 @@ Image *new_image(int width, int height, char *name)
                ima->ibuf= ibuf;
 
                rect= (unsigned char*)ibuf->rect;
-               for(y=0; y<ibuf->y; y++) {
-                       for(x=0; x<ibuf->x; x++, rect+=4) {
-                               rect[0]= rect[1]= rect[2]= 0;
-                               rect[3]= 255;
+               
+               if (uvtestgrid) {
+                       for(y=0; y<ibuf->y; y++) {
+                               if (y % 20 == 0) hoffs += 0.125;
+                               if (y % 160 == 0) hoffs = 0.0;
+                               
+                               for(x=0; x<ibuf->x; x++, rect+=4) {
+                                       if (x % 20 == 0) h += 0.125;
+                                       if (x % 160 == 0) h = 0.0;
+                                                               
+                                       hsv_to_rgb(fabs(h-hoffs), s, v, &r, &g, &b);
+                                       
+                                       rect[0]= (char)(r * 255.0);
+                                       rect[1]= (char)(g * 255.0);
+                                       rect[2]= (char)(b * 255.0);
+                                       rect[3]= 255;
+                               }
+                       }
+               } else {        /* blank image */
+                       for(y=0; y<ibuf->y; y++) {
+                               for(x=0; x<ibuf->x; x++, rect+=4) {
+                                       rect[0]= rect[1]= rect[2]= 0;
+                                       rect[3]= 255;
+                               }
                        }
                }
 
index 8a4603ec532a9c08a2d627affae2ee1ab25e162f..e0571e94e4562c53aa7b718ddfd432864a15dbcf 100644 (file)
@@ -731,6 +731,7 @@ static void do_image_imagemenu(void *arg, int event)
        case 7: /* New Image */
                {
                        static int width= 256, height= 256;
+                       static short uvtestgrid=0;
                        char name[256];
 
                        strcpy(name, "Image");
@@ -738,10 +739,11 @@ static void do_image_imagemenu(void *arg, int event)
                        add_numbut(0, TEX, "Name:", 0, 255, name, NULL);
                        add_numbut(1, NUM|INT, "Width:", 1, 5000, &width, NULL);
                        add_numbut(2, NUM|INT, "Height:", 1, 5000, &height, NULL);
-                       if (!do_clever_numbuts("New Image", 3, REDRAW))
+                       add_numbut(3, TOG|SHO, "UV Test Grid", 0, 0, &uvtestgrid, NULL);
+                       if (!do_clever_numbuts("New Image", 4, REDRAW))
                                return;
 
-                       G.sima->image= new_image(width, height, name);
+                       G.sima->image= new_image(width, height, name, uvtestgrid);
                        image_changed(G.sima, 0);
 
                        allqueue(REDRAWIMAGE, 0);