ATLAS Offline Software
Loading...
Searching...
No Matches
VP1QtInventorUtils::Imp Class Reference
Collaboration diagram for VP1QtInventorUtils::Imp:

Classes

struct  _ImageRec

Public Types

typedef struct VP1QtInventorUtils::Imp::_ImageRec ImageRec

Static Public Member Functions

static QImage constructImageWithTransparentBackground (const QImage &im_black_bgd, const QImage &image_white_bgd)
static void bwtorgba (unsigned char *b, unsigned char *l, int n)
static void latorgba (unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void rgbtorgba (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *l, int n)
static void rgbatorgba (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void ConvertLong (unsigned *array, long length)
static ImageRecImageOpen (const char *fileName)
static void ImageClose (ImageRec *image)
static void ImageGetRow (ImageRec *image, unsigned char *buf, int y, int z)
static unsigned * read_texture (const char *name, int *width, int *height, int *components)
static void * buffer_realloc (void *bufptr, size_t size)
static QString buffer_writeaction (SoNode *root)
static void buffer_vrmlwriteaction (SoNode *root, const QString &filename)

Static Public Attributes

static char * buffer = 0
static size_t buffer_size = 0
static bool lineWidthAndPointSizeNeedsInit = true
static double allowedLineWidthMin = -1.0
static double allowedLineWidthMax = -1.0
static double allowedLineWidthGranularity = -1.0
static double allowedPointSizeMin = -1.0
static double allowedPointSizeMax = -1.0
static double allowedPointSizeGranularity = -1.0

Detailed Description

Definition at line 60 of file VP1QtInventorUtils.cxx.

Member Typedef Documentation

◆ ImageRec

Member Function Documentation

◆ buffer_realloc()

void * VP1QtInventorUtils::Imp::buffer_realloc ( void * bufptr,
size_t size )
static

Definition at line 1384 of file VP1QtInventorUtils.cxx.

1385{
1386 buffer = (char *)realloc(bufptr, size);
1387 buffer_size = size;
1388 return buffer;
1389}

◆ buffer_vrmlwriteaction()

void VP1QtInventorUtils::Imp::buffer_vrmlwriteaction ( SoNode * root,
const QString & filename )
static

Definition at line 1408 of file VP1QtInventorUtils.cxx.

1409{
1410 SoToVRML2Action vwa;
1411
1412 vwa.apply(root);
1413 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1414
1415 SoOutput out;
1416 out.openFile(qPrintable(filename));
1417 out.setHeaderString("#VRML V2.0 utf8");
1418 SoWriteAction wra(&out);
1419 wra.apply(newroot);
1420 out.closeFile();
1421 newroot->unref();
1422 return;
1423}

◆ buffer_writeaction()

QString VP1QtInventorUtils::Imp::buffer_writeaction ( SoNode * root)
static

Definition at line 1392 of file VP1QtInventorUtils.cxx.

1393{
1394 SoOutput out;
1395 buffer = (char *)malloc(1024);
1396 buffer_size = 1024;
1397 out.setBuffer(buffer, buffer_size, buffer_realloc);
1398
1399 SoWriteAction wa(&out);
1400 wa.apply(root);
1401
1402 QString s(buffer);
1403 free(buffer);
1404 return s;
1405}
static void * buffer_realloc(void *bufptr, size_t size)

◆ bwtorgba()

void VP1QtInventorUtils::Imp::bwtorgba ( unsigned char * b,
unsigned char * l,
int n )
inlinestatic

Definition at line 65 of file VP1QtInventorUtils.cxx.

66 {
67 while (n--) {
68 l[0] = *b;
69 l[1] = *b;
70 l[2] = *b;
71 l[3] = 0xff;
72 l += 4; ++b;
73 }
74 }
l
Printing final latex table to .tex output file.

◆ constructImageWithTransparentBackground()

QImage VP1QtInventorUtils::Imp::constructImageWithTransparentBackground ( const QImage & im_black_bgd,
const QImage & image_white_bgd )
static

Definition at line 605 of file VP1QtInventorUtils.cxx.

606{
607 if (im_black_bgd.isNull()||im_white_bgd.isNull()||im_black_bgd.size()!=im_white_bgd.size())
608 return QImage();
609
610 QImage im(im_black_bgd.size(),QImage::Format_ARGB32);
611
612 int width = im.width();
613 int height = im.height();
614 QRgb white = qRgba(255,255,255,255);
615 QRgb black = qRgba(0,0,0,255);
616
617 for (int x = 0; x < width; ++x)
618 for (int y = 0; y < height; ++y) {
619 if (im_black_bgd.pixel(x,y)==im_white_bgd.pixel(x,y)) {
620 im.setPixel(x,y,im_white_bgd.pixel(x,y));
621 } else if (im_black_bgd.pixel(x,y)==black&&im_white_bgd.pixel(x,y)==white) {
622 im.setPixel(x,y,Qt::transparent);
623 } else {
624 //Calculate ...
625 QColor pix_b = QColor(im_black_bgd.pixel(x,y));
626 QColor pix_w = QColor(im_white_bgd.pixel(x,y));
627 qreal alpha = 1.0 - pix_w.redF() + pix_b.redF();
628 if (alpha==0) {
629 im.setPixel(x,y,Qt::transparent);
630 } else {
631 im.setPixel(x,y,qRgba(static_cast<int>(pix_b.redF()/alpha*255+0.5),
632 static_cast<int>(pix_b.greenF()/alpha*255+0.5),
633 static_cast<int>(pix_b.blueF()/alpha*255+0.5),
634 static_cast<int>(alpha*255+0.5)));
635 }
636 }
637 }
638
639 return im;
640}
const double width
#define y
#define x

◆ ConvertLong()

void VP1QtInventorUtils::Imp::ConvertLong ( unsigned * array,
long length )
inlinestatic

Definition at line 127 of file VP1QtInventorUtils.cxx.

128 {
129 while (length--) {
130 *array = CxxUtils::byteswap (*array);
131 ++array;
132 }
133 }
double length(const pvec &v)
constexpr T byteswap(T value) noexcept
Reverse the bytes in n.
Definition byteswap.h:42

◆ ImageClose()

void VP1QtInventorUtils::Imp::ImageClose ( ImageRec * image)
inlinestatic

Definition at line 225 of file VP1QtInventorUtils.cxx.

226 {
227 fclose(image->file);
228 free(image->tmp);
229 free(image->tmpR);
230 free(image->tmpG);
231 free(image->tmpB);
232 free(image->rowSize);
233 free(image->rowStart);
234 free(image);
235 }
str image
Definition MyPlots.py:40

◆ ImageGetRow()

void VP1QtInventorUtils::Imp::ImageGetRow ( ImageRec * image,
unsigned char * buf,
int y,
int z )
inlinestatic

Definition at line 237 of file VP1QtInventorUtils.cxx.

239 {
240 unsigned char *iPtr, *oPtr, pixel;
241 int count;
242
243 if (image) {
244 if ((image->type & 0xFF00) == 0x0100) {
245
246 int okseek = fseek(image->file, (long)image->rowStart[y+z*image->ysize], SEEK_SET);
247 int okread = fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
248 image->file);
249
250 if( !okseek || !okread ) VP1Msg::messageDebug("fseek or fread failed!!");
251
252 iPtr = image->tmp;
253 oPtr = buf;
254 for (;;) {
255 pixel = *iPtr++;
256 count = (int)(pixel & 0x7F);
257 if (!count) {
258 return;
259 }
260 if (pixel & 0x80) {
261 while (count--) {
262 *oPtr++ = *iPtr++;
263 }
264 } else {
265 pixel = *iPtr++;
266 while (count--) {
267 *oPtr++ = pixel;
268 }
269 }
270 }
271 } else {
272 const unsigned int yDim(y*image->xsize), zDim(z*image->xsize*image->ysize);
273 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
274 if (okstatus) { VP1Msg::messageDebug("fseek failed!!"); }
275
276 size_t bytesRead = 0;
277 bytesRead = fread(buf, 1, image->xsize, image->file);
278 VP1Msg::messageDebug("bytesRead(buf): " + QString::number(bytesRead));
279
280 }
281 }
282 else {
283 std::cout << "Warning! ImageGetRow() - no 'image'..." << std::endl;
284 }
285 }
#define z
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

◆ ImageOpen()

ImageRec * VP1QtInventorUtils::Imp::ImageOpen ( const char * fileName)
inlinestatic

Definition at line 135 of file VP1QtInventorUtils.cxx.

136 {
137 union {
138 int testWord;
139 char testByte[4];
140 } endianTest;
142 int swapFlag;
143
144 endianTest.testWord = 1;
145 if (endianTest.testByte[0] == 1) {
146 swapFlag = 1;
147 } else {
148 swapFlag = 0;
149 }
150
151 image = (ImageRec *)malloc(sizeof(ImageRec));
152 if (image == NULL) {
153 fprintf(stderr, "Out of memory!\n");
154 exit(1);
155 }
156 if ((image->file = fopen(fileName, "rb")) == NULL) {
157 perror(fileName);
158 exit(1);
159 }
160
161 int bytesRead = fread(image, 1, 12, image->file);
162
163 if (!bytesRead) {
164 fprintf(stderr, "fread failed!\n");
165 }
166 //what are reasonable limits on x,y,zsize?
167
168
169
170
171 if (swapFlag) {
172 image->imagic = CxxUtils::byteswap (image->imagic);
173 image->type = CxxUtils::byteswap (image->type);
174 image->dim = CxxUtils::byteswap (image->dim);
175 image->xsize = CxxUtils::byteswap (image->zsize);
176 image->ysize = CxxUtils::byteswap (image->ysize);
177 image->zsize = CxxUtils::byteswap (image->zsize);
178 }
179
180
181 const unsigned int colourBuffSize=image->xsize*256u;
182 image->tmp = ucharAddress(malloc(colourBuffSize));
183 image->tmpR = ucharAddress(malloc(colourBuffSize));
184 image->tmpG = ucharAddress(malloc(colourBuffSize));
185 image->tmpB = ucharAddress(malloc(colourBuffSize));
186 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
187 image->tmpB == NULL) {
188 fprintf(stderr, "Out of memory!\n");
189 exit(1);
190 }
191
192 //should test upper limits on x here...but what is sensible? 1Mb? 100Mb?
193 if ((image->type & 0xFF00) == 0x0100) {
194 size_t x = ((size_t)image->ysize * (size_t)image->zsize) * sizeof(unsigned);
195 //cid 13609 complaining there is no input sanitising
196 //coverity[TAINTED_SCALAR]
197 image->rowStart = (unsigned *)malloc(x);
198 image->rowSize = (int *)malloc(x);
199 if (image->rowStart == NULL || image->rowSize == NULL) {
200 fprintf(stderr, "Out of memory!\n");
201 exit(1);
202 }
203 image->rleEnd = 512 + (2 * x);
204 const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
205 if (fseekRetVal !=0){
206 fprintf(stderr, "Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
207 }
208 size_t bytesRead = 0;
209 bytesRead = fread(image->rowStart, 1, x, image->file);
210 VP1Msg::messageDebug("bytesRead(rowStart): " + QString::number(bytesRead));
211 bytesRead = fread(image->rowSize, 1, x, image->file);
212 VP1Msg::messageDebug("bytesRead(rowSize): " + QString::number(bytesRead));
213
214 if (swapFlag) {
215 ConvertLong(image->rowStart, x/(int)sizeof(unsigned));
216 ConvertLong((unsigned *)image->rowSize, x/(int)sizeof(int));
217 }
218 } else {
219 image->rowStart = NULL;
220 image->rowSize = NULL;
221 }
222 return image;
223 }
struct VP1QtInventorUtils::Imp::_ImageRec ImageRec
static void ConvertLong(unsigned *array, long length)

◆ latorgba()

void VP1QtInventorUtils::Imp::latorgba ( unsigned char * b,
unsigned char * a,
unsigned char * l,
int n )
inlinestatic

Definition at line 76 of file VP1QtInventorUtils.cxx.

77 {
78 while (n--) {
79 l[0] = *b;
80 l[1] = *b;
81 l[2] = *b;
82 l[3] = *a;
83 l += 4; ++b; ++a;
84 }
85 }
static Double_t a

◆ read_texture()

unsigned * VP1QtInventorUtils::Imp::read_texture ( const char * name,
int * width,
int * height,
int * components )
inlinestatic

Definition at line 287 of file VP1QtInventorUtils.cxx.

288 {
289 unsigned *base, *lptr;
290 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
292 int y;
293
294 image = ImageOpen(name);
295
296 if(!image)
297 return NULL;
298
299 (*width)=image->xsize;
300 (*height)=image->ysize;
301 (*components)=image->zsize;
302 const unsigned int imageWidth = image->xsize;
303 const unsigned int imageHeight = image->ysize;
304 const unsigned int uintSize(sizeof(unsigned)), ucharSize(sizeof(unsigned char));
305 const unsigned int colourBufSize=imageWidth*ucharSize;
306 base = reinterpret_cast<unsigned *>(malloc(imageWidth*imageHeight*uintSize));
307 rbuf = ucharAddress(malloc(colourBufSize));
308 gbuf = ucharAddress(malloc(colourBufSize));
309 bbuf = ucharAddress(malloc(colourBufSize));
310 abuf = ucharAddress(malloc(colourBufSize));
311 if(!base || !rbuf || !gbuf || !bbuf) {
312 ImageClose(image);
313 if (base) free(base);
314 if (rbuf) free(rbuf);
315 if (gbuf) free(gbuf);
316 if (bbuf) free(bbuf);
317 if (abuf) free(abuf);
318 return NULL;
319 }
320 lptr = base;
321 for (y=0; y<image->ysize; ++y) {
322 if (image->zsize>=4) {
323 //cid 13919 complaining that there was no input sanitising
324 //coverity[TAINTED_SCALAR]
325 ImageGetRow(image,rbuf,y,0);
326 ImageGetRow(image,gbuf,y,1);
327 ImageGetRow(image,bbuf,y,2);
328 ImageGetRow(image,abuf,y,3);
329 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
330 lptr += image->xsize;
331 } else if(image->zsize==3) {
332 ImageGetRow(image,rbuf,y,0);
333 ImageGetRow(image,gbuf,y,1);
334 ImageGetRow(image,bbuf,y,2);
335 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
336 lptr += image->xsize;
337 } else if(image->zsize==2) {
338 ImageGetRow(image,rbuf,y,0);
339 ImageGetRow(image,abuf,y,1);
340 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
341 lptr += image->xsize;
342 } else {
343 ImageGetRow(image,rbuf,y,0);
344 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
345 lptr += image->xsize;
346 }
347 }
348 ImageClose(image);
349 free(rbuf);
350 free(gbuf);
351 free(bbuf);
352 free(abuf);
353
354 return (unsigned *) base;
355 }
static void rgbatorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void ImageGetRow(ImageRec *image, unsigned char *buf, int y, int z)
static void latorgba(unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void rgbtorgba(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *l, int n)
static void ImageClose(ImageRec *image)
static void bwtorgba(unsigned char *b, unsigned char *l, int n)
static ImageRec * ImageOpen(const char *fileName)
std::string base
Definition hcg.cxx:81

◆ rgbatorgba()

void VP1QtInventorUtils::Imp::rgbatorgba ( unsigned char * r,
unsigned char * g,
unsigned char * b,
unsigned char * a,
unsigned char * l,
int n )
inlinestatic

Definition at line 99 of file VP1QtInventorUtils.cxx.

101 {
102 while (n--) {
103 l[0] = r[0];
104 l[1] = g[0];
105 l[2] = b[0];
106 l[3] = a[0];
107 l += 4; ++r; ++g; ++b; ++a;
108 }
109 }
int r
Definition globals.cxx:22

◆ rgbtorgba()

void VP1QtInventorUtils::Imp::rgbtorgba ( unsigned char * r,
unsigned char * g,
unsigned char * b,
unsigned char * l,
int n )
inlinestatic

Definition at line 87 of file VP1QtInventorUtils.cxx.

89 {
90 while (n--) {
91 l[0] = r[0];
92 l[1] = g[0];
93 l[2] = b[0];
94 l[3] = 0xff;
95 l += 4; ++r; ++g; ++b;
96 }
97 }

Member Data Documentation

◆ allowedLineWidthGranularity

double VP1QtInventorUtils::Imp::allowedLineWidthGranularity = -1.0
static

Definition at line 367 of file VP1QtInventorUtils.cxx.

◆ allowedLineWidthMax

double VP1QtInventorUtils::Imp::allowedLineWidthMax = -1.0
static

Definition at line 366 of file VP1QtInventorUtils.cxx.

◆ allowedLineWidthMin

double VP1QtInventorUtils::Imp::allowedLineWidthMin = -1.0
static

Definition at line 365 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeGranularity

double VP1QtInventorUtils::Imp::allowedPointSizeGranularity = -1.0
static

Definition at line 370 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMax

double VP1QtInventorUtils::Imp::allowedPointSizeMax = -1.0
static

Definition at line 369 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMin

double VP1QtInventorUtils::Imp::allowedPointSizeMin = -1.0
static

Definition at line 368 of file VP1QtInventorUtils.cxx.

◆ buffer

char * VP1QtInventorUtils::Imp::buffer = 0
static

Definition at line 358 of file VP1QtInventorUtils.cxx.

◆ buffer_size

size_t VP1QtInventorUtils::Imp::buffer_size = 0
static

Definition at line 359 of file VP1QtInventorUtils.cxx.

◆ lineWidthAndPointSizeNeedsInit

bool VP1QtInventorUtils::Imp::lineWidthAndPointSizeNeedsInit = true
static

Definition at line 364 of file VP1QtInventorUtils.cxx.


The documentation for this class was generated from the following file: