2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2007-06-25 19:50:25 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbdds
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2007-06-25 19:50:25 +00:00
|
|
|
/*
|
|
|
|
|
* This file is based on a similar file from the NVIDIA texture tools
|
|
|
|
|
* (http://nvidia-texture-tools.googlecode.com/)
|
|
|
|
|
*
|
|
|
|
|
* Original license from NVIDIA follows.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* This code is in the public domain -- <castanyo@yahoo.es>. */
|
|
|
|
|
|
|
|
|
|
#include <Color.h>
|
|
|
|
|
#include <Image.h>
|
|
|
|
|
|
2020-12-04 11:28:09 +01:00
|
|
|
#include <cstdio> /* printf */
|
2007-06-25 19:50:25 +00:00
|
|
|
|
2020-11-06 17:49:09 +01:00
|
|
|
Image::Image() : m_width(0), m_height(0), m_format(Format_RGB), m_data(nullptr)
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Image::~Image()
|
|
|
|
|
{
|
|
|
|
|
free();
|
|
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
void Image::allocate(uint w, uint h)
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
free();
|
|
|
|
|
m_width = w;
|
|
|
|
|
m_height = h;
|
|
|
|
|
m_data = new Color32[w * h];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Image::free()
|
|
|
|
|
{
|
2020-07-03 16:44:46 +02:00
|
|
|
delete[] m_data;
|
2020-11-06 17:49:09 +01:00
|
|
|
m_data = nullptr;
|
2007-06-25 19:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
uint Image::width() const
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
return m_width;
|
|
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
uint Image::height() const
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
return m_height;
|
|
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
const Color32 *Image::scanline(uint h) const
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
if (h >= m_height) {
|
2015-11-16 11:59:15 +11:00
|
|
|
printf("DDS: scanline beyond dimensions of image\n");
|
2007-06-25 19:50:25 +00:00
|
|
|
return m_data;
|
|
|
|
|
}
|
|
|
|
|
return m_data + h * m_width;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 08:49:28 +11:00
|
|
|
Color32 *Image::scanline(uint h)
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
if (h >= m_height) {
|
2015-11-16 11:59:15 +11:00
|
|
|
printf("DDS: scanline beyond dimensions of image\n");
|
2007-06-25 19:50:25 +00:00
|
|
|
return m_data;
|
|
|
|
|
}
|
|
|
|
|
return m_data + h * m_width;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 08:49:28 +11:00
|
|
|
const Color32 *Image::pixels() const
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
return m_data;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 08:49:28 +11:00
|
|
|
Color32 *Image::pixels()
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
return m_data;
|
|
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
const Color32 &Image::pixel(uint idx) const
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
if (idx >= m_width * m_height) {
|
2015-11-16 11:59:15 +11:00
|
|
|
printf("DDS: pixel beyond dimensions of image\n");
|
2007-06-25 19:50:25 +00:00
|
|
|
return m_data[0];
|
|
|
|
|
}
|
|
|
|
|
return m_data[idx];
|
|
|
|
|
}
|
|
|
|
|
|
This is patch: [#7975] imbuf for DDS textures: improved read support and a few bugs fixed
Kent
Notes From the author:
The attached patch syncs the DDS code in Blender with the latest revision
(324) of the nvidia texture tools. This fixes a few minor issues and adds
support for a more types of DDS textures, in particular uncompressed textures
that don't have the standard 16, 24, or 32 bits per pixel.
Note: I have started using the nvidia texture tools convention for naming
integer types (uint, uint16, uint8, uint64 etc.) because doing so makes it
much easier to merge patches from upstream. Since the code is compiled
separately from the rest of Blender, this likely does not pose a problem.
However, if there turns out to be a good reason for avoiding those nvidia type
names from upstream, I'd be happy to fix it.
Regards,
Amorilia
2007-12-26 21:46:30 +00:00
|
|
|
Color32 &Image::pixel(uint idx)
|
2007-06-25 19:50:25 +00:00
|
|
|
{
|
|
|
|
|
if (idx >= m_width * m_height) {
|
2015-11-16 11:59:15 +11:00
|
|
|
printf("DDS: pixel beyond dimensions of image\n");
|
2007-06-25 19:50:25 +00:00
|
|
|
return m_data[0];
|
|
|
|
|
}
|
|
|
|
|
return m_data[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Image::Format Image::format() const
|
|
|
|
|
{
|
|
|
|
|
return m_format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Image::setFormat(Image::Format f)
|
|
|
|
|
{
|
|
|
|
|
m_format = f;
|
|
|
|
|
}
|