• Content count

  • Joined

  • Last visited

Community Reputation

203 Neutral

About Amnesty2

  • Rank
  1. ultimately i would like to have a 2D array loaded from a black and white tiff file such as bool image[width][length];   where true is pixel present and false is blank, or vice versa i don't care. Modify some bits and write it back out to a tiff       I'm using libtiff and C++, i attached a sample tiff   Basically, i followed one of the examples. Just modified it to print the buffer to a output file and it the result is bizzare This is what the output looks like      €   €T €   €T €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   €   Looks like its still in some kind of compressed format.   I tried other examples on libtiff site, and some from stackoverflow and haven't got anything really working.   Any help would be very MUCH appreciated!!       #include <stdio.h>  #include <tiffio.h> #include <memory> #include <fstream> #include <iostream> #pragma comment(lib,"libtiff.lib")   int main(int argc, char *argv[])   {    TIFF *image;  uint16 photo, bps, spp, fillorder;    uint32 width;    tsize_t stripSize;  unsigned long imageOffset, result;    int stripMax, stripCount;    char *buffer, tempbyte;   unsigned long bufferSize, count;   // Open the TIFF image      if((image = TIFFOpen("test.tiff", "r")) == NULL) {      std::cout << "Could not open incoming image\n" << std::endl;      system("Pause"); return (42);    }     int imageWidth, imageLength, tileWidth, tileLength; TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &imageWidth); TIFFGetField(image, TIFFTAG_IMAGELENGTH, &imageLength); TIFFGetField(image, TIFFTAG_TILEWIDTH, &tileWidth); TIFFGetField(image, TIFFTAG_TILELENGTH, &tileLength);     std::cout << "Image Width: " << imageWidth << std::endl; std::cout << "Image Height: " << imageLength << std::endl; std::cout << "Tile Width : " << tileWidth << std::endl; std::cout << "Tile Height : " << tileLength << std::endl;     // Check that it is of a type that we support    if((TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0) || (bps != 1)) {    fprintf(stderr, "Either undefined or unsupported number of bits per sample\n");      return(43);   }   if((TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp) == 0) || (spp != 1)) {      fprintf(stderr, "Either undefined or unsupported number of samples per pixel\n");    return(44);   }   // Read in the possibly multiple strips    stripSize = TIFFStripSize (image);    stripMax = TIFFNumberOfStrips (image);    imageOffset = 0;       bufferSize = TIFFNumberOfStrips (image) * stripSize;    if((buffer = (char *) malloc(bufferSize)) == NULL) {   fprintf(stderr, "Could not allocate enough memory for the uncompressed image\n");     return(42);   }       for (stripCount = 0; stripCount < stripMax; stripCount++) {      if((result = TIFFReadEncodedStrip (image, stripCount,           buffer + imageOffset,           stripSize)) == -1) {      fprintf(stderr, "Read error on input strip number %d\n", stripCount);        return(45);     }   imageOffset += result;    }   std::cout << "strip count: " << stripMax << std::endl;   // Deal with photometric interpretations    if(TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &photo) == 0) {    fprintf(stderr, "Image has an undefined photometric interpretation\n");     return(46);   }    if(photo != PHOTOMETRIC_MINISWHITE) {      // Flip bits      printf("Fixing the photometric interpretation\n");   for(count = 0; count < bufferSize; count++)        buffer[count] = ~buffer[count];   }   // Deal with fillorder    if(TIFFGetField(image, TIFFTAG_FILLORDER, &fillorder) == 0) {      fprintf(stderr, "Image has an undefined fillorder\n");     // return(47);   }      if(fillorder != FILLORDER_MSB2LSB) {     // We need to swap bits -- ABCDEFGH becomes HGFEDCBA      printf("Fixing the fillorder\n");   for(count = 0; count < bufferSize; count++) {  tempbyte = 0;        if(buffer[count] & 128) tempbyte += 1;      if(buffer[count] & 64) tempbyte += 2;        if(buffer[count] & 32) tempbyte += 4;    if(buffer[count] & 16) tempbyte += 8;       if(buffer[count] & 8) tempbyte += 16;       if(buffer[count] & 4) tempbyte += 32;        if(buffer[count] & 2) tempbyte += 64;      if(buffer[count] & 1) tempbyte += 128;     buffer[count] = tempbyte;      }    }         // Do whatever it is we do with the buffer -- we dump it in hex   if(TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width) == 0) {     fprintf(stderr, "Image does not define its width\n");      return(48);   }    std::fstream file("output.txt",std::ios_base::out); for(int i = 0; i < bufferSize; ++ i) { file << buffer[i]; } file.close();   std::cout << bufferSize << std::endl; system("Pause");   return 0; }  
  2. I'll give an example because i don't really know how to word it.   cout << "Input a filename :"; cin >> file;   I would like to print Input a filename :autosave.txt_<cursor here> autosave.txt can be backspaced on and edited.   I'd like to put some stuff in cins buffer before i ask and have it displayed and be editable.    i can only think of platform specific ways of achieving something similar. Simulating key presses or rolling your input function that pops data off on backspace, pushes chars in, and sets the cursor position accordingly.   I know, iostreams let you hack around at a pretty low level with them so i assume this possible some how. Maybe?      
  3. Zooming about to a point (2D surface)

    Works Great! thanks   In addition to your formulas, I averaged the new m_x and m_y values with the old ones so they were not changed so drastically. Seems really smooth now.
  4.     Hello, I need some help with this math. I've been at this for hours now.   I have a large surface (the whole tiger) and a view in blue that is 700,400. Right now, i have it zooming and panning with bounds checking fine, but can't figure out how to zoom to the mouse cursor (red dots).   Say, im at 660, 300 local coordinates of view A and zoom in, how do I get what appears in view B? Currently, it just zooms into 0,0 and would get a close up of the ear instead. Basically, I want the functionality of Paint, or Paint.NET or any image editor. This is all 2D math btw   // x, and y are local coordinates void Canvas::setScale(float s, int x, int y) { // m_x and m_y are are coordinates into the full canvas // the view treats them as 0,0 // in view marked A, these would something like 200,100 and would be at the tip of the ear // after this function i want them to point right above the eye like in the view B example float oldscale = m_scale; m_scale = s; // TODO add the math CheckBounds(); }   Right now, i have some math filled in but it only kinda working.. Its more of a hack and is definately not fluid or percise. I know there most be a standard way of doing this.     Thanks  
  5. Visual Studio Express 2012 Yay

    For anyone that don't know, if you're a college student you can go to dreamspark dot com and download the professional edition for free and skip the express all together.
  6. Nope it would fail you would have to initialize it in the factories constructor. [CODE] class ThreadingFactory { public: ThreadingFactory(LogManager& mLog) : mLogger(mLog) { } IMutex* const CreateMutex() { IMutex* ret = NULL; ret = mMemoryAllocator.AllocateObject<Mutex>(mLogger); return ret; } private: ILogManager& mLogger; Allocator mMemoryAllocator; }; [/CODE] references must be initialized. You would have to pass factory an instance of the logger class.
  7. Writing %-symbol to a string? (c++)

    [quote name='suliman' timestamp='1345125050' post='4970167'] Is there any way to write it so it always becomes an acutal "%" in the end? Different function now demand different amount of % to "bypass the format". [/quote] This sounds like the most fragile coding i've heard about in recent years. Don't format the string multiple times. Each function should take an unmodified string. mutate copies but leave the original unchanged.
  8. Polymorphism and pointer arrays in c++

    ApochPiQ: I think you meant [CODE] objects.push_back(std::unique_ptr<Object>(new IntObject(1))); objects.push_back(std::unique_ptr<Object>(new StringObject("Test"))); [/CODE] Or maybe not, if your compiler doesn't force you to be so verbose. VS10 does. Also you forgot to give Object a virtual dtor.
  9. Creating Terrain

    Try looking up samples of texture splatting for height map terrain. It would give your areas more detail.
  10. I'm creating a 2D game with DX9 using sprites and want to make a hit point bar. I created a image that with no scale would fill the hud's life bar to 100% because the bar is exactly the right size when drawn. It works fine when the scale is 1.0 but at any other value it is not right. It scales fine the problem is it is drawn in the wrong position. instead of the it being drawn at pos1.x = 12; pos1.y = 768 - 48 + 24; it looks like it is being drawn at this position pos1.x = 6; And then it over laps part of the HUD graphic. I don't understand why its moving the sprite to the left.. It gets worse the more scale there is. [source] D3DXVECTOR3 pos1; pos1.x = 12; pos1.y = 768 - 48 + 24; pos1.z = 0; D3DXMATRIX scale_matrix; D3DXVECTOR2 scale(0.5f,1.0f); // 50% scale in then x-direciton only D3DXMATRIX original; sprite_obj->GetTransform(&original); D3DXMatrixTransformation2D(&scale_matrix,NULL,0,&scale,NULL,NULL,NULL); sprite_obj->SetTransform(&scale_matrix); window::sprite_obj->Draw( txt_manager.get_texture("hp"),NULL,NULL,&pos1, D3DCOLOR_XRGB(255,255,255)); sprite_obj->SetTransform(&original); [/source] do i need to use a translation vector? If so how would i make it right every scale value? Why is this happening? Also how can i set the transparency of a sprite at run time before it is drawn?
  11. Hello, im working a game. I've been programming for a long time but this is the first time doing graphics programming. Im having trouble making the movement of my space invaders look good. The invaders move downward pretty nicely. But adding any movement along the x-axis is really choppy and poor. The invader will move straight down for 20 pixels smoothly and then just jump right or left; when it should be just a smooth slope. this is the invaders update function.. It is also responsible for drawing the invader [code] void invader::update(Timer& time) { if (_time == 0) _time = time.get_ticks(); if(is_alive) { _y = _y + ((time.get_ticks() - _time) * .10); _x = _x + ((time.get_ticks() - _time) * .05); _time = time.get_ticks(); // Apply texture } [size="3"][font="Calibri"]}[/font][/size] [/code] This is my game loop.. Its very small as i've dumbed it down .. Only one invader and nothing else.. It still has the same trouble. [code] [font="Calibri"][size="3"] [/size][/font] //While the user hasn't quit while( quit == false ) { //While there's an event to handle while( SDL_PollEvent( &event ) ) { //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Increment the frame counter frame++; //Apply the background to the screen apply_surface( 0, 0, background, screen ); invader_guy->update(fps); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //If we want to cap the frame rate if( ( cap == true ) && ( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) ) { //Sleep the remaining frame time SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } [/code] The timer class is lazyfoos it just makes SDL_GetTicks more useful by giving the elapsed ticks not the total. It uses Any ideas, thoughts or demo on proper 2D movements with velocitys and timers would be much much appreciated!
  12. Capitalizing Variables

    Quote:Original post by _goat Richy's code makes me cry. I use the boost standards: *** Source Snippet Removed *** The enums aren't exactly boost-style, but I find they're really good. C++09 ftw (strongly named enums). Hey, i started doing that with my enums a long time ago. Because scoping and qualifying is so much better. Except instead of Enum i use type. I didnt even realise boost did this too. So i must've had a few decent ideas after all :)
  13. Update: The answer was pretty simple. I had to set the size of the picturebox after creating each instance inside the foreach. The picturebox size was never set and it defaulted to (150,100) and the first picturebox covered up the others when drawn on the form. The reason it seemed to work in the designer when moving it around was because it then was being painted in reverse order.
  14. std::string greeting(std::string("* ") + "hello, " + "!" + " *"); Thats what you want. the annoymonus std::string("* ") clues the compiler in on the rest of the line Amnesty
  15. This control just displays a series of pictures based on the contents of a string. The string is hardcoded for now to make it easier. Well, it dont work. It paints the first picture. And none of the others. And its really confusing me because it all looks Right. Additonally, it paints the first pic only at design time. Unless i move the control around on the form then it magically shows them all? Really weird. I have no idea whats going on. Thanks for any help! public partial class CastingControl : UserControl { private PictureBox[] icons; private String CastingString; public CastingCostControl() { InitializeComponent(); CastingString = "RGGRGGRRRG"; int a = 0; icons = new PictureBox[CastingString.Length]; foreach (char CharT in CastingString ) { icons[a] = new PictureBox(); icons[a].Location = new System.Drawing.Point(16 * a, 0); if (CharT == 'G' ) icons[a].Image = global ::Magic.Properties.Resources.GreenB; if (CharT == 'R') icons[a].Image = global ::Magic.Properties.Resources.RedB; a++; } // End foreach this.Controls.AddRange(icons); this.Size = new System.Drawing.Size(icons .Length * 16, 16); } } At design time it appears to work fine (but only when moving the control around). At runtime, only shows the first PictureBox again.. I dont know why its doing this but it really freaking annoying!! [Edited by - Amnesty2 on October 16, 2008 2:20:19 PM]