rip out re encoding code because it does not solve the problem.

This commit is contained in:
Georg Fischer 2013-09-28 14:26:19 +02:00
parent f47c26c09e
commit 65be45c979

View File

@ -6,10 +6,6 @@ define(
var reader; var reader;
var feature; var feature;
var allowed_file_types = [ 'image/png', 'image/jpg', 'image/jpeg' ]; var allowed_file_types = [ 'image/png', 'image/jpg', 'image/jpeg' ];
var re_encode = false;
var tmp_canvas = document.createElement( 'canvas' );
var tmp_ctx = tmp_canvas.getContext( '2d' );
var tmp_img = new Image();
function init( shared ) function init( shared )
{ {
@ -32,49 +28,13 @@ define(
allowed_file_types.indexOf( file.type ) !== -1 allowed_file_types.indexOf( file.type ) !== -1
) )
{ {
re_encode = false; reader.readAsDataURL( file );
// beware of ugly hack:
// jpg images can be progressive, in which case we need to
// convert them to to png to remove the progressive rendering.
// why? because i haven't figured out how to deal with
// progressive jpgs in the glitch logic yet
if ( allowed_file_types.indexOf( file.type ) > 0 )
{
re_encode = true;
}
reader.readAsDataURL( event.dataTransfer.files[0] );
} }
} }
function fileLoaded( event ) function fileLoaded( event )
{ {
var file_src = event.target.result; signals['set-new-src'].dispatch( event.target.result );
if ( re_encode )
{
re_encode = false;
reEncode( file_src, signals['set-new-src'].dispatch );
}
else
{
signals['set-new-src'].dispatch( file_src );
}
}
function reEncode( file_src, callback )
{
tmp_img.onload = function() {
tmp_canvas.width = tmp_img.naturalWidth;
tmp_canvas.height = tmp_img.naturalHeight;
tmp_ctx.drawImage( tmp_img, 0, 0 );
callback( tmp_canvas.toDataURL( 'image/png' ) );
};
tmp_img.src = file_src;
} }
return { init: init }; return { init: init };