badpixel - show_bad_b mod - General Discussion and Assistance - CHDK Forum

badpixel - show_bad_b mod

  • 2 Replies
  • 4500 Views
badpixel - show_bad_b mod
« on: 10 / April / 2009, 09:14:37 »
Advertisements
Hi guys,
I hope this is the appropriate forum for this kind of thing.
I added some additional features the show_bad_b.c, so it may now accept a threshold and outputs some information about the marked pixels (I did this by putting together show_bad_b.c and show_bad.c). Now in the show_bad_b.c there is one additional line which is not in show_bad.c and in show_bad.c is some additional action which is not in show_bad_b.c. There is a shift on the black_level and the threshold performed, I don't know why. The line after that one was not in show_bad.c, so no shift. Should there be one? This works for me nevertheless, because I have an 8MP. But because I want to contribute a little bit to the community I want to do this right.

modified show_bad_b.c:
Code: (c) [Select]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
 
int main(int argc, char **argv)
{
    FILE *fcraw;
    FILE *out;
    unsigned char rawrow[10000];
    int rowpix, rows, rowlen;
    short nrow,i,src, value;
    struct stat info;
    int threshold=30;
    int total=0;
    char *err;
    char bits=10;
    int black_level=32;
 
        if ((argc!=2) && (argc!=3)) { printf("usage: %s raw_file <threshold>\n", argv[0]); return 1;}

        if (stat(argv[1],&info)!=0) { printf("file not exist\n"); return 2;}

        switch (info.st_size){
         case (2672*1968*10)/8: rowpix=2672; rows=1968; break; // 5 MP
         case (2664*1968*10)/8: rowpix=2664; rows=1968; break; // another 5 MP
         case (2888*2136*10)/8: rowpix=2888; rows=2136; break; // 6 MP
         case (3152*2340*10)/8: rowpix=3152; rows=2340; break; // 7 MP
         case (3344*2484*10)/8: rowpix=3344; rows=2484; break; // 8 MP
         case (3336*2480*10)/8: rowpix=3336; rows=2480; break; // another 8 MP
         case (3736*2772*10)/8: rowpix=3736; rows=2772; break; // 10 MP
         case (4104*3048*10)/8: rowpix=4104; rows=3048; break; // 12 MP
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! the following two lines are what I am talking about*/
         case (3720*2772*12)/8: rowpix=3720; rows=2772; bits=12; black_level<<=2; threshold<<=2; break; // another 10 MP with 12 bit RAW
         case (4480*3348*12)/8: rowpix=4480; rows=3348; bits=12; break; // 14.7 MP with 12 bit RAW

         default: printf("file is unknown\n"); return 3;
        }

        rowlen=(rowpix*bits)/8;

        fcraw=fopen(argv[1],"r+b");

        if (!fcraw) { printf("cannot open input file\n"); return 4;}

        if (argc==3){
         int thr=strtol(argv[2],&err,0);
         if ((*err) || (thr>((1<<bits)-1-black_level)) || (thr<=0)) {
          printf("invalid threshold, using default value (%d)\n", threshold);
         }
        else threshold=thr;
        }

        out=fopen("badpixel.bin","wb");

        if (!out) { printf("cannot open output file\n"); return 4;}

 
        for (nrow=0; nrow<rows; nrow++) {
            fread(rawrow, 1, rowlen, fcraw);
       
            for (i=0; i<rowpix; i++) {
             if (bits==10) {
              src=(i/8)*10;
              switch (i%8){
                case 0: value=((0x3fc&(((unsigned short)rawrow[src+1])<<2)) | (rawrow[src+0] >> 6)); break;
                case 1: value=((0x3f0&(((unsigned short)rawrow[src+0])<<4)) | (rawrow[src+3] >> 4)); break;
                case 2: value=((0x3c0&(((unsigned short)rawrow[src+3])<<6)) | (rawrow[src+2] >> 2)); break;
                case 3: value=((0x300&(((unsigned short)rawrow[src+2])<<8)) | (rawrow[src+5]));      break;
                case 4: value=((0x3fc&(((unsigned short)rawrow[src+4])<<2)) | (rawrow[src+7] >> 6)); break;
                case 5: value=((0x3f0&(((unsigned short)rawrow[src+7])<<4)) | (rawrow[src+6] >> 4)); break;
                case 6: value=((0x3c0&(((unsigned short)rawrow[src+6])<<6)) | (rawrow[src+9] >> 2)); break;
                case 7: value=((0x300&(((unsigned short)rawrow[src+9])<<8)) | (rawrow[src+8]));      break;
              }
             }
             else if (bits==12) {
              src=(i/4)*6;
              switch (i%4){
                case 0: value=((0xFF0&(((unsigned short)rawrow[src+1])<<4)) | (rawrow[src+0] >> 4)); break;
                case 1: value=((0xF00&(((unsigned short)rawrow[src+0])<<8)) | (rawrow[src+3]     )); break;
                case 2: value=((0xFF0&(((unsigned short)rawrow[src+2])<<4)) | (rawrow[src+5] >> 4)); break;
                case 3: value=((0xF00&(((unsigned short)rawrow[src+5])<<8)) | (rawrow[src+4]     )); break;
              }
             }
             if (value>threshold+black_level) {
              printf("%d,%d=%d\n",i,nrow, value);
              total++;
              fwrite(&i,1, sizeof(i),out);
              fwrite(&nrow,1, sizeof(nrow),out);
             }
            }
         }
     fclose(fcraw);
     fclose(out);
     printf("Total: %d.\n", total);
     return 0;
    }
« Last Edit: 10 / April / 2009, 09:16:23 by bon3fire »

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: badpixel - show_bad_b mod
« Reply #1 on: 13 / April / 2009, 17:47:51 »
i'm not sure i understand what exactly it is that your code does different from the original one. can you please explain a little bit more detailed?

Re: badpixel - show_bad_b mod
« Reply #2 on: 28 / April / 2009, 15:22:00 »
show_bad_b only creates badpixel.bin, you cannot enter a threshold
show_bad only creates badpixel.txt, you can enter a threshold
I needed something that creates badpixel.bin AND lets me choose a threshold, cause show_bad_b did map like 1000 pixels that were ok. That is why i compiled the advantages of both sources and one of them had a additional line on how to handle the raw images. I do not know if I have to change the lower marked line in the source code according to the one above this one.

Hope that helped.
bone

 

Related Topics


SimplePortal © 2008-2014, SimplePortal