PaliGemma: fix image loading.

Use uint8_t to make sure values are not interpreted as signed char.

PiperOrigin-RevId: 680965115
This commit is contained in:
Daniel Keysers 2024-10-01 04:52:57 -07:00 committed by Copybara-Service
parent 7d9fcda0d8
commit dc2e5f1505
1 changed files with 4 additions and 2 deletions

View File

@ -15,6 +15,8 @@
#include "paligemma/image.h" #include "paligemma/image.h"
#include <stdint.h>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
@ -97,8 +99,8 @@ bool Image::ReadPPM(const std::string& filename) {
height_ = height; height_ = height;
int data_size = width * height * 3; int data_size = width * height * 3;
data_.resize(data_size); data_.resize(data_size);
std::vector<char> data_bytes(data_size); std::vector<uint8_t> data_bytes(data_size);
file.read(data_bytes.data(), data_size); file.read(reinterpret_cast<char*>(data_bytes.data()), data_size);
if (file.gcount() != data_size) { if (file.gcount() != data_size) {
std::cerr << "Failed to read " << data_size << " bytes\n"; std::cerr << "Failed to read " << data_size << " bytes\n";
return false; return false;