pdv_dmy_image.c

00001 
00002 #include "edtinc.h"
00003 
00004 /*
00005 * change 1024x1024 8 bit with row 0 row0:       BGBGBGBG row1:  GRGRGRGR to
00006 * 24 bit BGR,BGR first pass 512/512
00007 */
00008 
00009 /* shorthand debug level */
00010 
00011 #define PDVWARN PDVLIB_MSG_WARNING
00012 #define PDVFATAL PDVLIB_MSG_FATAL
00013 #define DBG1 PDVLIB_MSG_INFO_1
00014 #define DBG2 PDVLIB_MSG_INFO_2
00015 
00016 
00017 int
00018 exp2_image(u_char * src, int width, int rows, u_char * dest)
00019 {
00020     u_char *cur_p;
00021     u_char *nxt_p;
00022     u_char *lst_p;
00023     u_char *dest_p = dest;
00024     int     x, y;
00025 
00026     edt_msg(DBG2, "exp2_image\n");
00027 
00028     if (width == 512)
00029     {
00030         cur_p = src;
00031         nxt_p = src + 1024;
00032 
00033         for (y = 0; y < rows; y++)
00034         {
00035             for (x = 0; x < width; x++)
00036             {
00037 
00038                 *dest_p++ = *cur_p;     /* blue */
00039                 /* use average of two greens */
00040                 *dest_p++ = *(cur_p + 1) + (*(nxt_p) >> 1);
00041                 *dest_p++ = *(nxt_p + 1);       /* red */
00042                 cur_p += 2;
00043                 nxt_p += 2;
00044             }
00045             cur_p += 1024;
00046             nxt_p += 1024;
00047         }
00048     }
00049     else
00050     {
00051         cur_p = src;
00052         lst_p = src;
00053         nxt_p = src + width;
00054         for (y = 0; y < rows - 2; y += 2)
00055         {
00056             for (x = 0; x < width; x += 2)
00057             {
00058 
00059                 *dest_p++ = *cur_p;
00060                 *dest_p++ = *nxt_p;     /* green from below */
00061                 *dest_p++ = *(nxt_p + 1);
00062                 *dest_p++ = *cur_p;
00063                 *dest_p++ = *(cur_p + 1);       /* green from cur row */
00064                 *dest_p++ = *(nxt_p + 1);
00065                 cur_p += 2;
00066                 nxt_p += 2;
00067             }
00068 
00069             for (x = 0; x < width; x += 2)
00070             {
00071 
00072                 *dest_p++ = *lst_p;     /* blue from above */
00073                 *dest_p++ = *cur_p;
00074                 *dest_p++ = *(cur_p + 1);
00075                 *dest_p++ = *nxt_p;     /* blue from below */
00076                 *dest_p++ = *(nxt_p + 1);       /* green from below */
00077                 *dest_p++ = *(cur_p + 1);
00078                 cur_p += 2;
00079                 nxt_p += 2;
00080                 lst_p += 2;
00081             }
00082             lst_p += width;
00083         }
00084     }
00085     return (0);
00086 }
00087 
00088 /*
00089 * change 1024x1024 8 bit dual with BGGRBGGRBGGR to 24 bit BGR,BGR first pass
00090 * 512/512
00091 */
00092 int
00093 exp2dual_image(u_char * src, int width, int rows, u_char * dest)
00094 {
00095     u_char *cur_p;
00096     u_char *nxt_p;
00097     u_char *lst_p;
00098     u_char *dest_p = dest;
00099     int     x, y;
00100 
00101     edt_msg(DBG2, "exp2dual_image\n");
00102 
00103 
00104     if (width == 512)
00105     {
00106         cur_p = src;
00107 
00108         for (y = 0; y < rows; y++)
00109         {
00110             for (x = 0; x < width; x++)
00111             {
00112 
00113                 *dest_p++ = cur_p[0];   /* blue */
00114                 /* use average of two greens */
00115                 *dest_p++ = (cur_p[1] + cur_p[2]) >> 1;
00116                 *dest_p++ = cur_p[3];   /* red */
00117                 cur_p += 4;
00118             }
00119         }
00120     }
00121     else
00122     {
00123         cur_p = src;
00124         lst_p = src;
00125         nxt_p = src + 1024;
00126         for (y = 0; y < rows - 2; y += 2)
00127         {
00128             for (x = 0; x < width; x += 2)
00129             {
00130 
00131                 *dest_p++ = *cur_p;
00132                 *dest_p++ = *nxt_p;     /* green from below */
00133                 *dest_p++ = *(nxt_p + 1);
00134                 *dest_p++ = *cur_p;
00135                 *dest_p++ = *(cur_p + 1);       /* green from cur row */
00136                 *dest_p++ = *(nxt_p + 1);
00137                 cur_p += 2;
00138                 nxt_p += 2;
00139             }
00140 
00141             for (x = 0; x < width; x += 2)
00142             {
00143 
00144                 *dest_p++ = *lst_p;     /* blue from above */
00145                 *dest_p++ = *cur_p;
00146                 *dest_p++ = *(cur_p + 1);
00147                 *dest_p++ = *nxt_p;     /* blue from below */
00148                 *dest_p++ = *(nxt_p + 1);       /* green from below */
00149                 *dest_p++ = *(cur_p + 1);
00150                 cur_p += 2;
00151                 nxt_p += 2;
00152                 lst_p += 2;
00153             }
00154             lst_p += 1024;
00155         }
00156     }
00157     return (0);
00158 }
00159 
00160 /*
00161 * fill in first half of image with value, then two smaller with value - 1
00162 * and value + 1 ;
00163 */
00164 static int tog = 0;
00165 void
00166 do_data8(u_char * buf, int width, int height, int scansize, int left, int right)
00167 {
00168 
00169     u_char *tmpp;
00170     u_char *p;
00171     int     x;
00172     int     y;
00173     int     delta;
00174     int     midpoint;
00175     u_char *p0;
00176     u_char *p1;
00177 
00178     /* edt_msg(DBG2, "do_data8\n");*/
00179 
00180     if (width == 0 || left == right - 1)
00181         return;
00182     midpoint = (left + right) / 2;
00183     delta = (right - left) / 2;
00184 
00185     /* fill in top half */
00186     p = buf;
00187     for (y = 0; y < height; y++)
00188     {
00189         tmpp = p;
00190         for (x = 0; x < width; x++)
00191             tmpp[x] = midpoint;
00192         p += scansize;
00193     }
00194 
00195     if (tog)
00196     {
00197         p0 = buf + (scansize * height);
00198         p1 = p0 + width / 2;
00199     }
00200     else
00201     {
00202         p1 = buf + (scansize * height);
00203         p0 = p1 + width / 2;
00204     }
00205 
00206 
00207     do_data8(p0, width / 2, height, scansize, left, midpoint);
00208     do_data8(p1, width / 2, height, scansize, midpoint, right);
00209 }
00210 
00211 void
00212 do_data16(u_short * buf, int width, int height, int scansize, int left, int right)
00213 {
00214 
00215     u_short *tmpp;
00216     u_short *p;
00217     int     x;
00218     int     y;
00219     int     delta;
00220     int     midpoint;
00221     u_short *p0;
00222     u_short *p1;
00223 
00224     if (width == 0 || left == right - 1)
00225         return;
00226     midpoint = (left + right) / 2;
00227     delta = (right - left) / 2;
00228     /* fill in top half */
00229     p = buf;
00230 
00231     /* edt_msg(DBG2, "do_data16\n"); */
00232 
00233     for (y = 0; y < height; y++)
00234     {
00235         tmpp = p;
00236         for (x = 0; x < width; x++)
00237             tmpp[x] = midpoint;
00238         p += scansize;
00239     }
00240 
00241     if (tog)
00242     {
00243         p0 = buf + (scansize * height);
00244         p1 = p0 + width / 2;
00245     }
00246     else
00247     {
00248         p1 = buf + (scansize * height);
00249         p0 = p1 + width / 2;
00250     }
00251 
00252     do_data16(p0, width / 2, height, scansize, left, midpoint);
00253     do_data16(p1, width / 2, height, scansize, midpoint, right);
00254 }
00255 
00263 void
00264 pdv_dmy_data(void *buf, int width, int height, int depth)
00265 {
00266     edt_msg(DBG2, "dmy_data\n");
00267     if (depth == 8)
00268     {
00269         do_data8(buf, width, height / depth, width, 0, 1 << depth);
00270         tog ^= 1;
00271     }
00272     else if (depth > 8 && depth <= 16)
00273     {
00274         /* fill in interesting data for histogram */
00275         do_data16(buf, width, height / depth, width, 0, 1 << depth);
00276         tog ^= 1;
00277     }
00278     else if (depth == 24)
00279     {
00280         int     x;
00281         int     y;
00282         int     v;
00283         int     row;
00284         int     col;
00285         static int cnt = 0;
00286         char   *tmpp = buf;
00287         char *oldcolor = getenv("OLDCOLOR") ;
00288 
00289         if (oldcolor)
00290         {
00291             for (y = 0; y < height; y++)
00292             {
00293                 for (x = 0; x < width; x++)
00294                 {
00295                     switch (cnt)
00296                     {
00297                     case 0:
00298                         *tmpp++ = x;
00299                         *tmpp++ = y;
00300                         *tmpp++ = (x + y) / 2;
00301                         break;
00302                     case 1:
00303                         *tmpp++ = (x + y) / 2;
00304                         *tmpp++ = x;
00305                         *tmpp++ = y;
00306                         break;
00307                     case 2:
00308                         *tmpp++ = y;
00309                         *tmpp++ = (x + y) / 2;
00310                         *tmpp++ = x;
00311                         break;
00312                     }
00313                 }
00314             }
00315         }
00316         else
00317         {
00318             for (y = 0; y < height; y++)
00319             {
00320                 row = y >> 6;
00321 
00322                 for (x = 0; x < width; x++)
00323                 {
00324                     col = x >> 6;
00325 
00326                     v = ((row + col) % 3);
00327 
00328 
00329                     switch (cnt)
00330                     {
00331                     case 0:
00332                         switch (v)
00333                         {
00334                         case 0:
00335                             *tmpp++ = (char) 0xc0;
00336                             *tmpp++ = (char) 0x40;
00337                             *tmpp++ = (char) 0x40;
00338                             break;
00339 
00340                         case 1:
00341                             *tmpp++ = (char) 0x40;
00342                             *tmpp++ = (char) 0xc0;
00343                             *tmpp++ = (char) 0x40;
00344                             break;
00345 
00346                         case 2:
00347                             *tmpp++ = (char) 0x40;
00348                             *tmpp++ = (char) 0x40;
00349                             *tmpp++ = (char) 0xc0;
00350                             break;
00351                         }
00352                         break;
00353                     case 1:
00354                         switch (v)
00355                         {
00356                         case 1:
00357                             *tmpp++ = (char) 0xc0;
00358                             *tmpp++ = (char) 0x40;
00359                             *tmpp++ = (char) 0x40;
00360                             break;
00361 
00362                         case 2:
00363                             *tmpp++ = (char) 0x40;
00364                             *tmpp++ = (char) 0xc0;
00365                             *tmpp++ = (char) 0x40;
00366                             break;
00367 
00368                         case 0:
00369                             *tmpp++ = (char) 0x40;
00370                             *tmpp++ = (char) 0x40;
00371                             *tmpp++ = (char) 0xc0;
00372                             break;
00373                         }
00374                         break;
00375                     case 2:
00376                         switch (v)
00377                         {
00378                         case 2:
00379                             *tmpp++ = (char) 0xc0;
00380                             *tmpp++ = (char) 0x40;
00381                             *tmpp++ = (char) 0x40;
00382                             break;
00383 
00384                         case 0:
00385                             *tmpp++ = (char) 0x40;
00386                             *tmpp++ = (char) 0xc0;
00387                             *tmpp++ = (char) 0x40;
00388                             break;
00389 
00390                         case 1:
00391                             *tmpp++ = (char) 0x40;
00392                             *tmpp++ = (char) 0x40;
00393                             *tmpp++ = (char) 0xc0;
00394                             break;
00395                         }
00396                         break;
00397                     }
00398                 }
00399             }
00400         }
00401         if (++cnt == 3)
00402             cnt = 0;
00403     }
00404     else if (depth == 32)
00405     {
00406         int     x;
00407         int     y;
00408         static int cnt = 0;
00409         char   *tmpp = buf;
00410 
00411         for (y = 0; y < height; y++)
00412         {
00413             for (x = 0; x < width; x++)
00414             {
00415                 switch (cnt)
00416                 {
00417                 case 0:
00418                     *tmpp++ = x;
00419                     *tmpp++ = 0;
00420                     *tmpp++ = 0;
00421                     *tmpp++ = 0;
00422                     break;
00423                 case 1:
00424                     *tmpp++ = 0;
00425                     *tmpp++ = x;
00426                     *tmpp++ = 0;
00427                     *tmpp++ = 0;
00428                     break;
00429                 case 2:
00430                     *tmpp++ = 0;
00431                     *tmpp++ = 0;
00432                     *tmpp++ = x;
00433                     *tmpp++ = 0;
00434                     break;
00435                 }
00436             }
00437         }
00438         if (++cnt == 3)
00439             cnt = 0;
00440     }
00441 }

Generated on 19 Jun 2015 by  doxygen 1.4.7