Skip to content

Commit 5398a4e

Browse files
committed
further simplification
1 parent c903587 commit 5398a4e

File tree

4 files changed

+17
-111
lines changed

4 files changed

+17
-111
lines changed

modules/mrpt_img/include/mrpt/img/CImage.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class CExceptionExternalImageNotFound : public std::runtime_error
8989
* the methods CImage::loadFromFile() and CImage::saveToFile(). This uses the [stb
9090
* library](https://github.com/nothings/stb).
9191
* - Importing from an XPM array (.xpm file format) using CImage::loadFromXPM()
92-
* - Importing TGA images. See CImage::loadTGA()
9392
* - Binary dump using the CSerializable interface(<< and >> operators),
9493
*just as most objects in MRPT. This format is not compatible with any
9594
*standardized image format but it is fast.
@@ -825,10 +824,10 @@ class CImage : public mrpt::serialization::CSerializable, public CCanvas
825824
* (internally uses OpenCV).
826825
* \param fileName The file to read from.
827826
*
828-
* MRPT also provides the special loaders loadFromXPM() and loadTGA().
827+
* MRPT also provides the special loader loadFromXPM().
829828
*
830829
* \return False on any error
831-
* \sa saveToFile, setExternalStorage,loadFromXPM, loadTGA
830+
* \sa saveToFile, setExternalStorage,loadFromXPM
832831
*/
833832
[[nodiscard]] bool loadFromFile(
834833
const std::string& fileName, TImageChannels loadChannels = CH_AS_IS);
@@ -842,13 +841,6 @@ class CImage : public mrpt::serialization::CSerializable, public CCanvas
842841
[[nodiscard]] static mrpt::img::CImage LoadFromFile(
843842
const std::string& fileName, TImageChannels loadChannels = CH_AS_IS);
844843

845-
/** Loads a TGA true-color RGBA image as two CImage objects, one for the RGB
846-
* channels plus a separate gray-level image with A channel.
847-
* \return true on success
848-
*/
849-
[[nodiscard]] static bool LoadTGA(
850-
const std::string& fileName, mrpt::img::CImage& out_RGB, mrpt::img::CImage& out_alpha);
851-
852844
/** Loads the image from an XPM array, as included from a ".xpm" file.
853845
* \param[in] swap_rb Swaps red/blue channels from loaded image. *Seems* to
854846
* be always needed, so it's enabled by default.

modules/mrpt_img/src/CCanvas.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,29 @@ void CCanvas::drawImage(const TPixelCoord& pt, const mrpt::img::CImage& img)
250250

251251
if (img.isColor())
252252
{
253-
for (unsigned int xx = 0; xx < img_lx; xx++)
253+
for (int32_t xx = 0; xx < img_lx; xx++)
254254
{
255-
for (unsigned int yy = 0; yy < img_ly; yy++)
255+
for (int32_t yy = 0; yy < img_ly; yy++)
256256
{
257257
auto ptr = img.ptr<uint8_t>(xx, yy);
258258
const int p = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
259-
setPixel(x + xx, y + yy, p);
259+
setPixel(pt.x + xx, pt.y + yy, p);
260260
}
261261
}
262262
}
263263
else
264264
{
265265
unsigned char c;
266266
int col;
267-
for (int xx = 0; xx < img_lx; xx++)
268-
for (int yy = 0; yy < img_ly; yy++)
267+
for (int32_t xx = 0; xx < img_lx; xx++)
268+
{
269+
for (int32_t yy = 0; yy < img_ly; yy++)
269270
{
270271
c = *((unsigned char*)img(xx, yy));
271272
col = c | (c << 8) | (c << 16);
272-
setPixel(x + xx, y + yy, col);
273+
setPixel(pt.x + xx, pt.y + yy, col);
273274
}
275+
}
274276
}
275277

276278
MRPT_END

modules/mrpt_img/src/CImage.cpp

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,93 +1625,12 @@ float CImage::KLT_response(const TPixelCoord& pt, const int32_t half_window_size
16251625
return 0.5f * (t - std::sqrt(discr));
16261626
}
16271627

1628-
// Load from TGA files. Used in loadFromFile()
1629-
// Contains code from
1630-
// https://github.com/tjohnman/Simple-Targa-Library/blob/master/src/simpleTGA.cpp
1631-
// (FreeBSD license)
1632-
bool CImage::LoadTGA(
1633-
const std::string& fileName, mrpt::img::CImage& out_RGB, mrpt::img::CImage& out_alpha)
1634-
{
1635-
std::fstream stream;
1636-
stream.open(fileName.c_str(), std::fstream::in | std::fstream::binary);
1637-
if (!stream.is_open())
1638-
{
1639-
std::cerr << "[CImage::loadTGA] Couldn't open file '" << fileName << "'.\n";
1640-
return false;
1641-
}
1642-
1643-
stream.seekg(0, std::ios_base::end);
1644-
// long length = stream.tellg();
1645-
stream.seekg(0, std::ios_base::beg);
1646-
1647-
// Simple uncompressed true-color image
1648-
char dumpBuffer[12];
1649-
char trueColorHeader[] = "\0\0\2\0\0\0\0\0\0\0\0\0";
1650-
stream.read(dumpBuffer, 12);
1651-
if (memcmp(dumpBuffer, trueColorHeader, 12) != 0)
1652-
{
1653-
std::cerr << "[CImage::loadTGA] Unsupported format or invalid file.\n";
1654-
return false;
1655-
}
1656-
1657-
unsigned short width, height;
1658-
uint8_t bpp;
1659-
1660-
stream.read((char*)&width, 2);
1661-
stream.read((char*)&height, 2);
1662-
bpp = stream.get();
1663-
if (bpp != 32)
1664-
{
1665-
std::cerr << "[CImage::loadTGA] Only 32 bpp format supported!\n";
1666-
return false;
1667-
}
1668-
1669-
uint8_t desc;
1670-
desc = stream.get();
1671-
if (desc != 8 && desc != 32)
1672-
{
1673-
std::cerr << "[CImage::loadTGA] Unsupported format or invalid file.\n";
1674-
return false;
1675-
}
1676-
const bool origin_is_low_corner = (desc == 8);
1677-
1678-
// Data section
1679-
std::vector<uint8_t> bytes(width * height * 4);
1680-
stream.read((char*)&bytes[0], width * height * 4);
1681-
stream.close();
1682-
1683-
// Move data to images:
1684-
out_RGB.resize(width, height, CH_RGB);
1685-
out_alpha.resize(width, height, CH_GRAY);
1686-
1687-
size_t idx = 0;
1688-
for (int r = 0; r < height; r++)
1689-
{
1690-
const auto actual_row = origin_is_low_corner ? (height - 1 - r) : r;
1691-
auto& img = out_RGB.m_state->img;
1692-
auto data = img.ptr<uint8_t>(actual_row);
1693-
1694-
auto& img_alpha = out_alpha.m_state->img;
1695-
auto data_alpha = img_alpha.ptr<uint8_t>(actual_row);
1696-
1697-
for (unsigned int c = 0; c < width; c++)
1698-
{
1699-
*data++ = bytes[idx++]; // R
1700-
*data++ = bytes[idx++]; // G
1701-
*data++ = bytes[idx++]; // B
1702-
*data_alpha++ = bytes[idx++]; // A
1703-
}
1704-
}
1705-
1706-
return true;
1707-
}
1708-
1709-
std::ostream& mrpt::img::operator<<(std::ostream& o, const TPixelCoordf& p)
1628+
std::ostream& operator<<(std::ostream& o, const TPixelCoordf& p)
17101629
{
17111630
o << "(" << p.x << "," << p.y << ")";
17121631
return o;
17131632
}
1714-
std::ostream& mrpt::img::operator<<(std::ostream& o, const TPixelCoord& p)
1633+
std::ostream& operator<<(std::ostream& o, const TPixelCoord& p)
17151634
{
17161635
o << "(" << p.x << "," << p.y << ")";
17171636
return o;

modules/mrpt_opengl/src/CAssimpModel.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,14 @@ class TexturesCache
8989
if (entry.load_attempted) return entry;
9090

9191
// Load images:
92-
// TGA is handled specially since it's not supported by OpenCV:
93-
if (mrpt::system::lowerCase(mrpt::system::extractFileExtension(texturePath)) == "tga"s)
94-
{
95-
entry.img_alpha.emplace();
96-
97-
entry.load_ok = mrpt::img::CImage::loadTGA(texturePath, entry.img_rgb, *entry.img_alpha);
98-
}
99-
else
100-
{
101-
entry.load_ok = entry.img_rgb.loadFromFile(texturePath);
102-
}
92+
entry.load_ok = entry.img_rgb.loadFromFile(texturePath);
10393

10494
if (entry.load_ok)
10595
{
106-
if (verboseLoad) std::cout << "[CAssimpModel] Loaded texture: " << texturePath << "\n";
96+
if (verboseLoad)
97+
{
98+
std::cout << "[CAssimpModel] Loaded texture: " << texturePath << "\n";
99+
}
107100
}
108101
#if MRPT_HAS_ASSIMP && MRPT_HAS_OPENCV
109102
else if (scene->HasTextures())

0 commit comments

Comments
 (0)