Browse Source

image: fix a bug introduced in the image conversion refactoring.

undefined
Sam Hocevar 11 years ago
parent
commit
c727182ac0
2 changed files with 16 additions and 12 deletions
  1. +6
    -5
      src/image/pixel.cpp
  2. +10
    -7
      src/lol/image/pixel.h

+ 6
- 5
src/image/pixel.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright: (c) 2004-2014 Sam Hocevar <sam@hocevar.net>
// Copyright: © 2004—2014 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To // modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See // Public License, Version 2, as published by Sam Hocevar. See
@@ -276,15 +276,15 @@ void Image::SetFormat(PixelFormat fmt)
dest[n] = u8tof32(src[n]); dest[n] = u8tof32(src[n]);
} }
/* Other conversions */ /* Other conversions */
else if (old_fmt == PixelFormat::RGBA_F32 && fmt == PixelFormat::Y_F32)
else if (old_fmt == PixelFormat::RGB_F32 && fmt == PixelFormat::Y_F32)
{ {
vec4 *src = (vec4 *)m_data->m_pixels[(int)old_fmt]->Data();
vec3 *src = (vec3 *)m_data->m_pixels[(int)old_fmt]->Data();
float *dest = (float *)m_data->m_pixels[(int)fmt]->Data(); float *dest = (float *)m_data->m_pixels[(int)fmt]->Data();


vec3 const coeff(0.299f, 0.587f, 0.114f); vec3 const coeff(0.299f, 0.587f, 0.114f);


for (int n = 0; n < count; ++n) for (int n = 0; n < count; ++n)
dest[n] = dot(coeff, src[n].rgb);
dest[n] = dot(coeff, src[n]);
} }
else if (old_fmt == PixelFormat::Y_F32 && fmt == PixelFormat::Y_8) else if (old_fmt == PixelFormat::Y_F32 && fmt == PixelFormat::Y_8)
{ {
@@ -343,7 +343,8 @@ void Image::SetFormat(PixelFormat fmt)
} }
else else
{ {
ASSERT(false, "Unable to find proper conversion");
ASSERT(false, "Unable to find image conversion from %d to %d",
(int)old_fmt, (int)fmt);
} }
} }




+ 10
- 7
src/lol/image/pixel.h View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright: (c) 2004-2014 Sam Hocevar <sam@hocevar.net>
// Copyright: © 2004—2015 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To // modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See // Public License, Version 2, as published by Sam Hocevar. See
@@ -15,6 +15,9 @@
// ------------------------- // -------------------------
// //


#include <lol/base/types.h>
#include <lol/math/vector.h>

namespace lol namespace lol
{ {


@@ -52,17 +55,17 @@ static inline uint8_t BytesPerPixel(PixelFormat format)
case PixelFormat::Unknown: case PixelFormat::Unknown:
break; break;
case PixelFormat::Y_8: case PixelFormat::Y_8:
return 1;
return sizeof(PixelType<PixelFormat::Y_8>::type);
case PixelFormat::RGB_8: case PixelFormat::RGB_8:
return 3;
return sizeof(PixelType<PixelFormat::RGB_8>::type);
case PixelFormat::RGBA_8: case PixelFormat::RGBA_8:
return 4;
return sizeof(PixelType<PixelFormat::RGBA_8>::type);
case PixelFormat::Y_F32: case PixelFormat::Y_F32:
return 4;
return sizeof(PixelType<PixelFormat::Y_F32>::type);
case PixelFormat::RGB_F32: case PixelFormat::RGB_F32:
return 12;
return sizeof(PixelType<PixelFormat::RGB_F32>::type);
case PixelFormat::RGBA_F32: case PixelFormat::RGBA_F32:
return 16;
return sizeof(PixelType<PixelFormat::RGBA_F32>::type);
} }
return 0; return 0;
#if __GNUC__ #if __GNUC__


Loading…
Cancel
Save