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

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

◆ buffer_vrmlwriteaction()

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

Definition at line 1401 of file VP1QtInventorUtils.cxx.

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

◆ buffer_writeaction()

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

Definition at line 1385 of file VP1QtInventorUtils.cxx.

1386{
1387 SoOutput out;
1388 buffer = (char *)malloc(1024);
1389 buffer_size = 1024;
1390 out.setBuffer(buffer, buffer_size, buffer_realloc);
1391
1392 SoWriteAction wa(&out);
1393 wa.apply(root);
1394
1395 QString s(buffer);
1396 free(buffer);
1397 return s;
1398}
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 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 598 of file VP1QtInventorUtils.cxx.

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

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

◆ ImageGetRow()

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

Definition at line 230 of file VP1QtInventorUtils.cxx.

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

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

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

◆ allowedLineWidthMax

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

Definition at line 359 of file VP1QtInventorUtils.cxx.

◆ allowedLineWidthMin

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

Definition at line 358 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeGranularity

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

Definition at line 363 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMax

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

Definition at line 362 of file VP1QtInventorUtils.cxx.

◆ allowedPointSizeMin

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

Definition at line 361 of file VP1QtInventorUtils.cxx.

◆ buffer

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

Definition at line 351 of file VP1QtInventorUtils.cxx.

◆ buffer_size

size_t VP1QtInventorUtils::Imp::buffer_size = 0
static

Definition at line 352 of file VP1QtInventorUtils.cxx.

◆ lineWidthAndPointSizeNeedsInit

bool VP1QtInventorUtils::Imp::lineWidthAndPointSizeNeedsInit = true
static

Definition at line 357 of file VP1QtInventorUtils.cxx.


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