Skip to content

Commit

Permalink
+ DNG->CHDK RAW conversion (in file browser).
Browse files Browse the repository at this point in the history
git-svn-id: http://tools.assembla.com/svn/chdk/trunk@666 6794e30b-3f2a-0410-a806-a2bbca1c07ff
  • Loading branch information
EWAVR authored and EWAVR committed Jan 5, 2009
1 parent 0deefbb commit f3309eb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ OBJS=entry.o nothumb.o main.o gui_draw.o gui_menu.o gui_palette.o gui_mbox.o \
gui_fselect.o gui.o kbd.o conf.o \
histogram.o gui_batt.o gui_space.o gui_osd.o script.o raw.o \
gui_lang.o gui_mpopup.o gui_grid.o motion_detector.o raw_merge.o \
luascript.o shot_histogram.o dng_hdr.o $(OPT_OBJS)
luascript.o shot_histogram.o dng.o $(OPT_OBJS)

gui.o: FORCE

Expand Down
41 changes: 41 additions & 0 deletions core/dng_hdr.c → core/dng.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,45 @@ struct t_data_for_exif* capture_data_for_exif(void){
return &data;
}

void convert_dng_to_chdk_raw(char* fn){
#define BUF_SIZE (32768)
FILE *dng, *raw;
int *buf;
int i;
struct stat st;
struct utimbuf t;

if (stat(fn, &st) != 0 || st.st_size<=hook_raw_size()) return;
buf=malloc(BUF_SIZE);
if (buf){
started();
dng=fopen(fn,"rb");
if (dng){
fread(buf, 1, 8, dng);
if (buf[0]==0x2A4949 && buf[1]==8) { // chdk dng header
i=strlen(fn)-3;
if (strncmp(fn+i,"CR",2)==0) strcpy(fn+i,"WAV"); else strcpy(fn+i,"CRW");
raw=fopen(fn,"w+b");
if (raw){
fseek(dng, st.st_size-hook_raw_size(), SEEK_SET); // SEEK_END is not working?
for (i=0; i<hook_raw_size()/BUF_SIZE; i++) {
fread(buf, 1, BUF_SIZE, dng);
reverse_bytes_order((char*)buf, BUF_SIZE);
fwrite(buf, 1, BUF_SIZE, raw);
}
fread(buf, 1, hook_raw_size()%BUF_SIZE, dng);
reverse_bytes_order((char*)buf, hook_raw_size()%BUF_SIZE);
fwrite(buf, 1, hook_raw_size()%BUF_SIZE, raw);
fclose(raw);
t.actime = t.modtime = time(NULL);
utime(fn, &t);
} // if (raw)
} // if chdk dng header
fclose(dng);
} //if (dng)
free(buf);
finished();
} //if (buf)
}

#endif //DNG_SUPPORT
2 changes: 2 additions & 0 deletions core/dng.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ unsigned short get_metering_mode_for_exif(short metering_mode);
int* get_shutter_speed_for_exif(short tv);
int* get_aperture_for_exif(short av);

void convert_dng_to_chdk_raw(char* fn);

#endif
34 changes: 34 additions & 0 deletions core/gui_fselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "raw_merge.h"
#include "raw.h"
#include "conf.h"
#include "dng.h"

//-------------------------------------------------------------------
#define HEAD_LINES 1
Expand Down Expand Up @@ -848,6 +849,30 @@ static void setup_batch_subtract(void) {
gui_mbox_init(LANG_FSELECT_SUBTRACT, (int)buf,
MBOX_TEXT_CENTER|MBOX_BTN_YES_NO|MBOX_DEF_BTN2, fselect_subtract_cb);
}
//-------------------------------------------------------------------
#if DNG_SUPPORT
void process_dng_to_raw_files(void){
struct fitem *ptr;
int i=0;
started();
msleep(100);
finished();

if (fselect_real_marked_count()) {
for (ptr=head; ptr; ptr=ptr->next)
if (ptr->marked && ptr->attr != 0xFF && !(ptr->attr & DOS_ATTR_DIRECTORY)) {
sprintf(selected_file, "%s/%s", current_dir, ptr->name);
gui_browser_progress_show(selected_file, (i++)*100/fselect_real_marked_count()) ;
convert_dng_to_chdk_raw(selected_file);
}
}
else {
sprintf(selected_file, "%s/%s", current_dir, selected->name);
convert_dng_to_chdk_raw(selected_file);
}
gui_fselect_read_dir(current_dir);
}
#endif

//-------------------------------------------------------------------
static void fselect_mpopup_cb(unsigned int actn) {
Expand Down Expand Up @@ -922,6 +947,11 @@ static void fselect_mpopup_cb(unsigned int actn) {
setup_batch_subtract();
break;
}
#if DNG_SUPPORT
case MPOPUP_DNG_TO_CRW:
process_dng_to_raw_files();
break;
#endif
}
gui_fselect_redraw = 2;
}
Expand Down Expand Up @@ -983,6 +1013,10 @@ void gui_fselect_kbd_process() {
i |= MPOPUP_PURGE;//Display PURGE RAW function in popup menu
if(selected->size == hook_raw_size())
i |= MPOPUP_RAW_DEVELOP;
#if DNG_SUPPORT
if((fselect_marked_count()>1)||(selected->size > hook_raw_size()))
i |= MPOPUP_DNG_TO_CRW;
#endif
gui_mpopup_init(i, fselect_mpopup_cb);
}
break;
Expand Down
3 changes: 3 additions & 0 deletions core/gui_mpopup.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ static struct {
{ MPOPUP_RAW_DEVELOP, LANG_MENU_RAW_DEVELOP },
{ MPOPUP_PURGE, LANG_POPUP_PURGE },
{ MPOPUP_SUBTRACT, LANG_POPUP_SUB_FROM_MARKED },
#if DNG_SUPPORT
{ MPOPUP_DNG_TO_CRW, (int)"DNG -> CHDK RAW"},
#endif
};

#define ACTIONSNUM (sizeof(actions)/sizeof(actions[0]))
Expand Down
5 changes: 3 additions & 2 deletions core/gui_mpopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
#define GUI_MPOPUP_H

//-------------------------------------------------------------------
#define MPOPUP_MASK 0x03FF
#define MPOPUP_MASK 0x07FF
#define MPOPUP_CANCEL 0x0800
#define MPOPUP_CUT 0x0001
#define MPOPUP_COPY 0x0002
#define MPOPUP_PASTE 0x0004
#define MPOPUP_DELETE 0x0008
#define MPOPUP_SELINV 0x0010
#define MPOPUP_RAW_ADD 0x0020
#define MPOPUP_RAW_AVERAGE 0x0040
#define MPOPUP_CANCEL 0x0400
#define MPOPUP_PURGE 0x0080
#define MPOPUP_SUBTRACT 0x0100
#define MPOPUP_RAW_DEVELOP 0x0200
#define MPOPUP_DNG_TO_CRW 0x0400

//-------------------------------------------------------------------
extern void gui_mpopup_init(const unsigned int flags, void (*on_select)(unsigned int actn));
Expand Down

0 comments on commit f3309eb

Please sign in to comment.