Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: third_party/android_opengl/etc1/etc1.cpp

Issue 486093002: Fix thumbnail store crashing on loading old files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2009 Google Inc. 1 // Copyright 2009 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 etc1_encode_block(block, mask, encoded); 580 etc1_encode_block(block, mask, encoded);
581 memcpy(pOut, encoded, sizeof(encoded)); 581 memcpy(pOut, encoded, sizeof(encoded));
582 } else { 582 } else {
583 memset(pOut, 0xFF, sizeof(encoded)); 583 memset(pOut, 0xFF, sizeof(encoded));
584 } 584 }
585 pOut += sizeof(encoded); 585 pOut += sizeof(encoded);
586 } 586 }
587 } 587 }
588 return true; 588 return true;
589 } 589 }
590
591 static const char kMagic[] = { 'P', 'K', 'M', ' ', '1', '0' };
592
593 static const etc1_uint32 ETC1_PKM_FORMAT_OFFSET = 6;
594 static const etc1_uint32 ETC1_PKM_ENCODED_WIDTH_OFFSET = 8;
595 static const etc1_uint32 ETC1_PKM_ENCODED_HEIGHT_OFFSET = 10;
596 static const etc1_uint32 ETC1_PKM_WIDTH_OFFSET = 12;
597 static const etc1_uint32 ETC1_PKM_HEIGHT_OFFSET = 14;
598
599 static const etc1_uint32 ETC1_RGB_NO_MIPMAPS = 0;
600
601 static void writeBEUint16(etc1_byte* pOut, etc1_uint32 data) {
602 pOut[0] = (etc1_byte) (data >> 8);
603 pOut[1] = (etc1_byte) data;
604 }
605
606 static etc1_uint32 readBEUint16(const etc1_byte* pIn) {
607 return (pIn[0] << 8) | pIn[1];
608 }
609
610 // Format a PKM header
611
612 void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 h eight) {
613 memcpy(pHeader, kMagic, sizeof(kMagic));
614 etc1_uint32 encodedWidth = (width + 3) & ~3;
Ted C 2014/08/19 16:51:09 what sort of witch craft is all this magic?
David Trainor- moved to gerrit 2014/08/19 18:31:07 The kind that is brought back from the original et
615 etc1_uint32 encodedHeight = (height + 3) & ~3;
616 writeBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET, ETC1_RGB_NO_MIPMAPS);
617 writeBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFFSET, encodedWidth);
618 writeBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_OFFSET, encodedHeight);
619 writeBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET, width);
620 writeBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET, height);
621 }
622
623 // Check if a PKM header is correctly formatted.
624
625 bool etc1_pkm_is_valid(const etc1_byte* pHeader) {
626 if (memcmp(pHeader, kMagic, sizeof(kMagic))) {
627 return false;
628 }
629 etc1_uint32 format = readBEUint16(pHeader + ETC1_PKM_FORMAT_OFFSET);
630 etc1_uint32 encodedWidth = readBEUint16(pHeader + ETC1_PKM_ENCODED_WIDTH_OFF SET);
631 etc1_uint32 encodedHeight = readBEUint16(pHeader + ETC1_PKM_ENCODED_HEIGHT_O FFSET);
632 etc1_uint32 width = readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET);
633 etc1_uint32 height = readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET);
634 return format == ETC1_RGB_NO_MIPMAPS &&
635 encodedWidth >= width && encodedWidth - width < 4 &&
636 encodedHeight >= height && encodedHeight - height < 4;
637 }
638
639 // Read the image width from a PKM header
640
641 etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader) {
642 return readBEUint16(pHeader + ETC1_PKM_WIDTH_OFFSET);
643 }
644
645 // Read the image height from a PKM header
646
647 etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader){
648 return readBEUint16(pHeader + ETC1_PKM_HEIGHT_OFFSET);
649 }
OLDNEW
« chrome/browser/android/thumbnail/thumbnail_store.cc ('K') | « third_party/android_opengl/etc1/etc1.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698