int R2Image:: WritePGM(const char *filename, int ascii) const { // Check type if (ascii) { // Open file FILE *fp = fopen(filename, "w"); if (!fp) { fprintf(stderr, "Unable to open image file: %s\n", filename); return 0; } // Print PGM image file // First pgm pixel is top-left, so write in opposite scan-line order fprintf(fp, "P2\n"); fprintf(fp, "%d %d\n", width, height); fprintf(fp, "255\n"); for (int j = height-1; j >= 0 ; j--) { for (int i = 0; i < width; i++) { int value = (int) (255 * Gray(i, j)); fprintf(fp, "%-3d ", value); if (((i+1) % 16) == 0) fprintf(fp, "\n"); } } fprintf(fp, "\n"); // Close file fclose(fp); } else { // Open file FILE *fp = fopen(filename, "wb"); if (!fp) { fprintf(stderr, "Unable to open image file: %s\n", filename); return 0; } // Print PPM image file // First ppm pixel is top-left, so write in opposite scan-line order fprintf(fp, "P5\n"); fprintf(fp, "%d %d\n", width, height); fprintf(fp, "255\n"); for (int j = height-1; j >= 0 ; j--) { for (int i = 0; i < width; i++) { int value = (int) (255 * Gray(i, j)); fprintf(fp, "%c", value); } } // Close file fclose(fp); } // Return success return 1; }
int R2Image:: WritePFM(const char *filename) const { // Open file FILE *fp = fopen(filename, "wb"); if (!fp) { fprintf(stderr, "Unable to open pfm image file %s", filename); return 0; } // Write header fprintf(fp, "Pf\n"); fprintf(fp, "%d %d\n", width, height); fprintf(fp, "-1.0\n"); // Write pixels (row by row to avoid large buffers) for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { float value = Gray(i, j); if (fwrite(&value, sizeof(float), 1, fp) != (unsigned int) 1) { fprintf(stderr, "Unable to write image values to file %s\n", filename); return 0; } } } // Close file fclose(fp); // Return success return 1; }
//============================================================================= // // LoadStdImage() // // Purpose: The LoadStdImage() Loads the image for the button. This // function (or LoadStdStyle()) must be called at a minimum. // Automatically generates the other standard states. // // Parameters: // [IN] id // resource id, one of the resources already imported with the // resource editor, usually begins with IDR_ // // [IN] pType // pointer to string describing the resource type // // Returns: BOOL // Non zero if successful, otherwise zero // //============================================================================= BOOL StyleButton::LoadStdImage(UINT id, LPCTSTR pType) { CRect rect; GetClientRect(rect); Stack Std(rect); Std.AddImage(CPoint(0,0), id, pType); m_StdStyle.AddStack(Std); Stack Press(rect); Press.AddImage(CPoint(1,1), id, pType); m_StdPStyle.AddStack(Press); Stack Hot(rect); Hot.AddImage(CPoint(0,0), id, pType, FALSE, LIGHTEN); m_StdHStyle.AddStack(Hot); Stack Gray(rect); Gray.AddImage(CPoint(0,0), id, pType, FALSE, GRAYSCALE); m_StdGStyle.AddStack(Gray); // create background Stack Back(rect); Back.FillSolid(CLEAR); m_Background.AddStack(Back); return TRUE; }
void GradientStop(Painter& sw) { sw.Rectangle(20.5, 20.5, 500, 100) .ColorStop(0.25, Green()) .ColorStop(0.5, Yellow()) .ColorStop(0.75, Gray()) .Fill(0, 0, Blue(), 500, 0, LtRed()) .Stroke(1, Black()); }
Color EditorSyntax::IfColor(char c) { switch(c){ case IfState::IF: return LtBlue(); case IfState::ELIF: return Gray(); case IfState::ELSE: return Green(); case IfState::ELSE_ERROR: return LtRed(); case IfState::ENDIF_ERROR: return LtMagenta(); default: return Null; } }
void main() { int fmode=0; int i,j; int red[256]; int green[256]; int blue[256]; FILE *f; char *filename="text_gray.bmp"; ReadBmp(filename,&tmp1); printf("%d %d\n",tmp1.height,tmp1.width); while(1){ printf(" 0:モード法\n 1:判別分析法\n 2:移動平均法\n 3:終了\n"); scanf("%d",&fmode); if(fmode > 2) break; tmp2=tmp1; /* 元の画像ファイルのすべての画像データをコピーする */ reset( red, green, blue ); Gray( &tmp2 , &tmp1 ); set( red , green , blue ); switch(fmode){ case 0 : mode(red); //モード法 break; case 1 : sweep(red); //判別分析法 break; case 2 : mov_ave(red); //移動平均法 break; } WriteBmp("border.bmp",&tmp2); PrintBmpInfo("border.bmp"); } }
UCHAR ImageArray::GetUCharAtLCDMem(UINT x, UINT y) { UCHAR val = 0; if (x < GetColumns() && y < GetRows()) { Points points; m_packer->GetPoints(points, x, y); Points::iterator point = points.begin(); while (point != points.end()) { Color c; m_img->GetPixel((*point).GetX(), (*point).GetY(), &c); UCHAR gray = Gray(c.GetR(), c.GetG(), c.GetB()); val |= (m_packer->Pack(gray, (*point).GetPackOffset(), m_invert)); point++; } } return val; }
void R2Image:: NormalizeForDisplay(void) { // Find minumum and maximum gray level double minimum = FLT_MAX; double maximum = -FLT_MAX; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { double gray = Gray(i, j); if (gray < minimum) minimum = gray; if (gray > maximum) maximum = gray; } } // Scale values between 0.0 and 1.0 double range = maximum - minimum; if (range == 0) return; Subtract(minimum); Divide(range); }
//============================================================================================== /*static*/ Color ConnState::ConvertStateToColor(EnumConnState enumConnState) { switch (enumConnState) { case NOCON_NEVER: return Gray(); case NOCON_WASSUCC: return Green(); case NOCON_WASFAIL: return Red(); case NOCON_UNDEF: return LtGray(); case NOCON_MISCONFIG: return Magenta(); case CONNECTING_START: return LtYellow(); case CONNECTING_YAWN: return Yellow(); case CONNECTING_2NDTRY: return LtMagenta(); case CONNECTING_3RDTRY: return White(); case CONNECTING_TIMEOUT: return Cyan(); case CON_SUCCEED: return LtGreen(); case CON_FAIL: return LtRed(); case CON_STALE: return LtBlue(); } return Black(); }
QImage Dialog::sepiaEffects(int val) { int gray; rgb structRgb; for(int i=0; i<m_Image.byteCount();i+=4) { structRgb.b = m_listImageIn[i]; structRgb.g = m_listImageIn[i+1]; structRgb.r = m_listImageIn[i+2]; gray = Gray(structRgb); gray = gray*(val/100.0); m_listImageOut[i] = gray*0.82; m_listImageOut[i+1] = gray*0.95; m_listImageOut[i+2] = gray; m_listImageOut[i+3] = m_listImageIn[i+3]; } return QImage((unsigned char *)m_listImageOut,m_Image.width(),m_Image.height(),m_Image.format()); }
void R2Image:: ConvertToGray(void) { // Check number of channels if (NPixels() == 0) return; if (nchannels <= 1) return; if (!pixels) return; // Create gray pixels double *gray_pixels = new double [ NPixels() ]; assert(gray_pixels); for (int j = 0; j < Height(); j++) { for (int i = 0; i < Width(); i++) { gray_pixels[j*width + i] = Gray(i, j); } } // Assign gray pixels delete [] pixels; pixels = gray_pixels; nchannels = 1; }
ImageGray WaterShedDecomposer::gradientMagnitude(ImageColor const & image) const { ImageGray gmImage(image.width(), image.height()); // Frobenius norm on Jacobian matrix for (int y=0; y<image.height(); ++y) { for (int x=0; x<image.width(); ++x) { gmImage.at(x, y) = Gray(sqrt((image.at(std::min(image.width()-1, x+1), y)- image.at(std::max(0, x-1), y)).magnitudeSquared() + (image.at(x, std::min(image.height()-1, y+1))- image.at(x, std::max(0, y-1))).magnitudeSquared())); } } // scaling just for debug float max = 0.0; for (int i=0; i<gmImage.area(); ++i) { max = std::max(max, gmImage.at(i).l); } for (int i=0; i<gmImage.area(); ++i) { gmImage.at(i).l *= 255.0/max; } return gmImage; }
void FormView::DrawObject(Draw& w, int id, const Color& c, bool springs) { if (!IsLayout()) return; FormObject *pI = GetObject(id); if (!pI) return; Rect offseted = Offseted(pI->GetRect()); offseted = Zoom(offseted); if (_showInfo == 2) w.DrawRect(offseted, c); String type = pI->Get("Type"); if (type == "Label") DrawRect(w, offseted.Offseted(-1, 0), 1, LtGray()); if (pI->IsSelected() && springs) { DrawSprings(w, offseted, pI->GetHAlign(), pI->GetVAlign()); w.DrawImage(offseted.right, offseted.bottom, FormViewImg::SizerBR()); DrawRect(w, offseted, 1, LtRed()); } else if (pI->IsSelected() && !springs) DrawRect(w, Point(offseted.left, offseted.top), Size(offseted.Width(), offseted.Height()), 1, LtRed()); else if (_showInfo == 2 || pI->GetBool("OutlineDraw")) DrawRect(w, offseted, 1, Black()); if (pI->GetBool("OutlineDraw")) { Rect l = offseted.Offseted( ZoomX(3), ZoomY(3) ); l = Rect( l.TopLeft(), l.GetSize() - Size(ZoomX(6), ZoomY(6)) ); DrawRect(w, l, 1, LtCyan()); } String temp = pI->Get("Variable"); Size t = GetTextSize( temp, _Font ); int cx = t.cx; int y = offseted.BottomCenter().y - t.cy - ZoomY(3); if (_showInfo > 0) { if (offseted.Width() > t.cx + 15) { int x1 = ZoomX(pI->GetRect().right) - DeZoomX(2) - 4 - t.cx + ZoomX(X(0)); w.DrawRect( x1 - 2, y, t.cx + 3, t.cy, White()); // DrawRect(w, Point(x1 - 2, y), Size(t.cx + 3, t.cy), 1, LtGray()); w.DrawText( x1, y, temp, _Font, LtBlue); } temp = AsString(id) + " " + type; t = GetTextSize(temp, _Font); Size s = GetTextSize(AsString(id), _Font); if (offseted.Width() - cx > t.cx + 10) { w.DrawRect( offseted.left + ZoomX(5) - 2, y, t.cx + 3, t.cy, White()); // DrawRect(w, Point(offseted.left + ZoomX(5) - 2, y), Size(t.cx + 3, t.cy), // 1, LtGray()); w.DrawText( offseted.left + ZoomX(5), y, temp, _Font, Gray()); } else if (offseted.Width() > s.cx + 5) { w.DrawRect( offseted.left + ZoomX(5) - 2, y, s.cx + 3, s.cy, White()); // DrawRect(w, Point(offseted.left + ZoomX(5) - 2, y), Size(s.cx + 3, s.cy), // 1, LtGray()); w.DrawText( offseted.left + ZoomX(5), y, AsString(id), _Font, Gray()); } } }
void RulerCtrl::Paint(Draw& draw) { Size client = GetSize(); int csize = is_vert ? client.cy : client.cx; int cheight = is_vert ? client.cx : client.cy; Rect clip = GetSize(); int cy = font.Info().GetHeight(); double pos1 = FromClient(0); double pos2 = FromClient(csize); if(pos1 > pos2) Swap(pos1, pos2); double lrange = min_range, rrange = max_range; if(!IsNull(min_range) && pos1 < min_range) pos1 = min_range; if(!IsNull(max_range) && pos2 > max_range) pos2 = max_range; int cli1 = 0, cli2 = csize; if(scale < 0) Swap(lrange, rrange); if(!IsNull(lrange)) cli1 = max<int>(cli1, ToClient(lrange)); if(!IsNull(rrange)) cli2 = min<int>(cli2, ToClient(rrange)); Rect nclip; if(is_vert) { draw.DrawRect(0, 0, client.cx, cli1, outer_color); if(!IsNull(lrange)) draw.DrawRect(0, cli1++, client.cx, 1, SBlack); draw.DrawRect(0, cli2, client.cx, client.cy - cli2, outer_color); if(!IsNull(rrange)) draw.DrawRect(0, --cli2, client.cx, 1, SBlack); draw.DrawRect(0, cli1, 1, cli2 - cli1, SGray); // draw.DrawRect(0, cli1, 1, cli2 - cli1, SBlack); draw.DrawRect(client.cx - 1, cli1, 1, cli2 - cli1, SBlack); nclip = RectC(1, cli1, client.cx - 2, cli2 - cli1); } else { draw.DrawRect(0, 0, cli1, client.cy, outer_color); if(!IsNull(lrange)) draw.DrawRect(cli1++, 0, 1, client.cy, SBlack); draw.DrawRect(cli2, 0, client.cx - cli2, client.cy, outer_color); if(!IsNull(rrange)) draw.DrawRect(--cli2, 0, 1, client.cy, SBlack); draw.DrawRect(cli1, 0, cli2 - cli1, 1, SGray); draw.DrawRect(cli1, client.cy - 1, cli2 - cli1, 1, SBlack); nclip = RectC(cli1, 1, cli2 - cli1, client.cy - 2); } draw.DrawRect(nclip, background); draw.Clip(nclip); enum { SMALL_LIMIT = 100, // TEXT_LIMIT = 50, TGAP = 3, HGAP = 2, VGAP = 0, HXGAP = 3, VXGAP = 2, SMALL_SIZE = 5, }; double rep_count = 1; double rep_delta = 0; if(!IsNull(small_repeat)) { rep_delta = small_repeat * floor(pos1 / small_repeat); rep_count = ceil(pos2 / small_repeat) - floor(pos1 / small_repeat); } if(!small_step.IsEmpty() && rep_count > 0 && rep_count * small_step.GetCount() <= cli2 - cli1) { int ix = BinFindIndex(small_step, pos1 - rep_delta); int ppos = (is_right ? 0 : cheight - SMALL_SIZE); for(int c = fround(rep_count); --c >= 0; ix = 0, rep_delta += small_repeat) { int lim = small_step.GetCount(); if(small_step.Top() > pos2 - rep_delta) lim = BinFindIndex(small_step, pos2 - rep_delta); for(; ix < lim; ix++) { int cli = ToClient(small_step[ix] + rep_delta); if(is_vert) draw.DrawRect(ppos, cli, SMALL_SIZE, 1, Gray()); else draw.DrawRect(cli, ppos, 1, SMALL_SIZE, Gray()); } } } rep_count = 1; double rep_index = 0; if(!IsNull(text_repeat)) { rep_index = floor(pos1 / text_repeat); rep_count = ceil(pos2 / text_repeat) - floor(pos1 / text_repeat) + 1; } if(!text_step.IsEmpty() && (!text_value.IsEmpty() || text_convert) && rep_count > 0 /*&& rep_count * text_step.GetCount() <= TEXT_LIMIT*/) { int ix = BinFindIndex(text_step, pos1 - rep_index * text_repeat); int ppos = (is_right ? SMALL_SIZE : cheight - cy - SMALL_SIZE); int rpos = (is_right ? 0 : cheight - SMALL_SIZE - 1); for(int c = fround(rep_count); --c >= 0; ix = 0, rep_index++) { int lim = text_step.GetCount(); double dp2 = pos2 - rep_index * text_repeat; if(text_step.Top() > dp2) { lim = BinFindIndex(text_step, dp2); if(lim + 1 < text_step.GetCount() && text_step[lim + 1] - dp2 < dp2 - text_step[lim]) lim++; } for(; ix < lim; ix++) { double value = text_step[ix] + rep_index * text_repeat; int cli = ToClient(value); String text; if(ix < text_value.GetCount()) text = text_value[ix]; else if(text_convert) text = StdFormat(text_convert -> Format(value)); else text = StdFormat(value); Size tsize = GetTextSize(text, font); int half = tsize.cx >> 1; if(is_vert) { draw.DrawRect(0, cli, ppos, 1, Black()); draw.DrawRect(rpos, cli, SMALL_SIZE + 1, 1, Black()); // draw.DrawRect(ppos - VGAP, cli - half - HGAP, tsize.cy + 2 * VGAP, tsize.cx + 2 * HGAP, background); draw.DrawText(ppos, cli + half, 900, text, font, Gray()); } else { draw.DrawRect(cli, 0, 1, ppos, Black()); draw.DrawRect(cli, rpos, 1, SMALL_SIZE + 1, Black()); // draw.DrawRect(cli - half - HGAP, ppos - VGAP, tsize.cx + 2 * HGAP, tsize.cy + 2 * VGAP, background); draw.DrawText(cli - half, ppos, text, font, Gray()); } } } }
void CWelcomePageBase::ConstructL( MPageObserver& aObserver ) { CALLSTACKITEM_N(_CL("CWelcomePageBase"), _CL("ConstructL")); iObserver = &aObserver; CreateWindowL(); iPageRect = TRect( TPoint(0,0), MJuikLayout::ScreenSize() ); iIcons = new (ELeave) CAknIconArray(KIconCount); Reporting().DebugLog(_L("LoadIcons")); JuikIcons::LoadIconsL( iIcons, KIconIds, KIconCount ); TJuikLayoutItem l = Layout().GetLayoutItemL(LG_welcome_selection_page, LI_welcome_selection_page__body_text); iMainText = new (ELeave) CEikLabel(); iMainText->SetContainerWindowL( *this ); iMainText->SetFont( l.Font() ); if ( iLayoutStyle == ESelectionLayout ) { iMainText->OverrideColorL(EColorLabelText, DarkGray()); //iMainText->SetLabelAlignment( ELayoutAlignCenter ); } else if ( iLayoutStyle == EWelcomeLayout ) { iMainText->OverrideColorL(EColorLabelText, Gray()); iMainText->SetLabelAlignment( ELayoutAlignCenter ); } else if ( iLayoutStyle == ECongratulationsLayout ) { iMainText->OverrideColorL(EColorLabelText, Gray()); iMainText->SetLabelAlignment( ELayoutAlignCenter ); } else { ASSERT( EFalse ); } iControls.Append(iMainText); l = Layout().GetLayoutItemL(LG_welcome_softkeys, LI_welcome__leftsoftkey); iLeftSoftkey = new (ELeave) CEikLabel(); iLeftSoftkey->SetContainerWindowL( *this ); iLeftSoftkey->SetFont( l.Font() ); iLeftSoftkey->OverrideColorL(EColorLabelText, DarkGray()); iLeftSoftkey->SetTextL( _L("Continue") ); iControls.Append(iLeftSoftkey); l = Layout().GetLayoutItemL(LG_welcome_softkeys, LI_welcome__rightsoftkey); iRightSoftkey = new (ELeave) CEikLabel(); iRightSoftkey->SetContainerWindowL( *this ); iRightSoftkey->SetFont( l.Font() ); iRightSoftkey->OverrideColorL(EColorLabelText, DarkGray()); iRightSoftkey->SetTextL( _L("") ); iControls.Append(iRightSoftkey); }
void CLjz153View::OnGrey() { // TODO: Add your command handler code here Gray(); Invalidate(); }
void image_bmp::Ideallow() { // 中间变量 double dTemp,MAX,MIN; // 循环变量 LONG i; LONG j; // 进行付立叶变换的宽度和高度(2的整数次方) LONG fw; LONG fh; int wp; int hp; // 赋初值 fw = 1; fh = 1; wp = 0; hp = 0; int H=Gray.rowsCount(); int W=Gray.colsCount(); datatemp=new imagedata *[H]; for(i=0;i<H;i++) datatemp[i]=new imagedata [W]; // 计算进行付立叶变换的宽度和高度(2的整数次方) while(fw * 2 <= W) { fw *= 2; wp++; } while(fh * 2 <= H) { fh *= 2; hp++; } // 分配内存 TD = new complex<double>[fw * fh]; FD = new complex<double>[fw * fh]; // 行 for(i = 0; i <fh; i++) { // 列 for(j = 0; j < fw; j++) { if((i+j)%2==0) // 给时域赋值 TD[j + fw * i] = complex<double>(Gray(i,j), 0); else // 给时域赋值 TD[j + fw * i] = complex<double>(-Gray(i,j), 0); } } for(i = 0; i <fh; i++) { // 对y方向进行快速付立叶变换 FFT_1D(&TD[fw * i], &FD[fw * i], wp); } // 保存变换结果 for(i = 0; i < fh; i++) { for(j = 0; j < fw; j++) { TD[i + fh * j] = FD[j + fw * i]; } } for(i = 0; i < fw; i++) { // 对x方向进行快速付立叶变换 FFT_1D(&TD[i * fh], &FD[i * fh], hp); } for(i = 0; i < fh; i++) for(j = 0; j < fw; j++) GrayTemp(i,j) = sqrt(FD[j * fh + i].real() * FD[j * fh + i].real() + FD[j * fh + i].imag() * FD[j * fh + i].imag()); MAX=GrayTemp.getMaxVal();MIN=GrayTemp.getMinVal(); int D0=20; // 行 for(i = 0; i < fh; i++) { // 列 for(j = 0; j < fw; j++) { // 计算频谱 dTemp = (double)sqrt(((double)i-H/2)*((double)i-H/2)+((double)j-W/2)*((double)j-W/2)); double Huv=(dTemp<=D0)?1:2; FD[j*fh+i]=FD[j*fh+i]*Huv; } } for(i = 0; i < fh; i++) for(j = 0; j < fw; j++) GrayTemp(i,j) = sqrt(FD[j * fh + i].real() * FD[j * fh + i].real() + FD[j * fh + i].imag() * FD[j * fh + i].imag()); for(i = 0; i < fh; i++) for(j = 0; j < fw; j++) { GrayTemp(i,j)=(GrayTemp(i,j)-MIN)/(MAX-MIN)*255; if(GrayTemp(i,j)>=1) GrayTemp(i,j)=255; else GrayTemp(i,j)=GrayTemp(i,j)*255; datatemp[i][j].blue=GrayTemp(i,j); datatemp[i][j].green=GrayTemp(i,j); datatemp[i][j].red=GrayTemp(i,j); } path="保存的图片\\Ideallow_FFT.bmp"; save_image(); //进行逆变换 for(i = 0; i < fh; i++) { // 对y方向进行快速付立叶变换 IFFT_1D(&FD[fw * i], &TD[fw * i], wp); } // 保存变换结果 for(i = 0; i < fh; i++) { for(j = 0; j < fw; j++) { FD[i + fh * j] = TD[j + fw * i]; } } for(i = 0; i < fw; i++) { // 对x方向进行快速付立叶变换 IFFT_1D(&FD[i * fh], &TD[i * fh], hp); } // 行 for(i = 0; i < fh; i++) { // 列 for(j = 0; j < fw; j++) { // 计算频谱 dTemp = sqrt(TD[i * fh + j].real() * TD[i * fh + j].real() + TD[i * fh + j].imag() * TD[i * fh + j].imag()); // 更新临时数组datatemp datatemp[i][j].blue=BYTE(dTemp); datatemp[i][j].green=BYTE(dTemp); datatemp[i][j].red=BYTE(dTemp); } } path="保存的图片\\Ideallow.bmp"; save_image(); for(i=0;i<H;i++) delete[] datatemp[i]; delete[] datatemp; delete[] TD; delete[] FD; }