File sd990.diff of Package dng4ps2

Index: dng4ps2-r62/src/CameraOpts.cpp
===================================================================
--- dng4ps2-r62.orig/src/CameraOpts.cpp
+++ dng4ps2-r62/src/CameraOpts.cpp
@@ -407,8 +407,19 @@ namespace
 			-1, {}, {},
 			L"{11111111-11110000-08a420c3-32f90025}"
 		},
 
+		{ // Canon DIGITAL IXUS 980 IS
+			L"Canon DIGITAL IXUS 980 IS", L"IXUS 980 IS",
+			4480,3348, 10,10,36,12, 4416,3312, 127,4095, MOSAIC_TYPE2,
+			lsDaylight, {		 0.837237f, -0.290137f, -0.128156f,
+			       			-0.127762f,  0.643909f,  0.052973f,
+						 0.004446f,  0.088354f,  0.224246f},
+			{1.0f, 1.0f, 1.0f},
+			-1, {}, {},
+			L"{11111111-11110000-08a420c3-32f90026}"
+		},
+
 		{NULL}
 	};
 
 	void copy_defaults(const CameraDefValue &def, CameraData &item)
@@ -569,9 +580,12 @@ void CameraOpts::sort_by_name()
 }
 
 unsigned int CameraOpts::get_file_size(const CameraData &camera)
 {
-	return (camera.width*camera.height*10)/8;
+	if (camera.white_level < 1024)
+		return (camera.width*camera.height*10)/8;
+	else
+		return (camera.width*camera.height*12)/8;
 }
 
 void CameraOpts::enum_file_sizes(std::vector<size_t> &items)
 {
Index: dng4ps2-r62/src/OptionsDialog.cpp
===================================================================
--- dng4ps2-r62.orig/src/OptionsDialog.cpp
+++ dng4ps2-r62/src/OptionsDialog.cpp
@@ -782,9 +782,13 @@ void OptionsDialog::txtSensWidthText(wxC
 	int size = -1;
 	bool ok = true;
 	if ((width != -1) && (height != -1))
 	{
-		int size_in_bits = (width*height*10);
+ 		int size_in_bits;
+ 		if (get_int(txtWhiteLevel) < 1024)
+ 			size_in_bits = (width*height*10);
+ 		else
+ 			size_in_bits = (width*height*12);
 		size = size_in_bits/8;
 		ok = ((size_in_bits%8) == 0);
 	}
 
Index: dng4ps2-r62/src/Utils.cpp
===================================================================
--- dng4ps2-r62.orig/src/Utils.cpp
+++ dng4ps2-r62/src/Utils.cpp
@@ -753,11 +753,12 @@ inline unsigned short swap_bytes_uint16(
 	return ((lower << 8) | upper);
 }
 
 // Utils::load_raw_file
-void Utils::load_raw_file(const wxString & raw_file_name, size_t file_size, std::vector<unsigned short> & data)
+void Utils::load_raw_file(const wxString & raw_file_name, size_t file_size, std::vector<unsigned short> & data, const int bpp)
 {
-	size_t size = (8*file_size/5)/2;
+	const int mask = (1<<bpp) - 1;
+	size_t size = (8*file_size/(bpp/2))/2;
 	std::vector<unsigned char> raw_data;
 	int vbits=0, buf=0;
 
 	raw_data.resize(file_size);
@@ -773,13 +774,13 @@ void Utils::load_raw_file(const wxString
 	const unsigned short* dp = (const unsigned short*)&raw_data.front();
 	for (size_t i = 0; i < size; i++)
 	{
 #if qDNGBigEndian
-		if (vbits < 10) buf = (vbits += 16, (buf << 16) + swap_bytes_uint16(*dp++));
+		if (vbits < bpp) buf = (vbits += 16, (buf << 16) + swap_bytes_uint16(*dp++));
 #else
-		if (vbits < 10) buf = (vbits += 16, (buf << 16) + *dp++);
+		if (vbits < bpp) buf = (vbits += 16, (buf << 16) + *dp++);
 #endif
-		data[i] = buf >> (vbits -= 10) & 0x3ff;
+		data[i] = buf >> (vbits -= bpp) & mask;
 	}
 }
 
 // Utils::remove_bad_pixels (idea from dcraw)
@@ -922,9 +923,12 @@ void Utils::process_file
 	if (camera == NULL) throw Exception(_("wrong_camera_type"));
 
 	// Load RAW-file
 	if (on_log) on_log(L" ("+wxString(camera->model_name, wxConvLocal)+L") ... ");
-	load_raw_file(raw_file, file_size, raw_data);
+	if (camera->white_level < 1024)
+		load_raw_file(raw_file, file_size, raw_data, 10);
+	else
+		load_raw_file(raw_file, file_size, raw_data, 12);
 	remove_bad_pixels(raw_data, camera->width, camera->height, camera->black_level, camera->mosaic);
 
 	// Read original time
 	wxDateTime dtAccess, dtMod, dtCreate, dtMin;
@@ -1228,9 +1232,12 @@ void Utils::create_raw_image(const Camer
 	offset_x = camera->active_origin_x + (active_area_width - camera->cropped_width)/2;
 	offset_y = camera->active_origin_y + (active_area_height - camera->cropped_height)/2;
 
 	std::vector<unsigned short> raw_data;
-	load_raw_file(raw_file_name, CameraOpts::get_file_size(*camera), raw_data);
+	if (camera->white_level < 1024)
+		load_raw_file(raw_file_name, CameraOpts::get_file_size(*camera), raw_data, 10);
+	else
+		load_raw_file(raw_file_name, CameraOpts::get_file_size(*camera), raw_data, 12);
 	remove_bad_pixels(raw_data, camera->width, camera->height, camera->black_level, camera->mosaic);
 
 	wxBitmap bitmap(camera->cropped_width, camera->cropped_height, 24);
 
Index: dng4ps2-r62/src/Utils.h
===================================================================
--- dng4ps2-r62.orig/src/Utils.h
+++ dng4ps2-r62/src/Utils.h
@@ -34,9 +34,9 @@ struct CorrMNoteData
 
 class Utils
 {
 private:
-    static void load_raw_file(const wxString & raw_file_name, size_t file_size, std::vector<unsigned short> & data);
+    static void load_raw_file(const wxString & raw_file_name, size_t file_size, std::vector<unsigned short> & data, const int bpp);
 
     static unsigned short& pixel(std::vector<unsigned short> & data, int col, int row, int width, int height)
     {
         static unsigned short empty = 0;