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 59 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 1376 of file VP1QtInventorUtils.cxx.

1377{
1378 buffer = (char *)realloc(bufptr, size);
1379 buffer_size = size;
1380 return buffer;
1381}
size_t size() const
Number of registered mappings.

◆ buffer_vrmlwriteaction()

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

Definition at line 1400 of file VP1QtInventorUtils.cxx.

1401{
1402 SoToVRML2Action vwa;
1403
1404 vwa.apply(root);
1405 SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
1406
1407 SoOutput out;
1408 out.openFile(qPrintable(filename));
1409 out.setHeaderString("#VRML V2.0 utf8");
1410 SoWriteAction wra(&out);
1411 wra.apply(newroot);
1412 out.closeFile();
1413 newroot->unref();
1414 return;
1415}

◆ buffer_writeaction()

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

Definition at line 1384 of file VP1QtInventorUtils.cxx.

1385{
1386 SoOutput out;
1387 buffer = (char *)malloc(1024);
1388 buffer_size = 1024;
1389 out.setBuffer(buffer, buffer_size, buffer_realloc);
1390
1391 SoWriteAction wa(&out);
1392 wa.apply(root);
1393
1394 QString s(buffer);
1395 free(buffer);
1396 return s;
1397}
static void * buffer_realloc(void *bufptr, size_t size)
void free(pointer p)
Free an element.

◆ bwtorgba()

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

Definition at line 64 of file VP1QtInventorUtils.cxx.

65 {
66 while (n--) {
67 l[0] = *b;
68 l[1] = *b;
69 l[2] = *b;
70 l[3] = 0xff;
71 l += 4; ++b;
72 }
73 }
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 597 of file VP1QtInventorUtils.cxx.

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

◆ ConvertLong()

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

Definition at line 126 of file VP1QtInventorUtils.cxx.

127 {
128 while (length--) {
129 *array = std::byteswap (*array);
130 ++array;
131 }
132 }
double length(const pvec &v)

◆ ImageClose()

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

Definition at line 217 of file VP1QtInventorUtils.cxx.

218 {
219 fclose(image->file);
220 free(image->tmp);
221 free(image->tmpR);
222 free(image->tmpG);
223 free(image->tmpB);
224 free(image->rowSize);
225 free(image->rowStart);
226 free(image);
227 }
str image
Definition MyPlots.py:40

◆ ImageGetRow()

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

Definition at line 229 of file VP1QtInventorUtils.cxx.

231 {
232 unsigned char *iPtr, *oPtr, pixel;
233 int count;
234
235 if (image) {
236 if ((image->type & 0xFF00) == 0x0100) {
237
238 int okseek = fseek(image->file, (long)image->rowStart[y+z*image->ysize], SEEK_SET);
239 int okread = fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
240 image->file);
241
242 if (okseek != 0 || okread == 0) VP1Msg::messageDebug("fseek or fread failed!!");
243
244 iPtr = image->tmp;
245 oPtr = buf;
246 for (;;) {
247 pixel = *iPtr++;
248 count = (int)(pixel & 0x7F);
249 if (!count) {
250 return;
251 }
252 if (pixel & 0x80) {
253 while (count--) {
254 *oPtr++ = *iPtr++;
255 }
256 } else {
257 pixel = *iPtr++;
258 while (count--) {
259 *oPtr++ = pixel;
260 }
261 }
262 }
263 } else {
264 const unsigned int yDim(y*image->xsize), zDim(z*image->xsize*image->ysize);
265 int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
266 if (okstatus) { VP1Msg::messageDebug("fseek failed!!"); }
267
268 size_t bytesRead = 0;
269 bytesRead = fread(buf, 1, image->xsize, image->file);
270 VP1Msg::messageDebug("bytesRead(buf): " + QString::number(bytesRead));
271
272 }
273 }
274 else {
275 std::cout << "Warning! ImageGetRow() - no 'image'..." << std::endl;
276 }
277 }
#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:148

◆ ImageOpen()

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

Definition at line 134 of file VP1QtInventorUtils.cxx.

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

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

◆ read_texture()

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

Definition at line 279 of file VP1QtInventorUtils.cxx.

280 {
281 unsigned *base, *lptr;
282 unsigned char *rbuf, *gbuf, *bbuf, *abuf;
284 int y;
285
286 image = ImageOpen(name);
287
288 if(!image)
289 return nullptr;
290
291 (*width)=image->xsize;
292 (*height)=image->ysize;
293 (*components)=image->zsize;
294 const unsigned int imageWidth = image->xsize;
295 const unsigned int imageHeight = image->ysize;
296 const unsigned int uintSize(sizeof(unsigned)), ucharSize(sizeof(unsigned char));
297 const unsigned int colourBufSize=imageWidth*ucharSize;
298 base = reinterpret_cast<unsigned *>(malloc(imageWidth*imageHeight*uintSize));
299 rbuf = ucharAddress(malloc(colourBufSize));
300 gbuf = ucharAddress(malloc(colourBufSize));
301 bbuf = ucharAddress(malloc(colourBufSize));
302 abuf = ucharAddress(malloc(colourBufSize));
303 if(!base || !rbuf || !gbuf || !bbuf) {
304 ImageClose(image);
305 if (base) free(base);
306 if (rbuf) free(rbuf);
307 if (gbuf) free(gbuf);
308 if (bbuf) free(bbuf);
309 if (abuf) free(abuf);
310 return NULL;
311 }
312 lptr = base;
313 for (y=0; y<image->ysize; ++y) {
314 if (image->zsize>=4) {
315 //cid 13919 complaining that there was no input sanitising
316 //coverity[TAINTED_SCALAR]
317 ImageGetRow(image,rbuf,y,0);
318 ImageGetRow(image,gbuf,y,1);
319 ImageGetRow(image,bbuf,y,2);
320 ImageGetRow(image,abuf,y,3);
321 rgbatorgba(rbuf,gbuf,bbuf,abuf,ucharAddress(lptr),image->xsize);
322 lptr += image->xsize;
323 } else if(image->zsize==3) {
324 ImageGetRow(image,rbuf,y,0);
325 ImageGetRow(image,gbuf,y,1);
326 ImageGetRow(image,bbuf,y,2);
327 rgbtorgba(rbuf,gbuf,bbuf,ucharAddress(lptr),image->xsize);
328 lptr += image->xsize;
329 } else if(image->zsize==2) {
330 ImageGetRow(image,rbuf,y,0);
331 ImageGetRow(image,abuf,y,1);
332 latorgba(rbuf,abuf,ucharAddress(lptr),image->xsize);
333 lptr += image->xsize;
334 } else {
335 ImageGetRow(image,rbuf,y,0);
336 bwtorgba(rbuf,ucharAddress(lptr),image->xsize);
337 lptr += image->xsize;
338 }
339 }
340 ImageClose(image);
341 free(rbuf);
342 free(gbuf);
343 free(bbuf);
344 free(abuf);
345
346 return (unsigned *) base;
347 }
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:83

◆ 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 98 of file VP1QtInventorUtils.cxx.

100 {
101 while (n--) {
102 l[0] = r[0];
103 l[1] = g[0];
104 l[2] = b[0];
105 l[3] = a[0];
106 l += 4; ++r; ++g; ++b; ++a;
107 }
108 }
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 86 of file VP1QtInventorUtils.cxx.

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

Member Data Documentation

◆ allowedLineWidthGranularity

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

Definition at line 359 of file VP1QtInventorUtils.cxx.

◆ allowedLineWidthMax

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

Definition at line 358 of file VP1QtInventorUtils.cxx.

◆ allowedLineWidthMin

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

Definition at line 357 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeGranularity

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

Definition at line 362 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMax

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

Definition at line 361 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMin

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

Definition at line 360 of file VP1QtInventorUtils.cxx.

◆ buffer

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

Definition at line 350 of file VP1QtInventorUtils.cxx.

◆ buffer_size

size_t VP1QtInventorUtils::Imp::buffer_size = 0
static

Definition at line 351 of file VP1QtInventorUtils.cxx.

◆ lineWidthAndPointSizeNeedsInit

bool VP1QtInventorUtils::Imp::lineWidthAndPointSizeNeedsInit = true
static

Definition at line 356 of file VP1QtInventorUtils.cxx.


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