Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds basic image size detection for WebP and support in the MediaHandler. Currently renders WebP files as PNGs, because that handles transparency. Bug: T50519 Change-Id: I3c00653a8a034efc3f6b60fe62b7ac2e5391f921
- Loading branch information
Showing
12 changed files
with
543 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.sh eol=lf | ||
*.icc binary | ||
*.webp binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Extractor for the Resource Interchange File Format | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* http://www.gnu.org/copyleft/gpl.html | ||
* | ||
* @file | ||
* @author Bryan Tong Minh | ||
* @ingroup Media | ||
*/ | ||
|
||
class RiffExtractor { | ||
public static function findChunksFromFile( $filename, $maxChunks = -1 ) { | ||
$file = fopen( $filename, 'rb' ); | ||
$info = self::findChunks( $file, $maxChunks ); | ||
fclose( $file ); | ||
return $info; | ||
} | ||
|
||
public static function findChunks( $file, $maxChunks = -1 ) { | ||
$riff = fread( $file, 4 ); | ||
if ( $riff !== 'RIFF' ) { | ||
return false; | ||
} | ||
|
||
// Next four bytes are fileSize | ||
$fileSize = fread( $file, 4 ); | ||
if ( !$fileSize || strlen( $fileSize ) != 4 ) { | ||
return false; | ||
} | ||
|
||
// Next four bytes are the FourCC | ||
$fourCC = fread( $file, 4 ); | ||
if ( !$fourCC || strlen( $fourCC ) != 4 ) { | ||
return false; | ||
} | ||
|
||
// Create basic info structure | ||
$info = array( | ||
'fileSize' => self::extractUInt32( $fileSize ), | ||
'fourCC' => $fourCC, | ||
'chunks' => array(), | ||
); | ||
$numberOfChunks = 0; | ||
|
||
// Find out the chunks | ||
while ( !feof( $file ) && !( $numberOfChunks >= $maxChunks && $maxChunks >= 0 ) ) { | ||
$chunkStart = ftell( $file ); | ||
|
||
$chunkFourCC = fread( $file, 4 ); | ||
if ( !$chunkFourCC || strlen( $chunkFourCC ) != 4 ) { | ||
return $info; | ||
} | ||
|
||
$chunkSize = fread( $file, 4 ); | ||
if ( !$chunkSize || strlen( $chunkSize ) != 4 ) { | ||
return $info; | ||
} | ||
$intChunkSize = self::extractUInt32( $chunkSize ); | ||
|
||
// Add chunk info to the info structure | ||
$info['chunks'][] = array( | ||
'fourCC' => $chunkFourCC, | ||
'start' => $chunkStart, | ||
'size' => $intChunkSize | ||
); | ||
|
||
// Uneven chunks have padding bytes | ||
$padding = $intChunkSize % 2; | ||
// Seek to the next chunk | ||
fseek( $file, $intChunkSize + $padding, SEEK_CUR ); | ||
|
||
} | ||
|
||
return $info; | ||
} | ||
|
||
/** | ||
* Extract a little-endian uint32 from a 4 byte string | ||
* @param string $string 4-byte string | ||
* @return int | ||
*/ | ||
public static function extractUInt32( $string ) { | ||
$unpacked = unpack( 'V', $string ); | ||
return $unpacked[1]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.