/** * Read in (from stdin) a maze, parse, and fill m */ void read(maze * m) { uint lineNumber = 0; char *line = 0; while ((line = readline(NULL)) != NULL) { m->list.append(line); // Don't leak memory after saving line. free(line); if (lineNumber == 1) m->width = (m->list[1].length() - BUFFER) / 3; // On the third line figuring out a row if (lineNumber++ % 2 != 0 || lineNumber <= 2) continue; short *lastRow = NULL; if (lineNumber > 3) lastRow = m->rows[lineNumber / 2 - 2]; short *col = convertRow(lastRow, m->list[lineNumber - 2], m->list[lineNumber - 1], m->width); if (m->rows.size() <= (int) (lineNumber / 2)) m->rows.resize(lineNumber * 4); m->rows.insert((lineNumber / 2) - 1, col); } m->rows.resize(lineNumber / 2); m->height = lineNumber / 2 - 1; }
void KImportDialog::applyConverter() { kdDebug(5300) << "KImportDialog::applyConverter" << endl; KProgressDialog pDialog(this, 0, i18n("Importing Progress"), i18n("Please wait while the data is imported."), true); pDialog.setAllowCancel(true); pDialog.showCancelButton(true); pDialog.setAutoClose(true); KProgress *progress = pDialog.progressBar(); progress->setTotalSteps(mTable->numRows() - 1); progress->setValue(0); readFile(0); pDialog.show(); for(uint i = mStartRow->value() - 1; i < mData.count() && !pDialog.wasCancelled(); ++i) { mCurrentRow = i; progress->setValue(i); if(i % 5 == 0) // try to avoid constantly processing events kapp->processEvents(); convertRow(); } }
void bumpmap (KisPixelSelectionSP device, const QRect &selectionRect, const bumpmap_vals_t &bmvals) { KIS_ASSERT_RECOVER_RETURN(bmvals.xofs == 0); KIS_ASSERT_RECOVER_RETURN(bmvals.yofs == 0); bumpmap_params_t params; bumpmap_init_params (¶ms, bmvals); const QRect dataRect = kisGrowRect(selectionRect, 1); const int dataRowSize = dataRect.width() * sizeof(quint8); const int selectionRowSize = selectionRect.width() * sizeof(quint8); QScopedArrayPointer<quint8> dstRow(new quint8[selectionRowSize]); QScopedArrayPointer<quint8> bmRow1(new quint8[dataRowSize]); QScopedArrayPointer<quint8> bmRow2(new quint8[dataRowSize]); QScopedArrayPointer<quint8> bmRow3(new quint8[dataRowSize]); device->readBytes(bmRow1.data(), dataRect.left(), dataRect.top(), dataRect.width(), 1); device->readBytes(bmRow2.data(), dataRect.left(), dataRect.top() + 1, dataRect.width(), 1); device->readBytes(bmRow3.data(), dataRect.left(), dataRect.top() + 2, dataRect.width(), 1); convertRow(bmRow1.data(), dataRect.width(), params.lut); convertRow(bmRow2.data(), dataRect.width(), params.lut); convertRow(bmRow3.data(), dataRect.width(), params.lut); for (int row = selectionRect.top(); row < selectionRect.top() + selectionRect.height(); row++) { bumpmap_row (bmvals, dstRow.data(), selectionRect.width(), bmRow1.data() + 1, bmRow2.data() + 1, bmRow3.data() + 1, ¶ms); device->writeBytes(dstRow.data(), selectionRect.left(), row, selectionRect.width(), 1); bmRow1.swap(bmRow2); bmRow2.swap(bmRow3); device->readBytes(bmRow3.data(), dataRect.left(), row + 1, dataRect.width(), 1); convertRow(bmRow3.data(), dataRect.width(), params.lut); } }
static void doPage(FILE * const ifP, struct cmdlineInfo const cmdline) { bit * bitrow; int rows, cols, format, row; unsigned int blankRows; bool rowIsBlank; pbm_readpbminit(ifP, &cols, &rows, &format); bitrow = pbm_allocrow(cols); allocateBuffers(cols); putinit(cmdline); blankRows = 0; prevRowBufferIndex = 0; memset(prevRowBuffer, 0, rowBufferSize); for (row = 0; row < rows; ++row) { pbm_readpbmrow(ifP, bitrow, cols, format); convertRow(bitrow, cols, cmdline.pack, cmdline.delta, &rowIsBlank); if (rowIsBlank) ++blankRows; else { printBlankRows(blankRows); blankRows = 0; printRow(); } } printBlankRows(blankRows); blankRows = 0; putrest(!cmdline.noreset); freeBuffers(); pbm_freerow(bitrow); }
static void copyRaster(struct pam * const inpamP, struct pam * const outpamP, tupletable const colormap, unsigned int const colormapSize, bool const floyd, bool const randomize, tuple const defaultColor, unsigned int * const missingCountP) { tuplehash const colorhash = pnm_createtuplehash(); tuple * inrow; tuple * outrow; struct pam workpam; /* This is for work space we use for building up the output pixels. To save time and memory, we modify them in place in a buffer, which ultimately holds the output pixels. This pam structure is thus the same as the *outpamP, but with a tuple allocation depth large enough to handle intermediate results. */ depthAdjustment depthAdjustment; struct colormapFinder * colorFinderP; bool usehash; struct fserr fserr; int row; workpam = *outpamP; workpam.allocation_depth = MAX(workpam.depth, inpamP->depth); workpam.size = sizeof(workpam); workpam.len = PAM_STRUCT_SIZE(allocation_depth); inrow = pnm_allocpamrow(inpamP); outrow = pnm_allocpamrow(&workpam); if (outpamP->maxval != inpamP->maxval && defaultColor) pm_error("The maxval of the colormap (%u) is not equal to the " "maxval of the input image (%u). This is allowable only " "if you are doing an approximate mapping (i.e. you don't " "specify -firstisdefault or -missingcolor)", (unsigned int)outpamP->maxval, (unsigned int)inpamP->maxval); selectDepthAdjustment(inpamP, outpamP->depth, &depthAdjustment); usehash = TRUE; createColormapFinder(outpamP, colormap, colormapSize, &colorFinderP); if (floyd) initFserr(inpamP, &fserr, randomize); *missingCountP = 0; /* initial value */ for (row = 0; row < inpamP->height; ++row) { unsigned int missingCount; pnm_readpamrow(inpamP, inrow); convertRow(inpamP, &workpam, inrow, depthAdjustment, colormap, colorFinderP, colorhash, &usehash, floyd, defaultColor, &fserr, outrow, &missingCount); *missingCountP += missingCount; pnm_writepamrow(outpamP, outrow); } destroyColormapFinder(colorFinderP); pnm_freepamrow(inrow); pnm_freepamrow(outrow); pnm_destroytuplehash(colorhash); }