// draw or remove a kite // do it with 2 loops void drawKite(int x, int y, int length, char borderColor, char fillColor){ int i, j, tempy; char bg = d.backgroundColor; int len = 0, indc = 1, rangeStart, rangeEnd; if(borderColor != bg) logFig[figCount].isPresent = 1; else logFig[figCount].isPresent = 0; tempy = y-length; rangeStart = rangeEnd = x; do{ for(i=rangeStart; i<=rangeEnd; i++){ if(!checkRange(i,tempy)) continue; if(i==rangeStart && i==rangeEnd) setPixels(i, tempy, (borderColor!=bg)?'x':bg); else if((i==rangeStart && indc==1) || (i==rangeEnd && indc==-1)) setPixels(i,tempy, (borderColor!=bg)?'/':bg); else if((i==rangeEnd && indc==1) || (i==rangeStart && indc==-1)) setPixels(i, tempy, (borderColor!=bg)?'\\':bg); else setPixels(i,tempy,fillColor); } if(rangeEnd-rangeStart >= 2*length) indc *= -1; tempy ++; rangeStart -= indc; rangeEnd += indc; }while(rangeStart != rangeEnd); if(checkRange(i,tempy)) setPixels(rangeStart, tempy, (borderColor!=bg)?'x':bg); if(borderColor != bg) addlogFig(KITE, x, y, 0, 0, length, borderColor, fillColor); }
UserInterface::UserInterface(MADSEngine *vm) : _vm(vm), _dirtyAreas(vm), _uiSlots(vm) { _invSpritesIndex = -1; _invFrameNumber = 1; _scrollMilli = 0; _scrollFlag = false; _category = CAT_NONE; _inventoryTopIndex = 0; _selectedInvIndex = -1; _selectedActionIndex = 0; _selectedItemVocabIdx = -1; _scrollbarActive = SCROLLBAR_NONE; _scrollbarOldActive = SCROLLBAR_NONE; _scrollbarStrokeType = SCROLLBAR_NONE; _scrollbarQuickly = false; _scrollbarMilliTime = 0; _scrollbarElevator = _scrollbarOldElevator = 0; _highlightedCommandIndex = -1; _highlightedInvIndex = -1; _highlightedItemVocabIndex = -1; _dirtyAreas.resize(50); _inventoryChanged = false; _noSegmentsActive = 0; _someSegmentsActive = 0; _rectP = nullptr; Common::fill(&_categoryIndexes[0], &_categoryIndexes[7], 0); // Map the user interface to the bottom of the game's screen surface byte *pData = _vm->_screen.getBasePtr(0, MADS_SCENE_HEIGHT); setPixels(pData, MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT); _surface.setSize(MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT); }
// センサの値に変更があったらピクセルの更新を行う void testApp::handleSequence(){ if (!(arduino.GetBallRadius() > prevRadius - 10 && arduino.GetBallRadius() < prevRadius + 10)) { offset = arduino.GetBallRadius()/50; setPixels(); prevRadius = arduino.GetBallRadius(); } }
void RFD_WS2812::initialize() { pinMode(pin, OUTPUT); digitalWrite(pin, LOW); setPixels(0,0,0); render(); }
void testApp::setup(){ // 画面の基本設定 ofBackground(0,0,0); ofEnableSmoothing(); // 画面の混色の設定を加算合成にする ofEnableBlendMode(OF_BLENDMODE_ADD); // 画像データの読込み myImage.loadImage("ryota_10.jpg"); // 画像の描画位置を設定 imgWidth = myImage.width; imgHeight = myImage.height; // 画像データのビットマップ情報を配列に格納 pixels = myImage.getPixels(); // 初回のピクセルサイズ prevRadius = arduino.GetBallRadius(); // ピクセル配列の初期化 setPixels(); }
// deleteData() - void Image::deleteData() { setPixels(nullptr); width = 0; height = 0; numComponents = 0; }
bool rxImage::load(const std::string& filename) { // std::string filepath = File::toDataPath(filename); WebP wp; if(!wp.load(filename)) { return false; } setPixels(wp.getPixels(), wp.getWidth(), wp.getHeight(), GL_RGBA); return true; }
void Image::copyData(const Image& org, const bool) { BaseClass::copyData(org); width = org.width; height = org.height; numComponents = org.numComponents; format = org.format; setPixels(org.pixels); xPixPerMeter = org.xPixPerMeter; yPixPerMeter = org.yPixPerMeter; }
/** * This method copies the pixels values from the input image to the current image. * None of the parameters of the input image are edited. * All the parameters in the two images have to be the same. If not, the copy operation * is interrupted and nothing is done. * * \param img DiVAImage * \return Verification code */ int DiVAImage::copy(DiVAImage *img){ if(this->getWidth() != img->getWidth() || this->getHeight() != img->getHeight() || this->getDepth() != img->getDepth()|| this->getNChannels() != img->getNChannels() ) return -1; setPixels(img->getPixels()); setId(img->getId()); setTimeStamp(img->getTimeStamp()); setVAlign(img->getVAlign()); return 1; }
void testApp::keyPressed(int key){ //「x」キーを押すと、画面をキャプチャーする if(key == 'x'){ // 位置とサイズを指定して、画面をキャプチャー grabbedImage.grabScreen(drawX, drawY, imgWidth, imgHeight); // キャプチャーした画像データを「grabbedImage.png」で保存 grabbedImage.saveImage("grabbedImage.png"); } // スペースキーでピクセルのサイズを変更 if (key == ' ') { offset = ofRandom(1, maxCount); setPixels(); } }
bool GifDecoder::readBitmap(DataBlock* dataBlock) { uint8_t packed; if (!dataBlock->read(&ix) || !dataBlock->read(&iy) || // (sub)image position & size !dataBlock->read(&iw) || !dataBlock->read(&ih) || !dataBlock->read(&packed, 1)) { return false; } bool lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace int32_t lctSize = 2 << (packed & 0x07); // 3 - sort flag // 4-5 - reserved lctSize = 2 << (packed & 7); // 6-8 - local color // table size interlace = (packed & 0x40) != 0; uint32_t lct[256]; uint32_t* act; if (lctFlag) { if (!readColorTable(dataBlock, lct, lctSize)) { // read table return false; } act = lct; // make local table active } else { act = gct; // make global table active if (bgIndex == transIndex) { bgColor = 0; } } uint32_t save; if (transparency) { save = act[transIndex]; act[transIndex] = 0; // set transparent color if specified } if (!decodeBitmapData(dataBlock) || !skip(dataBlock)) { // decode pixel data return false; } frameCount++; // create new image to receive frame data setPixels(act); // transfer pixel data to image if (transparency) { act[transIndex] = save; } resetFrame(); return true; }
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { OID ID; /* OMEIS data structures */ omeis* is; pixHeader* head; /* MATLAB data structueres */ mxArray *m_url, *m_sessionkey; mxArray *permute_inputs[2]; mxArray *copy_input_array; /* we need a local copy so we can transpose it */ char* url, *sessionkey; if (nrhs != 3) mexErrMsgTxt("\n [pix] = setPixels (is, ID, pixels)"); if (!mxIsStruct(prhs[0])) mexErrMsgTxt("setPixels requires the first input to be the struct outputed" " from openConnectionOMEIS\n"); if (!(m_url = mxGetField(prhs[0], 0, "url"))) mexErrMsgTxt("setPixels requires the first input, OMEIS struct, to have field: url"); if (!(m_sessionkey = mxGetField(prhs[0], 0, "sessionkey"))) mexErrMsgTxt("setPixels requires the first input, OMEIS struct, to have field: sessionkey"); if (!mxIsChar(m_url) || !mxIsChar(m_sessionkey)) mexErrMsgTxt("OMEIS field aren't character array.\n"); if (!mxIsNumeric(prhs[1])) mexErrMsgTxt("setPixels requires the second input to be the PixelsID\n") ; ID = (OID) mxGetScalar(prhs[1]) ; url = mxArrayToString(m_url); sessionkey = mxArrayToString(m_sessionkey); is = openConnectionOMEIS (url, sessionkey); if (!(head = pixelsInfo (is, ID))){ char err_str[128]; sprintf(err_str, "PixelsID %llu or OMEIS URL '%s' is probably wrong\n", ID, is->url); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(is); mexErrMsgTxt(err_str); } /* In OMEIS Size_X corresponds to columns and Size_Y corresponds to rows. This is diametrically opposite to MATLAB's assumptions. hence we do "$matlab_var_name = permute($matlab_var_name, [2 1 3 4 5]);" the hard way (groan) */ permute_inputs[0] = prhs[2]; /* permute_input isn't being modified so discarding the const qualifier is okay */ permute_inputs[1] = mxCreateDoubleMatrix(1, 5, mxREAL); mxGetPr(permute_inputs[1])[0] = 2; mxGetPr(permute_inputs[1])[1] = 1; mxGetPr(permute_inputs[1])[2] = 3; mxGetPr(permute_inputs[1])[3] = 4; mxGetPr(permute_inputs[1])[4] = 5; /* mexCallMATLAB allocates memory for copy_input_array */ if (mexCallMATLAB(1, ©_input_array, 2, permute_inputs, "permute")) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); char err_str[128]; sprintf(err_str, "Couldn't permute the pixels to get them in MATLAB orientation"); mexErrMsgTxt(err_str); } /* check dimension and class check */ const mwSize* dims = mxGetDimensions (copy_input_array); switch (mxGetNumberOfDimensions (copy_input_array)) { char err_str[128]; case 5: if (head->dt != dims[4]) { sprintf (err_str, "5th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[4], head->dt); mexErrMsgTxt(err_str); } case 4: if (head->dc != dims[3]) { sprintf (err_str, "4th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[3], head->dc); mexErrMsgTxt(err_str); } case 3: if (head->dz != dims[2]){ sprintf (err_str, "3th Dimension (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[2], head->dz); mexErrMsgTxt(err_str); } case 2: if (head->dy != dims[1]){ sprintf (err_str, "Height (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[1], head->dy); mexErrMsgTxt(err_str); } case 1: if (head->dx != dims[0]){ sprintf (err_str, "Width (%d) of input array doesn't match OMEIS Pixels (%d).\n", dims[0], head->dx); mexErrMsgTxt(err_str); } break; default: /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); mexErrMsgTxt("Input Array must be 5D or less"); break; } pixHeader tmp_head; CtoOMEISDatatype ((char*) mxGetClassName(copy_input_array), &tmp_head); if ( !samePixelType(&tmp_head, head)) { /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); mexErrMsgTxt("Types of input array and Pixels don't match\n"); } /* set the pixels */ int pix = setPixels (is, ID, mxGetPr(copy_input_array)); /* record number of pixels written */ plhs[0] = mxCreateScalarDouble((double) pix); /* clean up */ mxFree(url); mxFree(sessionkey); mxFree(head); mxFree(is); mxDestroyArray(copy_input_array); }
//------------------------------------------------------------------------------ // Read a bitmap (BMP) format file //------------------------------------------------------------------------------ bool Image::readFileBMP(const char* const filename, const char* const path) { static const unsigned int BITMAPFILE_SIZE = (MAX_PATH_LEN + MAX_FILENAME_LEN); char bitmapFile[BITMAPFILE_SIZE]; bitmapFile[0] = '\0'; // append path name const char* p1 = path; if (p1 != nullptr && std::strlen(p1) > 0) { base::utStrcat(bitmapFile, sizeof(bitmapFile), p1); base::utStrcat(bitmapFile, sizeof(bitmapFile), "/"); } // append file name const char* p2 = filename; if (p2 != nullptr && std::strlen(p2) > 0) { base::utStrcat(bitmapFile, sizeof(bitmapFile), p2); } // Do we have a full path name? if (std::strlen(bitmapFile) <= 1) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Image::readFileBMP(): invalid file name: " << bitmapFile << std::endl; } return false; } if (isMessageEnabled(MSG_INFO)) { std::cout << "Image: Loading file: " << filename << std::endl; } FILE* fp = std::fopen(bitmapFile,"rb"); if (fp == nullptr) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Image::readFileBMP: unable to open bitmap file: " << bitmapFile << std::endl; } return false; } // Big or little ending? Swap if we're a big endian arch bool swap = checkSwap(); // Read the bitmap file header (BITMAPFILEHEADER) char bfType[2]; uint32_t bfSize(0); uint16_t bfReserved1(0); uint16_t bfReserved2(0); uint32_t bfOffBits(0); //unsigned int bitmapFileHdrSize = // sizeof(bfType) + sizeof(bfSize) + sizeof(bfReserved1) + sizeof(bfReserved2) + sizeof(bfOffBits); size_t nItemsRead(0); nItemsRead = std::fread(&bfType, sizeof(char), 2, fp); nItemsRead = std::fread(&bfSize, sizeof(bfSize), 1, fp); if (swap) bfSize = convertUInt32(bfSize); nItemsRead = std::fread(&bfReserved1, sizeof(bfReserved1), 1, fp); if (swap) bfReserved1 = convertUInt16(bfReserved1); nItemsRead = std::fread(&bfReserved2, sizeof(bfReserved2), 1, fp); if (swap) bfReserved2 = convertUInt16(bfReserved2); nItemsRead = std::fread(&bfOffBits, sizeof(bfOffBits), 1, fp); if (swap) bfOffBits = convertUInt32(bfOffBits); if (bfType[0] != 'B' || bfType[1] != 'M') { // Not a bitmap file if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Image::readFileBMP(1): invalid bitmap file: " << bitmapFile << std::endl; } std::fclose(fp); return false; } // Read the bitmap file info BITMAPINFOHEADER_X bmfi; nItemsRead = std::fread(&bmfi, sizeof(BITMAPINFOHEADER_X), 1, fp); if (swap) { bmfi.biSize = convertUInt32(bmfi.biSize); bmfi.biWidth = convertInt32(bmfi.biWidth); bmfi.biHeight = convertInt32(bmfi.biHeight); bmfi.biPlanes = convertUInt16(bmfi.biPlanes); bmfi.biBitCount = convertUInt16(bmfi.biBitCount); bmfi.biCompression = convertUInt32(bmfi.biCompression); bmfi.biSizeImage = convertUInt32(bmfi.biSizeImage); bmfi.biXPelsPerMeter = convertInt32(bmfi.biXPelsPerMeter); bmfi.biYPelsPerMeter = convertInt32(bmfi.biYPelsPerMeter); bmfi.biClrUsed = convertUInt32(bmfi.biClrUsed); bmfi.biClrImportant = convertUInt32(bmfi.biClrImportant); } if (bmfi.biSize != sizeof(BITMAPINFOHEADER_X) || bmfi.biPlanes != 1) { // Not a bitmap file if (isMessageEnabled(MSG_ERROR)) { std::cerr << "Image::readFileBMP(2): invalid bitmap file: " << bitmapFile << std::endl; } std::fclose(fp); return false; } // set width & height (truncates to powers of two) setWidth(bmfi.biWidth); setHeight(bmfi.biHeight); // set resolution setXResolutionPPM(bmfi.biXPelsPerMeter); setYResolutionPPM(bmfi.biYPelsPerMeter); // Read the colors GLubyte* bmap = nullptr; if (bmfi.biBitCount == 24) { setNumComponents(3); setFormat(GL_BGR_EXT); bmap = readRgbValuesBMP(fp, bfOffBits, &bmfi); } else if (bmfi.biBitCount == 8){ setNumComponents(3); setFormat(GL_BGR_EXT); bmap = readColorValuesBMP(fp, bfOffBits, &bmfi); } else if (bmfi.biBitCount == 4){ if (isMessageEnabled(MSG_WARNING)) { std::cerr << "Image::readFileBMP: can not load a 16 color bitmap!" << std::endl; } } if (bmap == nullptr) { if (isMessageEnabled(MSG_WARNING)) { std::cerr << "Image::readFileBMP(3): invalid bitmap file: " << bitmapFile << std::endl; } } // close the file std::fclose(fp); // Set the pixel bit map if (bmap != nullptr) setPixels(bmap); return (bmap != nullptr); }
void Texture::setPixels(const Image& img, const Vec2u& pos /*= Vec2u() */) { setPixels(img.getPixels(), img.getSize(), pos); }
int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); int rank = 0; int size = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); SDLImage *image = nullptr; Pixel *pixels = nullptr; int pixelsNum = 0; int pixelsRows = 0; int pixelsCols = 0; if (rank == ROOT) { image = new SDLImage(IMAGE_PATH); pixelsRows = image->getHeight(); pixelsCols = image->getWidth(); pixelsNum = pixelsRows * pixelsCols; pixels = new Pixel[pixelsNum](); getPixels(image, pixels); } MPI_Bcast(&pixelsNum, 1, MPI_INT, ROOT, MPI_COMM_WORLD); MPI_Bcast(&pixelsRows, 1, MPI_INT, ROOT, MPI_COMM_WORLD); MPI_Bcast(&pixelsCols, 1, MPI_INT, ROOT, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); int localPixelsNum = pixelsNum / size; Pixel *localPixels = new Pixel[localPixelsNum]; Pixel *outLocalPixels = new Pixel[localPixelsNum]; Pixel *outPixels = new Pixel[pixelsNum]; MPI_Datatype MPI_PIXEL; MPI_Type_contiguous(sizeof(Pixel), MPI_BYTE, &MPI_PIXEL); MPI_Type_commit(&MPI_PIXEL); MPI_Scatter(pixels, localPixelsNum, MPI_PIXEL, localPixels, localPixelsNum, MPI_PIXEL, ROOT, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); linearFilter(localPixels, pixelsRows / size, pixelsCols, outLocalPixels, 7); MPI_Barrier(MPI_COMM_WORLD); MPI_Gather(outLocalPixels, localPixelsNum, MPI_PIXEL, outPixels, localPixelsNum, MPI_PIXEL, ROOT, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); if (rank == ROOT) { image->ShowImage(); SDL_Event event; bool stop = false; while (!stop && SDL_WaitEvent(&event) != -1) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_RETURN: setPixels(outPixels, image); image->UpdateImage(); break; case SDLK_ESCAPE: stop = true; break; } } } } if (rank == ROOT) { delete[](pixels); } delete[](localPixels); delete[](outLocalPixels); delete[](outPixels); MPI_Finalize(); return 0; }
bool Bitmap::loadTarga(LPCTSTR pszFilename) { // Loads a TGA image and stores it in the Bitmap object. HANDLE hFile = CreateFile(pszFilename, FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return false; DWORD dwBytesRead = 0; TgaHeader header = {0}; // Read in the TGA file header. ReadFile(hFile, &header, sizeof(header), &dwBytesRead, 0); // Skip over the TGA file's ID field. if (header.idLength > 0) SetFilePointer(hFile, header.idLength, 0, FILE_CURRENT); // Check for compatible color depth. if (!(header.pixelDepth == 32 || header.pixelDepth == 24 || header.pixelDepth == 8)) { CloseHandle(hFile); return false; } // Only support uncompressed true color and grayscale images. if (!(header.imageType == 0x02 || header.imageType == 0x01)) { CloseHandle(hFile); return false; } // Read the TGA file into a temporary buffer. DWORD dwPitch = header.width * (header.pixelDepth / 8); DWORD dwBufferSize = dwPitch * header.height; std::vector<BYTE> buffer(dwBufferSize); // Load the pixel data from the TGA file. Flip image if it's not top down. if ((header.imageDescriptor & 0x30) == 0x20) { // TGA image is stored top down in file. ReadFile(hFile, &buffer[0], dwBufferSize, &dwBytesRead, 0); } else { // TGA image is stored bottom up in file. Need to flip it. BYTE *pRow = 0; for (int i = 0; i < header.height; ++i) { pRow = &buffer[(header.height - 1 - i) * dwPitch]; ReadFile(hFile, pRow, dwPitch, &dwBytesRead, 0); } } CloseHandle(hFile); if (!create(header.width, header.height)) return false; setPixels(&buffer[0], header.width, header.height, header.pixelDepth / 8); return true; }
void Bitmap::resize(int newWidth, int newHeight) { // Resizes the bitmap image using bilinear sampling. float ax = 0.0f, ay = 0.0f; float bx = 0.0f, by = 0.0f; float cx = 0.0f, cy = 0.0f; float dx = 0.0f, dy = 0.0f; float u = 0.0f, v = 0.0f, uv = 0.0f; float oneMinusU = 0.0f, oneMinusV = 0.0f, oneMinusUOneMinusV = 0.0f; float uOneMinusV = 0.0f, vOneMinusU = 0.0f; float srcX = 0.0f; float srcY = 0.0f; float srcXStep = static_cast<float>(width) / static_cast<float>(newWidth); float srcYStep = static_cast<float>(height) / static_cast<float>(newHeight); int destPitch = newWidth * 4; std::vector<BYTE> destPixels(destPitch * newHeight); BYTE pixel[4] = {0}; const BYTE *pSrcPixelA = 0; const BYTE *pSrcPixelB = 0; const BYTE *pSrcPixelC = 0; const BYTE *pSrcPixelD = 0; BYTE *pDestPixel = 0; for (int y = 0; y < newHeight; ++y) { for (int x = 0; x < newWidth; ++x) { ax = floor(srcX); u = srcX - ax; ay = floor(srcY); v = srcY - ay; dx = ax + 1.0f; dy = ay + 1.0f; if (dx >= width) dx = width - 1.0f; if (dy >= height) dy = height - 1.0f; bx = dx; by = ay; cx = ax; cy = dy; uv = u * v; oneMinusU = 1.0f - u; oneMinusV = 1.0f - v; uOneMinusV = u * oneMinusV; vOneMinusU = v * oneMinusU; oneMinusUOneMinusV = oneMinusU * oneMinusV; pSrcPixelA = &m_pBits[(static_cast<int>(ay) * pitch) + (static_cast<int>(ax) * 4)]; pSrcPixelB = &m_pBits[(static_cast<int>(by) * pitch) + (static_cast<int>(bx) * 4)]; pSrcPixelC = &m_pBits[(static_cast<int>(cy) * pitch) + (static_cast<int>(cx) * 4)]; pSrcPixelD = &m_pBits[(static_cast<int>(dy) * pitch) + (static_cast<int>(dx) * 4)]; pixel[0] = static_cast<BYTE>(pSrcPixelA[0] * oneMinusUOneMinusV + pSrcPixelB[0] * uOneMinusV + pSrcPixelC[0] * vOneMinusU + pSrcPixelD[0] * uv); pixel[1] = static_cast<BYTE>(pSrcPixelA[1] * oneMinusUOneMinusV + pSrcPixelB[1] * uOneMinusV + pSrcPixelC[1] * vOneMinusU + pSrcPixelD[1] * uv); pixel[2] = static_cast<BYTE>(pSrcPixelA[2] * oneMinusUOneMinusV + pSrcPixelB[2] * uOneMinusV + pSrcPixelC[2] * vOneMinusU + pSrcPixelD[2] * uv); pixel[3] = static_cast<BYTE>(pSrcPixelA[3] * oneMinusUOneMinusV + pSrcPixelB[3] * uOneMinusV + pSrcPixelC[3] * vOneMinusU + pSrcPixelD[3] * uv); pDestPixel = &destPixels[(y * destPitch) + (x * 4)]; pDestPixel[0] = pixel[0]; pDestPixel[1] = pixel[1]; pDestPixel[2] = pixel[2]; pDestPixel[3] = pixel[3]; srcX += srcXStep; } srcX = 0.0f; srcY += srcYStep; } destroy(); if (create(newWidth, newHeight)) setPixels(&destPixels[0], newWidth, newHeight, 4); }
// draw or erase a rectangle void drawRectangle(int x, int y, int width, int height, char borderColor, char fillColor, int divisibility){ int i,j,x1,x2,y1,y2,count=1; char bg = d.backgroundColor; if(borderColor != bg) logFig[figCount].isPresent = 1; else logFig[figCount].isPresent = 0; /**/ for(i=x, j=y; j<=height+y-1; j++){ if(!checkRange(i,j)) continue; setPixels(i,j,'0'+count); count = next(count); } for(i=x+1, j=y+height-1; i<=x+width-1; i++){ if(!checkRange(i,j)) continue; setPixels(i,j,'0'+count); count = next(count); } for(i=x+width-1, j=y+height-2; j>=y; j--){ if(!checkRange(i,j)) continue; setPixels(i,j,'0'+count); count = next(count); } for(i=x+width-2, j=y; i>x; i--){ if(!checkRange(i,j)) continue; setPixels(i,j,'0'+count); count = next(count); } for(i=x; i<width+x; i++){ for(j=y; j<height+y; j++){ if(!checkRange(i,j)) continue; if(i==x && j==y){ //setPixels(i,j,'1'); }else if((i==x+width-1&&j==y+height-1)){ //setPixels(i,j,'0'+width); }else if((i==x && j==y+height-1)){ //setPixels(i,j,'0'+height); }else if((j==y && i==x+width-1)){ //setPixels(i,j,'0'+width); }else if(i==x || i==x+width-1){ //if(i==x) setPixels(i,j, (j-y+1)+'0'); //else setPixels(i,j,height-(j-y+1)+'0'+1); }else if(j==y || j==y+height-1){ //setPixels(i,j,i-x+1+'0'); }else{ // original values //x1 = d.pixels[i][y]; //x2 = d.pixels[i][y+height-1]; //y1 = d.pixels[x][j]; //y2 = d.pixels[x+width-1][j]; x1 = y1 = x2 = y2 = -1; if(checkRange(i,y)) x1 = d.pixels[y-1][i-1]-'0'; if(checkRange(i,y+height-1)) x2 = d.pixels[y+height-2][i-1]-'0'; if(checkRange(x,j)) y1 = d.pixels[j-1][x-1]-'0'; if(checkRange(x+width-1,j)) y2 = d.pixels[j-1][x+width-2]-'0'; printf("%d %d %d %d\n", x1,x2,y1,y2); if((x1%divisibility==0 && y1%divisibility==0) || (x1%divisibility==0 && y2%divisibility==0) || (x2%divisibility==0 && y1%divisibility==0) || (x2%divisibility==0 && y2%divisibility==0)){ printf("PRINT\n"); setPixels(i,j,'0'+divisibility); }else setPixels(i,j,fillColor); } } } if(borderColor != bg) addlogFig(RECT, x, y, width, height, 0, borderColor, fillColor); }