http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* std::sort causes segfault when sorting class arrays - 6 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/67d1aa830ced63bb?hl=en
* Accessing & Updating an STL list - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/484fb30bdd8b6c0b?hl=en
* place stl container object on shared memory - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/5b1cd77c35d6247c?hl=en
* macro - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/84731ce3c14b7152?hl=en
* networking libraries - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/956adbc777247eed?hl=en
* set of values returned from a function - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/740e156a3ef7d0d0?hl=en
* Possibly my new personal homepage (some C++ stuff there!) - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/82f5a17a2a74a6bd?hl=en
* ===Welcome to comp.lang.c++! Read this first. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/571bdad8d41c0338?hl=en
* Copy Constructor And Temporary Objects - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/683b8aca2561a280?hl=en
* What does the function parameter "..." mean? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/8fa3e867025013f6?hl=en
==============================================================================
TOPIC: std::sort causes segfault when sorting class arrays
http://groups.google.com/group/comp.lang.c++/t/67d1aa830ced63bb?hl=en
==============================================================================
== 1 of 6 ==
Date: Sat, Feb 28 2009 2:07 pm
From: Philip Pemberton
Hi,
I'm trying to write some image processing software, and as part of that I
need to sort an array of pixel values by their luminance...
I'm using std::sort to do this, which works OK.. as long as no two pixels
in the array have the same luminance value. In that case.... it
segfaults. Here's my code:
////// CODE BEGINS
// gcc -o test test.cpp
#include <algorithm>
using namespace std;
class Pixel {
public:
double r, g, b;
Pixel(double _r=0, double _g=0, double _b=0) {
r = _r;
g = _g;
b = _b;
}
// Return the CIE luminance of this pixel
double get_luminance() const {
return (r * 255.0 * 0.212671) + (g * 255.0 *
0.715160) + (b * 255.0 * 0.072169);
}
bool operator<(const Pixel &rhs) const { return
(get_luminance() < rhs.get_luminance()); }
};
int main(int argc, char **argv)
{
for (int gx=0; gx<1000; gx++) {
Pixel pixels[15 * 15];
unsigned int pixel_count = 0;
for (int ym=0; ym<15; ym++) {
for (int xm=0; xm<15; xm++) {
#ifndef MAKE_PIXELS_THE_SAME
pixels[pixel_count].r = (xm*15)+ym;
pixels[pixel_count].g = (xm*15)+ym;
pixels[pixel_count].b = (xm*15)+ym;
#else
pixels[pixel_count].r = 0.12;
pixels[pixel_count].g = 0.93;
pixels[pixel_count].b = 0.32;
No comments:
Post a Comment