Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-23 04:01:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-23 04:22:22 +0300
commit64b4b719ebd5201d27aa25d7fa2d765eabded9b0 (patch)
treec6e1147f3b81b90193d3acaa0df3f8c5c93db328 /source/blender/imbuf/intern/dds
parentac53291e1ff79144ca41d63b0787bfe04da21677 (diff)
Cleanup: style, use braces for imbuf
Diffstat (limited to 'source/blender/imbuf/intern/dds')
-rw-r--r--source/blender/imbuf/intern/dds/BlockDXT.cpp3
-rw-r--r--source/blender/imbuf/intern/dds/ColorBlock.cpp18
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.cpp171
-rw-r--r--source/blender/imbuf/intern/dds/FlipDXT.cpp9
-rw-r--r--source/blender/imbuf/intern/dds/Image.cpp3
-rw-r--r--source/blender/imbuf/intern/dds/Image.h4
-rw-r--r--source/blender/imbuf/intern/dds/PixelFormat.h2
-rw-r--r--source/blender/imbuf/intern/dds/dds_api.cpp30
8 files changed, 158 insertions, 82 deletions
diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp
index f960faee1ab..b1ca6221753 100644
--- a/source/blender/imbuf/intern/dds/BlockDXT.cpp
+++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp
@@ -610,8 +610,9 @@ void mem_read(Stream &mem, BlockDXT1 &block)
void mem_read(Stream &mem, AlphaBlockDXT3 &block)
{
- for (unsigned int i = 0; i < 4; i++)
+ for (unsigned int i = 0; i < 4; i++) {
mem_read(mem, block.row[i]);
+ }
}
void mem_read(Stream &mem, BlockDXT3 &block)
diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp
index c392ef351ff..581d740c97c 100644
--- a/source/blender/imbuf/intern/dds/ColorBlock.cpp
+++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp
@@ -130,16 +130,21 @@ void ColorBlock::init(uint w, uint h, const float *data, uint x, uint y)
static inline uint8 component(Color32 c, uint i)
{
- if (i == 0)
+ if (i == 0) {
return c.r;
- if (i == 1)
+ }
+ if (i == 1) {
return c.g;
- if (i == 2)
+ }
+ if (i == 2) {
return c.b;
- if (i == 3)
+ }
+ if (i == 3) {
return c.a;
- if (i == 4)
+ }
+ if (i == 4) {
return 0xFF;
+ }
return 0;
}
@@ -238,8 +243,9 @@ Color32 ColorBlock::averageColor() const
bool ColorBlock::hasAlpha() const
{
for (uint i = 0; i < 16; i++) {
- if (m_color[i].a != 255)
+ if (m_color[i].a != 255) {
return true;
+ }
}
return false;
}
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
index 89fe3bf5f25..abe8a0c1883 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
@@ -479,8 +479,9 @@ void mem_read(Stream &mem, DDSHeader &header)
mem_read(mem, header.pitch);
mem_read(mem, header.depth);
mem_read(mem, header.mipmapcount);
- for (uint i = 0; i < 11; i++)
+ for (uint i = 0; i < 11; i++) {
mem_read(mem, header.reserved[i]);
+ }
mem_read(mem, header.pf);
mem_read(mem, header.caps);
mem_read(mem, header.notused);
@@ -550,8 +551,9 @@ DDSHeader::DDSHeader()
this->pitch = 0;
this->depth = 0;
this->mipmapcount = 0;
- for (uint i = 0; i < 11; i++)
+ for (uint i = 0; i < 11; i++) {
this->reserved[i] = 0;
+ }
// Store version information on the reserved header attributes.
this->reserved[9] = FOURCC_NVTT;
@@ -747,26 +749,32 @@ void DDSHeader::setDX10Format(uint format)
void DDSHeader::setNormalFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_NORMAL;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_NORMAL;
+ }
}
void DDSHeader::setSrgbFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_SRGB;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_SRGB;
+ }
}
void DDSHeader::setHasAlphaFlag(bool b)
{
- if (b)
+ if (b) {
this->pf.flags |= DDPF_ALPHAPIXELS;
- else
+ }
+ else {
this->pf.flags &= ~DDPF_ALPHAPIXELS;
+ }
}
void DDSHeader::setUserVersion(int version)
@@ -868,8 +876,9 @@ DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : stream(mem
// some ATI2 compressed normal maps do not have their
// normal flag set, so force it here (the original nvtt don't do
// this, but the decompressor has a -forcenormal flag)
- if (header.pf.fourcc == FOURCC_ATI2)
+ if (header.pf.fourcc == FOURCC_ATI2) {
header.setNormalFlag(true);
+ }
}
DirectDrawSurface::~DirectDrawSurface()
@@ -975,10 +984,12 @@ bool DirectDrawSurface::hasAlpha() const
uint DirectDrawSurface::mipmapCount() const
{
- if (header.flags & DDSD_MIPMAPCOUNT)
+ if (header.flags & DDSD_MIPMAPCOUNT) {
return header.mipmapcount;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::fourCC() const
@@ -988,26 +999,32 @@ uint DirectDrawSurface::fourCC() const
uint DirectDrawSurface::width() const
{
- if (header.flags & DDSD_WIDTH)
+ if (header.flags & DDSD_WIDTH) {
return header.width;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::height() const
{
- if (header.flags & DDSD_HEIGHT)
+ if (header.flags & DDSD_HEIGHT) {
return header.height;
- else
+ }
+ else {
return 1;
+ }
}
uint DirectDrawSurface::depth() const
{
- if (header.flags & DDSD_DEPTH)
+ if (header.flags & DDSD_DEPTH) {
return header.depth;
- else
+ }
+ else {
return 1;
+ }
}
bool DirectDrawSurface::isTexture1D() const
@@ -1196,8 +1213,9 @@ static Color32 buildNormal(uint8 x, uint8 y)
float nx = 2 * (x / 255.0f) - 1;
float ny = 2 * (y / 255.0f) - 1;
float nz = 0.0f;
- if (1 - nx * nx - ny * ny > 0)
+ if (1 - nx * nx - ny * ny > 0) {
nz = sqrt(1 - nx * nx - ny * ny);
+ }
uint8 z = CLAMP(int(255.0f * (nz + 1) / 2.0f), 0, 255);
return Color32(x, y, z);
@@ -1209,16 +1227,21 @@ void DirectDrawSurface::readBlock(ColorBlock *rgba)
// Map DX10 block formats to fourcc codes.
if (header.hasDX10Header()) {
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM)
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM) {
fourcc = FOURCC_DXT1;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM) {
fourcc = FOURCC_DXT3;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM) {
fourcc = FOURCC_DXT5;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC4_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC4_UNORM) {
fourcc = FOURCC_ATI1;
- if (header.header10.dxgiFormat == DXGI_FORMAT_BC5_UNORM)
+ }
+ if (header.header10.dxgiFormat == DXGI_FORMAT_BC5_UNORM) {
fourcc = FOURCC_ATI2;
+ }
}
if (fourcc == FOURCC_DXT1) {
@@ -1307,8 +1330,8 @@ uint DirectDrawSurface::blockSize() const
case DXGI_FORMAT_BC5_UNORM:
case DXGI_FORMAT_BC5_SNORM:
return 16;
- };
- };
+ }
+ }
// Not a block image.
return 0;
@@ -1341,7 +1364,7 @@ uint DirectDrawSurface::mipmapSize(uint mipmap) const
else {
printf("DDS: mipmap format not supported\n");
return (0);
- };
+ }
}
uint DirectDrawSurface::faceSize() const
@@ -1378,56 +1401,77 @@ uint DirectDrawSurface::offset(const uint face, const uint mipmap)
void DirectDrawSurface::printInfo() const
{
printf("Flags: 0x%.8X\n", header.flags);
- if (header.flags & DDSD_CAPS)
+ if (header.flags & DDSD_CAPS) {
printf("\tDDSD_CAPS\n");
- if (header.flags & DDSD_PIXELFORMAT)
+ }
+ if (header.flags & DDSD_PIXELFORMAT) {
printf("\tDDSD_PIXELFORMAT\n");
- if (header.flags & DDSD_WIDTH)
+ }
+ if (header.flags & DDSD_WIDTH) {
printf("\tDDSD_WIDTH\n");
- if (header.flags & DDSD_HEIGHT)
+ }
+ if (header.flags & DDSD_HEIGHT) {
printf("\tDDSD_HEIGHT\n");
- if (header.flags & DDSD_DEPTH)
+ }
+ if (header.flags & DDSD_DEPTH) {
printf("\tDDSD_DEPTH\n");
- if (header.flags & DDSD_PITCH)
+ }
+ if (header.flags & DDSD_PITCH) {
printf("\tDDSD_PITCH\n");
- if (header.flags & DDSD_LINEARSIZE)
+ }
+ if (header.flags & DDSD_LINEARSIZE) {
printf("\tDDSD_LINEARSIZE\n");
- if (header.flags & DDSD_MIPMAPCOUNT)
+ }
+ if (header.flags & DDSD_MIPMAPCOUNT) {
printf("\tDDSD_MIPMAPCOUNT\n");
+ }
printf("Height: %u\n", header.height);
printf("Width: %u\n", header.width);
printf("Depth: %u\n", header.depth);
- if (header.flags & DDSD_PITCH)
+ if (header.flags & DDSD_PITCH) {
printf("Pitch: %u\n", header.pitch);
- else if (header.flags & DDSD_LINEARSIZE)
+ }
+ else if (header.flags & DDSD_LINEARSIZE) {
printf("Linear size: %u\n", header.pitch);
+ }
printf("Mipmap count: %u\n", header.mipmapcount);
printf("Pixel Format:\n");
printf("\tFlags: 0x%.8X\n", header.pf.flags);
- if (header.pf.flags & DDPF_RGB)
+ if (header.pf.flags & DDPF_RGB) {
printf("\t\tDDPF_RGB\n");
- if (header.pf.flags & DDPF_LUMINANCE)
+ }
+ if (header.pf.flags & DDPF_LUMINANCE) {
printf("\t\tDDPF_LUMINANCE\n");
- if (header.pf.flags & DDPF_FOURCC)
+ }
+ if (header.pf.flags & DDPF_FOURCC) {
printf("\t\tDDPF_FOURCC\n");
- if (header.pf.flags & DDPF_ALPHAPIXELS)
+ }
+ if (header.pf.flags & DDPF_ALPHAPIXELS) {
printf("\t\tDDPF_ALPHAPIXELS\n");
- if (header.pf.flags & DDPF_ALPHA)
+ }
+ if (header.pf.flags & DDPF_ALPHA) {
printf("\t\tDDPF_ALPHA\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED1)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED1) {
printf("\t\tDDPF_PALETTEINDEXED1\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED2)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED2) {
printf("\t\tDDPF_PALETTEINDEXED2\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED4)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED4) {
printf("\t\tDDPF_PALETTEINDEXED4\n");
- if (header.pf.flags & DDPF_PALETTEINDEXED8)
+ }
+ if (header.pf.flags & DDPF_PALETTEINDEXED8) {
printf("\t\tDDPF_PALETTEINDEXED8\n");
- if (header.pf.flags & DDPF_ALPHAPREMULT)
+ }
+ if (header.pf.flags & DDPF_ALPHAPREMULT) {
printf("\t\tDDPF_ALPHAPREMULT\n");
- if (header.pf.flags & DDPF_NORMAL)
+ }
+ if (header.pf.flags & DDPF_NORMAL) {
printf("\t\tDDPF_NORMAL\n");
+ }
if (header.pf.fourcc != 0) {
// Display fourcc code even when DDPF_FOURCC flag not set.
@@ -1458,33 +1502,44 @@ void DirectDrawSurface::printInfo() const
printf("Caps:\n");
printf("\tCaps 1: 0x%.8X\n", header.caps.caps1);
- if (header.caps.caps1 & DDSCAPS_COMPLEX)
+ if (header.caps.caps1 & DDSCAPS_COMPLEX) {
printf("\t\tDDSCAPS_COMPLEX\n");
- if (header.caps.caps1 & DDSCAPS_TEXTURE)
+ }
+ if (header.caps.caps1 & DDSCAPS_TEXTURE) {
printf("\t\tDDSCAPS_TEXTURE\n");
- if (header.caps.caps1 & DDSCAPS_MIPMAP)
+ }
+ if (header.caps.caps1 & DDSCAPS_MIPMAP) {
printf("\t\tDDSCAPS_MIPMAP\n");
+ }
printf("\tCaps 2: 0x%.8X\n", header.caps.caps2);
- if (header.caps.caps2 & DDSCAPS2_VOLUME)
+ if (header.caps.caps2 & DDSCAPS2_VOLUME) {
printf("\t\tDDSCAPS2_VOLUME\n");
+ }
else if (header.caps.caps2 & DDSCAPS2_CUBEMAP) {
printf("\t\tDDSCAPS2_CUBEMAP\n");
- if ((header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) == DDSCAPS2_CUBEMAP_ALL_FACES)
+ if ((header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) == DDSCAPS2_CUBEMAP_ALL_FACES) {
printf("\t\tDDSCAPS2_CUBEMAP_ALL_FACES\n");
+ }
else {
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX)
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEX) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEX\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEX\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEY) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEY\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEY\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ) {
printf("\t\tDDSCAPS2_CUBEMAP_POSITIVEZ\n");
- if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ)
+ }
+ if (header.caps.caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ) {
printf("\t\tDDSCAPS2_CUBEMAP_NEGATIVEZ\n");
+ }
}
}
diff --git a/source/blender/imbuf/intern/dds/FlipDXT.cpp b/source/blender/imbuf/intern/dds/FlipDXT.cpp
index 0660d5ce5cc..cf228cea3ea 100644
--- a/source/blender/imbuf/intern/dds/FlipDXT.cpp
+++ b/source/blender/imbuf/intern/dds/FlipDXT.cpp
@@ -173,11 +173,13 @@ int FlipDXTCImage(
unsigned int width, unsigned int height, unsigned int levels, int fourcc, uint8_t *data)
{
// must have valid dimensions
- if (width == 0 || height == 0)
+ if (width == 0 || height == 0) {
return 0;
+ }
// height must be a power-of-two
- if ((height & (height - 1)) != 0)
+ if ((height & (height - 1)) != 0) {
return 0;
+ }
FlipBlockFunction full_block_function;
FlipBlockFunction half_block_function;
@@ -223,8 +225,9 @@ int FlipDXTCImage(
}
else {
// flip each block.
- for (unsigned int i = 0; i < blocks; ++i)
+ for (unsigned int i = 0; i < blocks; ++i) {
full_block_function(data + i * block_bytes);
+ }
// swap each block line in the first half of the image with the
// corresponding one in the second half.
diff --git a/source/blender/imbuf/intern/dds/Image.cpp b/source/blender/imbuf/intern/dds/Image.cpp
index 6f0fff75818..d08a61a5a60 100644
--- a/source/blender/imbuf/intern/dds/Image.cpp
+++ b/source/blender/imbuf/intern/dds/Image.cpp
@@ -51,8 +51,9 @@ void Image::allocate(uint w, uint h)
void Image::free()
{
- if (m_data)
+ if (m_data) {
delete[] m_data;
+ }
m_data = NULL;
}
diff --git a/source/blender/imbuf/intern/dds/Image.h b/source/blender/imbuf/intern/dds/Image.h
index b6191b7e96c..1aa60ef48ca 100644
--- a/source/blender/imbuf/intern/dds/Image.h
+++ b/source/blender/imbuf/intern/dds/Image.h
@@ -30,8 +30,8 @@
#ifndef __IMAGE_H__
#define __IMAGE_H__
-#include <Common.h>
-#include <Color.h>
+#include "Common.h"
+#include "Color.h"
/// 32 bit RGBA image.
class Image {
diff --git a/source/blender/imbuf/intern/dds/PixelFormat.h b/source/blender/imbuf/intern/dds/PixelFormat.h
index ba487afdfc1..e63b17c89e5 100644
--- a/source/blender/imbuf/intern/dds/PixelFormat.h
+++ b/source/blender/imbuf/intern/dds/PixelFormat.h
@@ -51,7 +51,7 @@
#ifndef __PIXELFORMAT_H__
#define __PIXELFORMAT_H__
-#include <Common.h>
+#include "Common.h"
namespace PixelFormat {
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp
index 6a76e231e37..098b695b8a3 100644
--- a/source/blender/imbuf/intern/dds/dds_api.cpp
+++ b/source/blender/imbuf/intern/dds/dds_api.cpp
@@ -49,10 +49,12 @@ int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/)
return (0); /* todo: finish this function */
/* check image buffer */
- if (ibuf == 0)
+ if (ibuf == 0) {
return (0);
- if (ibuf->rect == 0)
+ }
+ if (ibuf->rect == 0) {
return (0);
+ }
/* open file for writing */
std::ofstream fildes;
@@ -76,11 +78,13 @@ int imb_is_a_dds(const unsigned char *mem) // note: use at most first 32 bytes
{
/* heuristic check to see if mem contains a DDS file */
/* header.fourcc == FOURCC_DDS */
- if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' '))
+ if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) {
return (0);
+ }
/* header.size == 124 */
- if ((mem[4] != 124) || mem[5] || mem[6] || mem[7])
+ if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) {
return (0);
+ }
return (1);
}
@@ -106,14 +110,16 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
*/
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
- if (!imb_is_a_dds(mem))
+ if (!imb_is_a_dds(mem)) {
return (0);
+ }
/* check if DDS is valid and supported */
if (!dds.isValid()) {
/* no need to print error here, just testing if it is a DDS */
- if (flags & IB_test)
+ if (flags & IB_test) {
return (0);
+ }
printf("DDS: not valid; header follows\n");
dds.printInfo();
@@ -144,18 +150,21 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
}
}
ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0);
- if (ibuf == 0)
+ if (ibuf == 0) {
return (0); /* memory allocation failed */
+ }
ibuf->ftype = IMB_FTYPE_DDS;
ibuf->dds_data.fourcc = dds.fourCC();
ibuf->dds_data.nummipmaps = dds.mipmapCount();
if ((flags & IB_test) == 0) {
- if (!imb_addrectImBuf(ibuf))
+ if (!imb_addrectImBuf(ibuf)) {
return (ibuf);
- if (ibuf->rect == 0)
+ }
+ if (ibuf->rect == 0) {
return (ibuf);
+ }
rect = ibuf->rect;
cp[3] = 0xff; /* default alpha if alpha channel is not present */
@@ -165,8 +174,9 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
cp[0] = pixel.r; /* set R component of col */
cp[1] = pixel.g; /* set G component of col */
cp[2] = pixel.b; /* set B component of col */
- if (dds.hasAlpha())
+ if (dds.hasAlpha()) {
cp[3] = pixel.a; /* set A component of col */
+ }
rect[i] = col;
}