Commit 645729cc authored by Andrey Filippov's avatar Andrey Filippov

bug fixing on chunk edges, added optional debug

parent 8040cfa1
......@@ -32,9 +32,8 @@ Found problem - does not process files that start in one file and end in another
define('MIN_JP_LEN', 0x500); // skip from jpeg looking for end marker
define('MAX_IMG_LEN', 0x1000000); // maximal image size (16M) to look for the end marker
define('REQUIRE_EXIF', 1); // JPEG/JP4 must have Exif (more filtering, less false positives)
//define('DEBUG_LEVEL', 3); // Generate debug output
define('DEBUG_LEVEL', 0); //3); // Generate debug output
//define('DEBUG_OUT_FILES',DEBUG_LEVEL? 1 : 0 ); // 1 to add sequence number to result image names (make all unique)
define('DEBUG_LEVEL', 1); // Generate debug output
define('DEBUG_OUT_FILES',DEBUG_LEVEL? 0 : 0 ); // 1 to add sequence number to result image names (make all unique)
//disable the default time limit for php scripts.
set_time_limit(0);
......@@ -270,6 +269,9 @@ function split_file($path, $file, $destination, $add_to_chn = - 1, $next_file =
}
}
fseek($f, $markers[$i]);
if ((DEBUG_LEVEL >= 1)) {
printf("marker: %6d, position 0x%x\n",$i,$markers[$i]);
}
$s = fread($f, $markers[$i + 1] - $markers[$i]);
if ((DEBUG_LEVEL >= 2)) {
if (($i == (count($markers) - 2)) || ($i == 0)) {
......@@ -313,7 +315,18 @@ function split_file($path, $file, $destination, $add_to_chn = - 1, $next_file =
}
} else if ($file_type == 1) { // Tiff
// file_put_contents($tmp_name,$s);
// read continuation if needed
//$s = fread($f, $markers[$i + 1] - $markers[$i]);
if ((strlen($s) < $markers[$i + 1] - $markers[$i]) && $next_path) {
$f1 = fopen($next_path, "r");
$s .= fread($f1, $markers[$i + 1] - $markers[$i] - strlen($s)); // beginning of the next file
fclose($f1);
if (DEBUG_LEVEL >= 0) {
printf("Got continuation of the image from the next file %s\n", $next_path);
}
}
// file_put_contents($tmp_name,$s);
file_put_contents($tmp_name, substr($s, 0, MAX_HEAD_LEN)); // only save beginning of the file
// printf ("header length = %d\n", strlen(substr($s, 0, MAX_HEAD_LEN)));
$result_name = elphel_specific_result_name($tmp_name, $image_length, $add_to_chn);
......@@ -328,7 +341,7 @@ function split_file($path, $file, $destination, $add_to_chn = - 1, $next_file =
}
// rename($tmp_name, $dest_image); // "$path/$destination/$result_name");
file_put_contents($dest_image, substr($s, 0, $image_length));
if ((DEBUG_LEVEL >= 2)) {
if (DEBUG_LEVEL >= 2) {
if ($i == 0) {
file_put_contents($dest_image . ".test", substr($s, 0, $image_length));
printf("2.First image[%d] from img file - %s, length=0x%08x(%d), strlen(s)=%d (%d)\n", $i, $dest_image, $image_length, $image_length, strlen($s), strlen(substr($s, 0, $image_length)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment