/[gzz]/gzz/gfx/libcolor/spaces.cxx
ViewVC logotype

Diff of /gzz/gfx/libcolor/spaces.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by jvk, Thu Sep 19 13:01:28 2002 UTC revision 1.5 by jvk, Fri Sep 20 15:52:33 2002 UTC
# Line 306  namespace Color { Line 306  namespace Color {
306      }      }
307    
308    
309      unsigned getImageColorMap(char *colorspace, int x, int y, int w, int h, unsigned list = 0) {      unsigned getImageColorMap(char *colorspace, unsigned char *pixels, int n, unsigned list = 0) {
310        void (*fromRGB)(float [], float []);        void (*fromRGB)(float [], float []);
311    
312        if (strcmp(colorspace, "CIELAB") == 0) {        if (strcmp(colorspace, "CIELAB") == 0) {
# Line 315  namespace Color { Line 315  namespace Color {
315          fromRGB = RGB709toXYZ;          fromRGB = RGB709toXYZ;
316        }        }
317    
       float *pixels = new float[w * h * 3];  
       glReadBuffer(GL_FRONT);  
       glReadPixels(x, y, w, h, GL_RGB, GL_FLOAT, pixels);  
         
       glDrawBuffer(GL_FRONT);  
       glRasterPos2f(0, 0);  
       glDrawPixels(w, h, GL_RGB, GL_FLOAT, pixels);  
   
       glFinish();  
   
       glDrawBuffer(GL_BACK);  
   
318        if (list == 0) list = glGenLists(1);        if (list == 0) list = glGenLists(1);
319        glNewList(list, GL_COMPILE);        glNewList(list, GL_COMPILE);
320        glBegin(GL_POINTS);        glBegin(GL_POINTS);
321        for (int i = 0; i < w * h * 3; i += 3) {        for (int i = 0; i < n * 3; i += 3) {
322          float rgb[3] = { pixels[i], pixels[i+1], pixels[i+2] };          const float s = 1. / 255;
323            float rgb[3] = { s * pixels[i], s * pixels[i+1], s * pixels[i+2] };
324          float v[3];          float v[3];
325          fromRGB(rgb, v);          fromRGB(rgb, v);
326          glColor3fv(rgb);          glColor3fv(rgb);
327          glVertex3fv(v);          glVertex3fv(v);
328            /*
329          cout << "("          cout << "("
330               << rgb[0]<< "," << rgb[1] << "," << rgb[2]               << rgb[0]<< "," << rgb[1] << "," << rgb[2]
331               << ")->("               << ")->("
332               << v[0] << "," << v[1] << "," << v[2]               << v[0] << "," << v[1] << "," << v[2]
333               << ")\n";               << ")\n";
334            */
335        }        }
336        glEnd();        glEnd();
337    
338          float edge[12][2][3] = {
339            {{ 0, 0, 0 }, { 0, 0, 1 }},
340            {{ 0, 1, 0 }, { 0, 1, 1 }},
341            {{ 1, 0, 0 }, { 1, 0, 1 }},
342            {{ 1, 1, 0 }, { 1, 1, 1 }},
343    
344            {{ 0, 0, 0 }, { 0, 1, 0 }},
345            {{ 0, 0, 1 }, { 0, 1, 1 }},
346            {{ 1, 0, 0 }, { 1, 1, 0 }},
347            {{ 1, 0, 1 }, { 1, 1, 1 }},
348    
349            {{ 0, 0, 0 }, { 1, 0, 0 }},
350            {{ 0, 0, 1 }, { 1, 0, 1 }},
351            {{ 0, 1, 0 }, { 1, 1, 0 }},
352            {{ 0, 1, 1 }, { 1, 1, 1 }}
353          };
354    
355          for (int i = 0; i < 12; i++) {
356            float rgb[3], v[3];
357            glBegin(GL_LINE_STRIP);
358            for (float t = 0; t <= 1; t += 1.0 / 8) {
359              for (int c = 0; c < 3; c++)
360                rgb[c] = edge[i][0][c] * (1 - t) + edge[i][1][c] * t;
361              fromRGB(rgb, v);
362              glColor3fv(rgb);
363              glVertex3fv(v);
364            }
365            glEnd();
366          }
367    
368        glEndList();        glEndList();
369        delete[] pixels;        delete[] pixels;
370        return list;        return list;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26